Go to the documentation of this file.00001
00002
00003 #ifndef RECORD_KANJIPRINT_H
00004 #define RECORD_KANJIPRINT_H
00005
00006 #include "osl/state/simpleState.h"
00007 #include "osl/misc/carray.h"
00008 #include <boost/shared_ptr.hpp>
00009 #include <iosfwd>
00010 #include <string>
00011
00012 namespace osl
00013 {
00014 class Move;
00015
00016 namespace record
00017 {
00018 class Color;
00019 std::ostream& operator<<(std::ostream& os, const Color& c);
00023 class Color
00024 {
00025 public:
00026 Color() : name(""), valid(false) {}
00027 Color(const std::string& value, const std::string& name, const bool valid=true);
00028 ~Color();
00029 private:
00030 std::string value;
00031 std::string name;
00032 bool valid;
00033 public:
00034 bool isValid() const {return valid;}
00035 const std::string& getName() const {return name;}
00036 bool operator==(const Color& rhs) const
00037 {
00038 return (this->valid == rhs.valid) &&
00039 (this->value == rhs.value);
00040 }
00041 bool operator!=(const Color& rhs) const
00042 {
00043 return !(*this == rhs);
00044
00045 }
00046
00050 static const Color colorFor(const std::string& str);
00051
00053 static const Color NONE;
00054 static const Color Black;
00055 static const Color Red;
00056 static const Color Green;
00057 static const Color Brown;
00058 static const Color Blue;
00059 static const Color Purple;
00060 static const Color Cyan;
00061 static const Color LightGray;
00062 static const Color DarkGray;
00063 static const Color LightRed;
00064 static const Color LightGreen;
00065 static const Color Yellow;
00066 static const Color LightBlue;
00067 static const Color LightPurple;
00068 static const Color LightCyan;
00069 static const Color White;
00070
00071 friend std::ostream& operator<<(std::ostream& os, const Color& c);
00072 };
00073
00074
00078 class ChangeShellColor
00079 {
00080 private:
00081 std::ostream& os;
00082 const Color color;
00083
00084 void escColSet() const;
00085 void escColReSet() const;
00086 public:
00087 ChangeShellColor(std::ostream& os, const Color& color)
00088 : os(os), color(color) {escColSet();}
00089 ~ChangeShellColor() {escColReSet();}
00090 };
00091
00093 std::string kanjiNumber(const int n);
00094
00098 class Characters
00099 {
00100 public:
00101 static const misc::CArray<std::string, 32> stand;
00102
00103 virtual ~Characters();
00104
00106 virtual const std::string& getDan(const size_t index) const = 0;
00108 virtual const std::string& getSuji(const size_t index) const = 0;
00110 virtual const std::string& getPiece(const size_t index) const = 0;
00111
00113 const std::string& getStand(const size_t index) const
00114 {
00115 return stand[index];
00116 }
00117
00118 const std::string& stand_kanji(const PtypeO& ptypeo) const
00119 {
00120 return getStand(piece_index(ptypeo));
00121 }
00122
00123 const std::string& kanji(const PtypeO& ptypeo) const
00124 {
00125 return getPiece(piece_index(ptypeo));
00126 }
00127 const std::string& kanji(Ptype ptype) const
00128 {
00129 return getPiece(newPtypeO(BLACK, ptype));
00130 }
00131 private:
00132 size_t piece_index(const PtypeO& ptypeo) const
00133 {
00134 #ifndef NDEBUG
00135 static const size_t NPieces = PTYPEO_MAX - PTYPEO_MIN+2;
00136 #endif
00137 const size_t index = ptypeo - PTYPEO_MIN;
00138 assert(index < NPieces);
00139 return index;
00140 }
00141 };
00142
00144 struct StandardCharacters : public Characters
00145 {
00147 static const misc::CArray<std::string,10> dan;
00149 static const misc::CArray<std::string,10> suji;
00151 static const misc::CArray<std::string,32> pieces;
00152
00153 const std::string& getDan(const size_t index) const {return dan[index];}
00154 const std::string& getSuji(const size_t index) const {return suji[index];}
00155 const std::string& getPiece(const size_t index) const {return pieces[index];}
00156 };
00157
00159 struct RussianCharacters : public Characters
00160 {
00161 static const misc::CArray<std::string,10> dan;
00162 static const misc::CArray<std::string,10> suji;
00163 static const misc::CArray<std::string,32> pieces;
00164
00165 const std::string& getDan(const size_t index) const {return dan[index];}
00166 const std::string& getSuji(const size_t index) const {return suji[index];}
00167 const std::string& getPiece(const size_t index) const {return pieces[index];}
00168 };
00169
00171 struct KIFCharacters : public Characters
00172 {
00173 static const misc::CArray<std::string,10> dan;
00174 static const misc::CArray<std::string,10> suji;
00175 static const misc::CArray<std::string,32> pieces;
00176
00177 const std::string& getDan(const size_t index) const {return dan[index];}
00178 const std::string& getSuji(const size_t index) const {return suji[index];}
00179 const std::string& getPiece(const size_t index) const {return pieces[index];}
00180 };
00181
00185 class KanjiPrint
00186 {
00187 private:
00188 std::ostream& os;
00189 const boost::shared_ptr<Characters> pieces;
00190 Color black_color;
00191 Color white_color;
00192 Color last_move_color;
00193
00194 public:
00195 explicit KanjiPrint(std::ostream& os,
00196 const boost::shared_ptr<Characters> pieces=boost::shared_ptr<Characters>(new StandardCharacters()))
00197 : os(os), pieces(pieces),
00198 black_color(Color::NONE),
00199 white_color(Color::NONE),
00200 last_move_color(Color::NONE) {}
00201 ~KanjiPrint() {}
00202
00208 void print(const state::SimpleState& state,
00209 const Move *last_move=NULL) const;
00210
00211 void setBlackColor(const Color& c) {black_color = c;}
00212 void setWhiteColor(const Color& c) {white_color = c;}
00213 void setLastMoveColor(const Color& c) {last_move_color = c;}
00214 };
00215 }
00216 }
00217
00218 #endif
00219
00220
00221
00222