All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ptype.cc
Go to the documentation of this file.
1 #include "osl/ptype.h"
2 #include "osl/ptypeTable.h"
3 #include <iostream>
4 #include <string>
5 
6 bool osl::isValid(Ptype ptype)
7 {
8  return static_cast<int>(ptype)>=PTYPE_MIN
9  && static_cast<int>(ptype)<=PTYPE_MAX;
10 }
11 
12 bool osl::isValidPtypeO(int ptypeO)
13 {
14  return (ptypeO >= PTYPEO_MIN) && (ptypeO <= PTYPEO_MAX);
15 }
16 
17 std::istream& osl::operator>>(std::istream& is, osl::Ptype& ptype)
18 {
19  std::string s;
20  is >> s;
21  if (s == "PTYPE_EMPTY")
22  ptype = PTYPE_EMPTY;
23  else if (s == "PTYPE_EDGE")
24  ptype = PTYPE_EDGE;
25  else if (s == "PPAWN")
26  ptype = PPAWN;
27  else if (s == "PLANCE")
28  ptype = PLANCE;
29  else if (s == "PKNIGHT")
30  ptype = PKNIGHT;
31  else if (s == "PSILVER")
32  ptype = PSILVER;
33  else if (s == "PBISHOP")
34  ptype = PBISHOP;
35  else if (s == "PROOK")
36  ptype = PROOK;
37  else if (s == "KING")
38  ptype = KING;
39  else if (s == "GOLD")
40  ptype = GOLD;
41  else if (s == "PAWN")
42  ptype = PAWN;
43  else if (s == "LANCE")
44  ptype = LANCE;
45  else if (s == "KNIGHT")
46  ptype = KNIGHT;
47  else if (s == "SILVER")
48  ptype = SILVER;
49  else if (s == "BISHOP")
50  ptype = BISHOP;
51  else if (s == "ROOK")
52  ptype = ROOK;
53  else{
54  std::cerr << "Incorrect input : " << s << std::endl;
55  ptype = PTYPE_EMPTY;
56  }
57  return is;
58 }
59 
60 std::ostream& osl::operator<<(std::ostream& os,const osl::Ptype ptype)
61 {
62  return os << Ptype_Table.getName(ptype);
63 }
64 
65 std::ostream& osl::operator<<(std::ostream& os,const osl::PtypeO ptypeO)
66 {
67  if (isPiece(ptypeO))
68  return os << "PtypeO(" << getOwner(ptypeO) << ","
69  << getPtype(ptypeO) << ")";
70  return os << "PtypeO(" << (int)ptypeO << "," << getPtype(ptypeO) << ")";
71 }
72 
73 // ;;; Local Variables:
74 // ;;; mode:c++
75 // ;;; c-basic-offset:2
76 // ;;; End: