kanjiPrint.h
Go to the documentation of this file.
/* kanjiPrint.h
*/
#ifndef RECORD_KANJIPRINT_H
#define RECORD_KANJIPRINT_H
#include "osl/simpleState.h"
#include <memory>
#include <iosfwd>
#include <string>
namespace osl
{
class Move;
namespace record
{
class Color;
std::ostream& operator<<(std::ostream& os, const Color& c);
class Color
{
public:
Color() : name(""), valid(false) {}
Color(const std::string& value, const std::string& name, const bool valid=true);
~Color();
private:
std::string value;
std::string name;
bool valid;
public:
bool isValid() const {return valid;}
const std::string& getName() const {return name;}
bool operator==(const Color& rhs) const
{
return (this->valid == rhs.valid) &&
(this->value == rhs.value);
}
bool operator!=(const Color& rhs) const
{
return !(*this == rhs);
}
static const Color colorFor(const std::string& str);
static const Color NONE;
static const Color Black;
static const Color Red;
static const Color Green;
static const Color Brown;
static const Color Blue;
static const Color Purple;
static const Color Cyan;
static const Color LightGray;
static const Color DarkGray;
static const Color LightRed;
static const Color LightGreen;
static const Color Yellow;
static const Color LightBlue;
static const Color LightPurple;
static const Color LightCyan;
static const Color White;
friend std::ostream& operator<<(std::ostream& os, const Color& c);
};
class ChangeShellColor
{
private:
std::ostream& os;
const Color color;
void escColSet() const;
void escColReSet() const;
public:
ChangeShellColor(std::ostream& os, const Color& color)
: os(os), color(color) {escColSet();}
~ChangeShellColor() {escColReSet();}
};
std::string kanjiNumber(const int n);
class Characters
{
public:
static const CArray<std::string, 32> stand;
virtual ~Characters();
virtual const std::string& getDan(const size_t index) const = 0;
virtual const std::string& getSuji(const size_t index) const = 0;
virtual const std::string& getPiece(const size_t index) const = 0;
/** 持ち駒の漢字文字を返す。1文字を期待する */
const std::string& getStand(const size_t index) const
{
return stand[index];
}
const std::string& stand_kanji(const PtypeO& ptypeo) const
{
return getStand(piece_index(ptypeo));
}
const std::string& kanji(const PtypeO& ptypeo) const
{
return getPiece(piece_index(ptypeo));
}
const std::string& kanji(Ptype ptype) const
{
return getPiece(newPtypeO(BLACK, ptype));
}
private:
size_t piece_index(const PtypeO& ptypeo) const
{
#ifndef NDEBUG
static const size_t NPieces = PTYPEO_MAX - PTYPEO_MIN+2;
#endif
const size_t index = ptypeo - PTYPEO_MIN;
assert(index < NPieces);
return index;
}
};
struct StandardCharacters : public Characters
{
static const CArray<std::string,10> dan;
static const CArray<std::string,10> suji;
static const CArray<std::string,32> pieces;
const std::string& getDan(const size_t index) const {return dan[index];}
const std::string& getSuji(const size_t index) const {return suji[index];}
const std::string& getPiece(const size_t index) const {return pieces[index];}
};
struct RussianCharacters : public Characters
{
static const CArray<std::string,10> dan;
static const CArray<std::string,10> suji;
static const CArray<std::string,32> pieces;
const std::string& getDan(const size_t index) const {return dan[index];}
const std::string& getSuji(const size_t index) const {return suji[index];}
const std::string& getPiece(const size_t index) const {return pieces[index];}
};
struct KIFCharacters : public Characters
{
static const CArray<std::string,10> dan;
static const CArray<std::string,10> suji;
static const CArray<std::string,32> pieces;
const std::string& getDan(const size_t index) const {return dan[index];}
const std::string& getSuji(const size_t index) const {return suji[index];}
const std::string& getPiece(const size_t index) const {return pieces[index];}
};
class KanjiPrint
{
private:
std::ostream& os;
const std::shared_ptr<Characters> pieces;
Color black_color;
Color white_color;
Color last_move_color;
public:
explicit KanjiPrint(std::ostream& os,
const std::shared_ptr<Characters> pieces=std::shared_ptr<Characters>(new StandardCharacters()))
: os(os), pieces(pieces),
black_color(Color::NONE),
white_color(Color::NONE),
last_move_color(Color::NONE) {}
~KanjiPrint() {}
void print(const SimpleState& state,
const Move *last_move=NULL) const;
void setBlackColor(const Color& c) {black_color = c;}
void setWhiteColor(const Color& c) {white_color = c;}
void setLastMoveColor(const Color& c) {last_move_color = c;}
};
} // namespace record
} // namespace osl
#endif /* RECORD_KANJIPRINT_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::CArray
Definition container.h:20
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::SimpleState
Definition simpleState.h:35
osl::record::ChangeShellColor::escColSet
void escColSet() const
Definition kanjiPrint.cc:162
osl::record::ChangeShellColor::color
const Color color
Definition kanjiPrint.h:81
osl::record::ChangeShellColor::ChangeShellColor
ChangeShellColor(std::ostream &os, const Color &color)
Definition kanjiPrint.h:86
osl::record::ChangeShellColor::os
std::ostream & os
Definition kanjiPrint.h:80
osl::record::ChangeShellColor::escColReSet
void escColReSet() const
Definition kanjiPrint.cc:169
osl::record::ChangeShellColor::~ChangeShellColor
~ChangeShellColor()
Definition kanjiPrint.h:88
osl::record::Characters
駒の文字を管理するAbstract class。
Definition kanjiPrint.h:98
osl::record::Characters::getDan
virtual const std::string & getDan(const size_t index) const =0
段数の文字を返す
osl::record::Characters::stand
static const CArray< std::string, 32 > stand
Definition kanjiPrint.h:100
osl::record::Characters::kanji
const std::string & kanji(const PtypeO &ptypeo) const
Definition kanjiPrint.h:122
osl::record::Characters::getPiece
virtual const std::string & getPiece(const size_t index) const =0
盤面上の駒を返す
osl::record::Characters::getStand
const std::string & getStand(const size_t index) const
持ち駒の漢字文字を返す。1文字を期待する
Definition kanjiPrint.h:112
osl::record::Characters::~Characters
virtual ~Characters()
Definition kanjiPrint.cc:96
osl::record::Characters::kanji
const std::string & kanji(Ptype ptype) const
Definition kanjiPrint.h:126
osl::record::Characters::piece_index
size_t piece_index(const PtypeO &ptypeo) const
Definition kanjiPrint.h:131
osl::record::Characters::stand_kanji
const std::string & stand_kanji(const PtypeO &ptypeo) const
Definition kanjiPrint.h:117
osl::record::Characters::getSuji
virtual const std::string & getSuji(const size_t index) const =0
筋の文字を返す。駒の文字幅に合わせる必要がある。
osl::record::Color
カラーコードを保持するクラス。
Definition kanjiPrint.h:23
osl::record::Color::value
std::string value
Definition kanjiPrint.h:29
osl::record::Color::Red
static const Color Red
Definition kanjiPrint.h:54
osl::record::Color::name
std::string name
Definition kanjiPrint.h:30
osl::record::Color::Cyan
static const Color Cyan
Definition kanjiPrint.h:59
osl::record::Color::valid
bool valid
Definition kanjiPrint.h:31
osl::record::Color::Yellow
static const Color Yellow
Definition kanjiPrint.h:64
osl::record::Color::Brown
static const Color Brown
Definition kanjiPrint.h:56
osl::record::Color::operator!=
bool operator!=(const Color &rhs) const
Definition kanjiPrint.h:40
osl::record::Color::Color
Color()
Definition kanjiPrint.h:25
osl::record::Color::Purple
static const Color Purple
Definition kanjiPrint.h:58
osl::record::Color::~Color
~Color()
Definition kanjiPrint.cc:64
osl::record::Color::White
static const Color White
Definition kanjiPrint.h:68
osl::record::Color::colorFor
static const Color colorFor(const std::string &str)
文字列に対応するColor objectを返す
Definition kanjiPrint.cc:40
osl::record::Color::LightGreen
static const Color LightGreen
Definition kanjiPrint.h:63
osl::record::Color::LightCyan
static const Color LightCyan
Definition kanjiPrint.h:67
osl::record::Color::Black
static const Color Black
Definition kanjiPrint.h:53
osl::record::Color::operator==
bool operator==(const Color &rhs) const
Definition kanjiPrint.h:35
osl::record::Color::LightGray
static const Color LightGray
Definition kanjiPrint.h:60
osl::record::Color::Blue
static const Color Blue
Definition kanjiPrint.h:57
osl::record::Color::LightBlue
static const Color LightBlue
Definition kanjiPrint.h:65
osl::record::Color::DarkGray
static const Color DarkGray
Definition kanjiPrint.h:61
osl::record::Color::Green
static const Color Green
Definition kanjiPrint.h:55
osl::record::Color::operator<<
friend std::ostream & operator<<(std::ostream &os, const Color &c)
osl::record::Color::isValid
bool isValid() const
Definition kanjiPrint.h:33
osl::record::Color::LightRed
static const Color LightRed
Definition kanjiPrint.h:62
osl::record::Color::NONE
static const Color NONE
色指定しない（デフォルトのまま）ことを示す特別なオブジェクト
Definition kanjiPrint.h:52
osl::record::Color::getName
const std::string & getName() const
Definition kanjiPrint.h:34
osl::record::Color::LightPurple
static const Color LightPurple
Definition kanjiPrint.h:66
osl::record::KanjiPrint::os
std::ostream & os
Definition kanjiPrint.h:187
osl::record::KanjiPrint::black_color
Color black_color
Definition kanjiPrint.h:189
osl::record::KanjiPrint::white_color
Color white_color
Definition kanjiPrint.h:190
osl::record::KanjiPrint::KanjiPrint
KanjiPrint(std::ostream &os, const std::shared_ptr< Characters > pieces=std::shared_ptr< Characters >(new StandardCharacters()))
Definition kanjiPrint.h:194
osl::record::KanjiPrint::setLastMoveColor
void setLastMoveColor(const Color &c)
Definition kanjiPrint.h:212
osl::record::KanjiPrint::setWhiteColor
void setWhiteColor(const Color &c)
Definition kanjiPrint.h:211
osl::record::KanjiPrint::print
void print(const SimpleState &state, const Move *last_move=NULL) const
出力
Definition kanjiPrint.cc:176
osl::record::KanjiPrint::pieces
const std::shared_ptr< Characters > pieces
Definition kanjiPrint.h:188
osl::record::KanjiPrint::~KanjiPrint
~KanjiPrint()
Definition kanjiPrint.h:200
osl::record::KanjiPrint::setBlackColor
void setBlackColor(const Color &c)
Definition kanjiPrint.h:210
osl::record::KanjiPrint::last_move_color
Color last_move_color
Definition kanjiPrint.h:191
osl::record
棋譜関係
Definition checkDuplicate.h:15
osl::record::kanjiNumber
std::string kanjiNumber(const int n)
漢数字を返す（持ち駒の数などで用いる）
Definition kanjiPrint.cc:69
osl::record::operator<<
std::ostream & operator<<(std::ostream &os, const Color &c)
Definition kanjiPrint.cc:156
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
osl::PTYPEO_MAX
@ PTYPEO_MAX
Definition basic_type.h:201
osl::PTYPEO_MIN
@ PTYPEO_MIN
Definition basic_type.h:200
osl::newPtypeO
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
simpleState.h
osl::record::KIFCharacters
柿木形式（KIF）。頭にv
Definition kanjiPrint.h:171
osl::record::KIFCharacters::dan
static const CArray< std::string, 10 > dan
Definition kanjiPrint.h:172
osl::record::KIFCharacters::pieces
static const CArray< std::string, 32 > pieces
Definition kanjiPrint.h:143
osl::record::KIFCharacters::getSuji
const std::string & getSuji(const size_t index) const
筋の文字を返す。駒の文字幅に合わせる必要がある。
Definition kanjiPrint.h:177
osl::record::KIFCharacters::suji
static const CArray< std::string, 10 > suji
Definition kanjiPrint.h:141
osl::record::KIFCharacters::getPiece
const std::string & getPiece(const size_t index) const
盤面上の駒を返す
Definition kanjiPrint.h:178
osl::record::KIFCharacters::getDan
const std::string & getDan(const size_t index) const
段数の文字を返す
Definition kanjiPrint.h:176
osl::record::RussianCharacters
ロシア文字（激指フォント用）
Definition kanjiPrint.h:159
osl::record::RussianCharacters::getDan
const std::string & getDan(const size_t index) const
段数の文字を返す
Definition kanjiPrint.h:164
osl::record::RussianCharacters::suji
static const CArray< std::string, 10 > suji
Definition kanjiPrint.h:161
osl::record::RussianCharacters::getSuji
const std::string & getSuji(const size_t index) const
筋の文字を返す。駒の文字幅に合わせる必要がある。
Definition kanjiPrint.h:165
osl::record::RussianCharacters::dan
static const CArray< std::string, 10 > dan
Definition kanjiPrint.h:160
osl::record::RussianCharacters::getPiece
const std::string & getPiece(const size_t index) const
盤面上の駒を返す
Definition kanjiPrint.h:166
osl::record::RussianCharacters::pieces
static const CArray< std::string, 32 > pieces
Definition kanjiPrint.h:128
osl::record::StandardCharacters
持ち駒用（標準文字）
Definition kanjiPrint.h:144
osl::record::StandardCharacters::getSuji
const std::string & getSuji(const size_t index) const
筋の文字を返す。駒の文字幅に合わせる必要がある。
Definition kanjiPrint.h:153
osl::record::StandardCharacters::getDan
const std::string & getDan(const size_t index) const
段数の文字を返す
Definition kanjiPrint.h:152
osl::record::StandardCharacters::pieces
static const CArray< std::string, 32 > pieces
盤面上の駒の漢字文字
Definition kanjiPrint.h:115
osl::record::StandardCharacters::getPiece
const std::string & getPiece(const size_t index) const
盤面上の駒を返す
Definition kanjiPrint.h:154
osl::record::StandardCharacters::dan
static const CArray< std::string, 10 > dan
段数の文字
Definition kanjiPrint.h:111
osl::record::StandardCharacters::suji
static const CArray< std::string, 10 > suji
筋の文字。駒の文字幅に合わせる必要がある。
Definition kanjiPrint.h:113