All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
record.h
Go to the documentation of this file.
1 #ifndef _RECORD_H
2 #define _RECORD_H
4 #include "osl/move.h"
6 #include "osl/misc/carray.h"
7 #include "osl/misc/align16New.h"
8 #include <boost/date_time/gregorian/gregorian_types.hpp>
9 #include <boost/ptr_container/ptr_vector.hpp>
10 #include <iosfwd>
11 
12 namespace osl
13 {
14  namespace record
15  {
16  class Record;
18  public:
19  virtual void load(Record*)=0;
20  virtual ~IRecordStream();
21  private:
22  };
24  public:
25  virtual void save(Record*)=0;
26  virtual ~ORecordStream();
27  private:
28  };
29 
30  enum NodeType{
39  ND_ERROR, // ERROR conflicts with ERROR macro on windows
42  };
43 
49  class MoveRecord{
50  private:
52  int nodeIndex;
53  int time;
54  std::string comment;
55  public:
57 
58  MoveRecord(const Move& mv, int ni);
59  const Move getMove() const;
60  int getNodeIndex() const;
61  void setTime(int t);
62  int getTime() const{ return time; }
63  void setComment(const std::string& com){ comment=com; }
64  void addComment(const std::string& com)
65  {
66  if (! comment.empty())
67  comment += "\n";
68  comment += com;
69  }
70  const std::string& getComment() const{ return comment; }
71  };
72 
73  class NodeRecord{
74  private:
76  vector<int> moves;
77  std::string comment;
78  public:
80  NodeType getType() const{ return type; }
81  int size() const { return moves.size(); }
82  int at(int index) const{ return moves.at(index); }
83  void setComment(const std::string& com){ comment=com; }
84  const std::string& getComment() const{ return comment; }
85  void addMoveRecord(int moveIndex);
86  };
87 
88  class Record
89 #if OSL_WORDSIZE == 32
90  : public misc::Align16New
91 #endif
92  {
93  public:
94  enum ResultType {
95  UNKNOWN=0,
98  SENNNICHITE=3,
100  };
101  private:
102  SimpleState initialState;
103  std::string version, initial_comment, tounament_name;
104  CArray<std::string,2> playerNames;
105  vector<NodeRecord> nrs;
106  vector<MoveRecord> mrs;
108  boost::gregorian::date start_date; // default : not_a_date_time
109  public:
110  Record();
111  Record(const SimpleState& initial, const vector<Move>& moves);
112  void init();
113  void setVersion(const std::string& str);
114  const std::string getVersion() const { return version; }
115  void addInitialComment(const std::string& comment)
116  {
117  if (! initial_comment.empty())
118  initial_comment += "\n";
119  initial_comment += comment;
120  }
121  const std::string getInitialComment() const
122  {
123  return initial_comment;
124  }
125  void setPlayer(Player player,const std::string& str);
126  const std::string& getPlayer(Player player) const;
127  void setInitialState(const SimpleState& state);
128  const NumEffectState getInitialState() const;
129  int addNodeRecord();
130  int addMoveRecord(const MoveRecord& moveRecord);
131  NodeRecord* nodeOf(int index);
132  NodeRecord& operator[](int index);
133  MoveRecord* moveOf(int index);
134  void load(IRecordStream&);
135  void save(ORecordStream&);
136  const vector<Move> getMoves() const;
137  void getMoves(vector<Move>&, vector<int>&) const;
138  void getMoves(vector<Move>&, vector<int>&, vector<std::string>&,
139  vector<SearchInfo>&) const;
140  const NodeRecord* nodeOf(int index) const;
141  const MoveRecord* moveOf(int index) const;
142  size_t moveRecordSize() const {return mrs.size();}
143  void setResult(ResultType new_result) { result = new_result; }
144  ResultType getResult() const { return result; }
145  void setTounamentName(const std::string& name) { tounament_name = name; }
146  const std::string& tounamentName() const { return tounament_name; }
152  void setDate(const std::string& date_str);
153  void setDate(const boost::gregorian::date& date);
154  boost::gregorian::date getDate() const;
155  };
156 
157  class RecordVisitor;
158 
160  public:
162  virtual void update(RecordVisitor* rv) = 0;
163  };
164 
166  private:
168  SimpleState* state;
171  boost::ptr_vector<RecordVisitorObserver> observers;
172  public:
174  RecordVisitor(Record& r);
175  ~RecordVisitor();
176 
177  SimpleState *getState() const{ return state; }
178  void setState(SimpleState *s){ state=s;}
179  Record *getRecord() { return rec; }
180  void setRecord(Record *r){ rec=r;}
182  void addMoveAndAdvance(Move move);
185  { observers.push_back(observer); }
186  };
187 
188  std::ostream& operator<<(std::ostream&,const MoveRecord &);
189  std::ostream& operator<<(std::ostream&,Record &);
190 
191  int readInt(std::istream& is);
192  void writeInt(std::ostream& os, int n);
193  } // namespace record
194  using record::Record;
195 } // namespace osl
196 #endif /* _RECORD_H */
197 // ;;; Local Variables:
198 // ;;; mode:c++
199 // ;;; c-basic-offset:2
200 // ;;; End: