ptype.cc
Go to the documentation of this file.
00001 #include "osl/ptype.h"
00002 #include "osl/ptypeTable.h"
00003 #include <iostream>
00004 #include <string>
00005 
00006 bool osl::isValid(Ptype ptype)
00007 {
00008   return static_cast<int>(ptype)>=PTYPE_MIN 
00009     && static_cast<int>(ptype)<=PTYPE_MAX;
00010 }
00011 
00012 bool osl::isValidPtypeO(int ptypeO)
00013 {
00014   return (ptypeO >= PTYPEO_MIN) && (ptypeO <= PTYPEO_MAX);
00015 }
00016 
00017 std::istream& osl::operator>>(std::istream& is, osl::Ptype& ptype)
00018 {
00019   std::string s;
00020   is >> s;
00021   if (s == "PTYPE_EMPTY")
00022     ptype = PTYPE_EMPTY;
00023   else if (s == "PTYPE_EDGE")
00024     ptype = PTYPE_EDGE;
00025   else if (s == "PPAWN")
00026     ptype = PPAWN;
00027   else if (s == "PLANCE")
00028     ptype = PLANCE;
00029   else if (s == "PKNIGHT")
00030     ptype = PKNIGHT;
00031   else if (s == "PSILVER")
00032     ptype = PSILVER;
00033   else if (s == "PBISHOP")
00034     ptype = PBISHOP;
00035   else if (s == "PROOK")
00036     ptype = PROOK;
00037   else if (s == "KING")
00038     ptype = KING;
00039   else if (s == "GOLD")
00040     ptype = GOLD;
00041   else if (s == "PAWN")
00042     ptype = PAWN;
00043   else if (s == "LANCE")
00044     ptype = LANCE;
00045   else if (s == "KNIGHT")
00046     ptype = KNIGHT;
00047   else if (s == "SILVER")
00048     ptype = SILVER;
00049   else if (s == "BISHOP")
00050     ptype = BISHOP;
00051   else if (s == "ROOK")
00052     ptype = ROOK;
00053   else{
00054     std::cerr << "Incorrect input : " << s << std::endl;
00055     ptype = PTYPE_EMPTY;
00056   }
00057   return is;
00058 }
00059 
00060 std::ostream& osl::operator<<(std::ostream& os,const osl::Ptype ptype)
00061 {
00062     return os << Ptype_Table.getName(ptype);
00063 }
00064   
00065 std::ostream& osl::operator<<(std::ostream& os,const osl::PtypeO ptypeO)
00066 {
00067   if (isPiece(ptypeO))
00068     return os << "PtypeO(" << getOwner(ptypeO) << "," 
00069               << getPtype(ptypeO) << ")";
00070   return os << "PtypeO(" << (int)ptypeO << "," << getPtype(ptypeO) << ")";
00071 }
00072 
00073 // ;;; Local Variables:
00074 // ;;; mode:c++
00075 // ;;; c-basic-offset:2
00076 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines