All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
kanjiPrint.h
Go to the documentation of this file.
1 /* kanjiPrint.h
2  */
3 #ifndef RECORD_KANJIPRINT_H
4 #define RECORD_KANJIPRINT_H
5 
7 #include "osl/misc/carray.h"
8 #include <boost/shared_ptr.hpp>
9 #include <iosfwd>
10 #include <string>
11 
12 namespace osl
13 {
14  class Move;
15 
16  namespace record
17  {
18  class Color;
19  std::ostream& operator<<(std::ostream& os, const Color& c);
23  class Color
24  {
25  public:
26  Color() : name(""), valid(false) {}
27  Color(const std::string& value, const std::string& name, const bool valid=true);
28  ~Color();
29  private:
30  std::string value;
31  std::string name;
32  bool valid;
33  public:
34  bool isValid() const {return valid;}
35  const std::string& getName() const {return name;}
36  bool operator==(const Color& rhs) const
37  {
38  return (this->valid == rhs.valid) &&
39  (this->value == rhs.value);
40  }
41  bool operator!=(const Color& rhs) const
42  {
43  return !(*this == rhs);
44 
45  }
46 
50  static const Color colorFor(const std::string& str);
51 
53  static const Color NONE;
54  static const Color Black;
55  static const Color Red;
56  static const Color Green;
57  static const Color Brown;
58  static const Color Blue;
59  static const Color Purple;
60  static const Color Cyan;
61  static const Color LightGray;
62  static const Color DarkGray;
63  static const Color LightRed;
64  static const Color LightGreen;
65  static const Color Yellow;
66  static const Color LightBlue;
67  static const Color LightPurple;
68  static const Color LightCyan;
69  static const Color White;
70 
71  friend std::ostream& operator<<(std::ostream& os, const Color& c);
72  };
73 
74 
79  {
80  private:
81  std::ostream& os;
82  const Color color;
83 
84  void escColSet() const;
85  void escColReSet() const;
86  public:
87  ChangeShellColor(std::ostream& os, const Color& color)
88  : os(os), color(color) {escColSet();}
90  };
91 
93  std::string kanjiNumber(const int n);
94 
98  class Characters
99  {
100  public:
102 
103  virtual ~Characters();
104 
106  virtual const std::string& getDan(const size_t index) const = 0;
108  virtual const std::string& getSuji(const size_t index) const = 0;
110  virtual const std::string& getPiece(const size_t index) const = 0;
111 
113  const std::string& getStand(const size_t index) const
114  {
115  return stand[index];
116  }
117 
118  const std::string& stand_kanji(const PtypeO& ptypeo) const
119  {
120  return getStand(piece_index(ptypeo));
121  }
122 
123  const std::string& kanji(const PtypeO& ptypeo) const
124  {
125  return getPiece(piece_index(ptypeo));
126  }
127  const std::string& kanji(Ptype ptype) const
128  {
129  return getPiece(newPtypeO(BLACK, ptype));
130  }
131  private:
132  size_t piece_index(const PtypeO& ptypeo) const
133  {
134 #ifndef NDEBUG
135  static const size_t NPieces = PTYPEO_MAX - PTYPEO_MIN+2;
136 #endif
137  const size_t index = ptypeo - PTYPEO_MIN;
138  assert(index < NPieces);
139  return index;
140  }
141  };
142 
145  {
152 
153  const std::string& getDan(const size_t index) const {return dan[index];}
154  const std::string& getSuji(const size_t index) const {return suji[index];}
155  const std::string& getPiece(const size_t index) const {return pieces[index];}
156  };
157 
160  {
164 
165  const std::string& getDan(const size_t index) const {return dan[index];}
166  const std::string& getSuji(const size_t index) const {return suji[index];}
167  const std::string& getPiece(const size_t index) const {return pieces[index];}
168  };
169 
171  struct KIFCharacters : public Characters
172  {
176 
177  const std::string& getDan(const size_t index) const {return dan[index];}
178  const std::string& getSuji(const size_t index) const {return suji[index];}
179  const std::string& getPiece(const size_t index) const {return pieces[index];}
180  };
181 
186  {
187  private:
188  std::ostream& os;
189  const boost::shared_ptr<Characters> pieces;
193 
194  public:
195  explicit KanjiPrint(std::ostream& os,
196  const boost::shared_ptr<Characters> pieces=boost::shared_ptr<Characters>(new StandardCharacters()))
197  : os(os), pieces(pieces),
198  black_color(Color::NONE),
199  white_color(Color::NONE),
200  last_move_color(Color::NONE) {}
202 
208  void print(const state::SimpleState& state,
209  const Move *last_move=NULL) const;
210 
211  void setBlackColor(const Color& c) {black_color = c;}
212  void setWhiteColor(const Color& c) {white_color = c;}
213  void setLastMoveColor(const Color& c) {last_move_color = c;}
214  };
215  } // namespace record
216 } // namespace osl
217 
218 #endif /* RECORD_KANJIPRINT_H */
219 // ;;; Local Variables:
220 // ;;; mode:c++
221 // ;;; c-basic-offset:2
222 // ;;; End: