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
00095 class Characters
00096 {
00097 public:
00098 static const osl::misc::CArray<std::string, 32> stand;
00099
00100 virtual ~Characters();
00101
00103 virtual const std::string& getDan(const size_t index) const = 0;
00105 virtual const std::string& getSuji(const size_t index) const = 0;
00107 virtual const std::string& getPiece(const size_t index) const = 0;
00108
00110 const std::string& getStand(const size_t index) const
00111 {
00112 return stand[index];
00113 }
00114
00115 const std::string& stand_kanji(const PtypeO& ptypeo) const
00116 {
00117 return getStand(piece_index(ptypeo));
00118 }
00119
00120 const std::string& kanji(const PtypeO& ptypeo) const
00121 {
00122 return getPiece(piece_index(ptypeo));
00123 }
00124
00125 private:
00126 size_t piece_index(const PtypeO& ptypeo) const
00127 {
00128 #ifndef NDEBUG
00129 static const size_t NPieces = PTYPEO_MAX - PTYPEO_MIN+2;
00130 #endif
00131 const size_t index = ptypeo - PTYPEO_MIN;
00132 assert(index < NPieces);
00133 return index;
00134 }
00135 };
00136
00138 struct StandardCharacters : public Characters
00139 {
00141 static const osl::misc::CArray<std::string,10> dan;
00143 static const osl::misc::CArray<std::string,10> suji;
00145 static const osl::misc::CArray<std::string,32> pieces;
00146
00147 const std::string& getDan(const size_t index) const {return dan[index];}
00148 const std::string& getSuji(const size_t index) const {return suji[index];}
00149 const std::string& getPiece(const size_t index) const {return pieces[index];}
00150 };
00151
00153 struct RussianCharacters : public Characters
00154 {
00155 static const osl::misc::CArray<std::string,10> dan;
00156 static const osl::misc::CArray<std::string,10> suji;
00157 static const osl::misc::CArray<std::string,32> pieces;
00158
00159 const std::string& getDan(const size_t index) const {return dan[index];}
00160 const std::string& getSuji(const size_t index) const {return suji[index];}
00161 const std::string& getPiece(const size_t index) const {return pieces[index];}
00162 };
00163
00165 struct KIFCharacters : public Characters
00166 {
00167 static const osl::misc::CArray<std::string,10> dan;
00168 static const osl::misc::CArray<std::string,10> suji;
00169 static const osl::misc::CArray<std::string,32> pieces;
00170
00171 const std::string& getDan(const size_t index) const {return dan[index];}
00172 const std::string& getSuji(const size_t index) const {return suji[index];}
00173 const std::string& getPiece(const size_t index) const {return pieces[index];}
00174 };
00175
00179 class KanjiPrint
00180 {
00181 private:
00182 std::ostream& os;
00183 const boost::shared_ptr<Characters> pieces;
00184 Color black_color;
00185 Color white_color;
00186 Color last_move_color;
00187
00188 public:
00189 explicit KanjiPrint(std::ostream& os,
00190 const boost::shared_ptr<Characters> pieces=boost::shared_ptr<Characters>(new StandardCharacters()))
00191 : os(os), pieces(pieces),
00192 black_color(Color::NONE),
00193 white_color(Color::NONE),
00194 last_move_color(Color::NONE) {}
00195 ~KanjiPrint() {}
00196
00202 void print(const osl::state::SimpleState& state,
00203 const osl::Move *last_move=NULL) const;
00204
00205 void setBlackColor(const Color& c) {black_color = c;}
00206 void setWhiteColor(const Color& c) {white_color = c;}
00207 void setLastMoveColor(const Color& c) {last_move_color = c;}
00208 };
00209 }
00210 }
00211
00212 #endif
00213
00214
00215
00216