Go to the documentation of this file.00001 #ifndef _RECORD_H
00002 #define _RECORD_H
00003 #include "osl/record/searchInfo.h"
00004 #include "osl/move.h"
00005 #include "osl/state/numEffectState.h"
00006 #include "osl/misc/carray.h"
00007 #include "osl/misc/align16New.h"
00008 #include <boost/date_time/gregorian/gregorian_types.hpp>
00009 #include <boost/ptr_container/ptr_vector.hpp>
00010 #include <iosfwd>
00011
00012 namespace osl
00013 {
00014 namespace record
00015 {
00016 class Record;
00017 class IRecordStream{
00018 public:
00019 virtual void load(Record*)=0;
00020 virtual ~IRecordStream();
00021 private:
00022 };
00023 class ORecordStream{
00024 public:
00025 virtual void save(Record*)=0;
00026 virtual ~ORecordStream();
00027 private:
00028 };
00029
00030 enum NodeType{
00031 MOVE,
00032 TORYO,
00033 MATTA,
00034 CHUDAN,
00035 SENNICHITE,
00036 JISHOGI,
00037 TSUMI,
00038 FUZUMI,
00039 ND_ERROR,
00040 KACHI,
00041 HIKIWAKE,
00042 };
00043
00049 class MoveRecord{
00050 private:
00051 Move move;
00052 int nodeIndex;
00053 int time;
00054 std::string comment;
00055 public:
00056 SearchInfo info;
00057
00058 MoveRecord(const Move& mv, int ni);
00059 const Move getMove() const;
00060 int getNodeIndex() const;
00061 void setTime(int t);
00062 int getTime() const{ return time; }
00063 void setComment(const std::string& com){ comment=com; }
00064 void addComment(const std::string& com)
00065 {
00066 if (! comment.empty())
00067 comment += "\n";
00068 comment += com;
00069 }
00070 const std::string& getComment() const{ return comment; }
00071 };
00072
00073 class NodeRecord{
00074 private:
00075 NodeType type;
00076 vector<int> moves;
00077 std::string comment;
00078 public:
00079 NodeRecord():type(MOVE){}
00080 NodeType getType() const{ return type; }
00081 int size() const { return moves.size(); }
00082 int at(int index) const{ return moves.at(index); }
00083 void setComment(const std::string& com){ comment=com; }
00084 const std::string& getComment() const{ return comment; }
00085 void addMoveRecord(int moveIndex);
00086 };
00087
00088 class Record
00089 #if OSL_WORDSIZE == 32
00090 : public misc::Align16New
00091 #endif
00092 {
00093 public:
00094 enum ResultType {
00095 UNKNOWN=0,
00096 BLACK_WIN=1,
00097 WHITE_WIN=2,
00098 SENNNICHITE=3,
00099 JISHOGI=4,
00100 };
00101 private:
00102 SimpleState initialState;
00103 std::string version, initial_comment, tounament_name;
00104 CArray<std::string,2> playerNames;
00105 vector<NodeRecord> nrs;
00106 vector<MoveRecord> mrs;
00107 ResultType result;
00108 boost::gregorian::date start_date;
00109 public:
00110 Record();
00111 void init();
00112 void setVersion(const std::string& str);
00113 const std::string getVersion() const { return version; }
00114 void addInitialComment(const std::string& comment)
00115 {
00116 if (! initial_comment.empty())
00117 initial_comment += "\n";
00118 initial_comment += comment;
00119 }
00120 const std::string getInitialComment() const
00121 {
00122 return initial_comment;
00123 }
00124 void setPlayer(Player player,const std::string& str);
00125 const std::string& getPlayer(Player player) const;
00126 void setInitialState(const SimpleState& state);
00127 const NumEffectState getInitialState() const;
00128 int addNodeRecord();
00129 int addMoveRecord(const MoveRecord& moveRecord);
00130 NodeRecord* nodeOf(int index);
00131 NodeRecord& operator[](int index);
00132 MoveRecord* moveOf(int index);
00133 void load(IRecordStream&);
00134 void save(ORecordStream&);
00135 const vector<Move> getMoves() const;
00136 void getMoves(vector<Move>&, vector<int>&) const;
00137 void getMoves(vector<Move>&, vector<int>&, vector<std::string>&,
00138 vector<SearchInfo>&) const;
00139 const NodeRecord* nodeOf(int index) const;
00140 const MoveRecord* moveOf(int index) const;
00141 void setResult(ResultType new_result) { result = new_result; }
00142 ResultType getResult() const { return result; }
00143 void setTounamentName(const std::string& name) { tounament_name = name; }
00144 const std::string& tounamentName() const { return tounament_name; }
00150 void setDate(const std::string& date_str);
00151 void setDate(const boost::gregorian::date& date);
00152 boost::gregorian::date getDate() const;
00153 };
00154
00155 class RecordVisitor;
00156
00157 class RecordVisitorObserver {
00158 public:
00159 virtual ~RecordVisitorObserver() {}
00160 virtual void update(RecordVisitor* rv) = 0;
00161 };
00162
00163 class RecordVisitor{
00164 private:
00165 Record* rec;
00166 SimpleState* state;
00167 int lastMoveIndex;
00168 int nodeIndex;
00169 boost::ptr_vector<RecordVisitorObserver> observers;
00170 public:
00171 RecordVisitor():rec(NULL),state(NULL),lastMoveIndex(0),nodeIndex(0){}
00172 RecordVisitor(Record& r);
00173 ~RecordVisitor();
00174
00175 SimpleState *getState() const{ return state; }
00176 void setState(SimpleState *s){ state=s;}
00177 Record *getRecord() { return rec; }
00178 void setRecord(Record *r){ rec=r;}
00179 MoveRecord *getLastMove(){ return rec->moveOf(lastMoveIndex); }
00180 void addMoveAndAdvance(Move move);
00181 NodeRecord *getNode(){ return rec->nodeOf(nodeIndex); }
00182 void addObserver(RecordVisitorObserver *observer)
00183 { observers.push_back(observer); }
00184 };
00185
00186 std::ostream& operator<<(std::ostream&,const MoveRecord &);
00187 std::ostream& operator<<(std::ostream&,Record &);
00188
00189 int readInt(std::istream& is);
00190 void writeInt(std::ostream& os, int n);
00191 }
00192 using record::Record;
00193 }
00194 #endif
00195
00196
00197
00198