All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
kisen.h
Go to the documentation of this file.
1 #ifndef OSL_KISEN_H
2 #define OSL_KISEN_H
3 
4 #include "osl/record/record.h"
6 #include "osl/misc/carray.h"
7 #include <boost/date_time/gregorian/gregorian_types.hpp>
8 #include <string>
9 #include <iosfwd>
10 #include <fstream>
11 namespace osl
12 {
13  namespace record
14  {
15  class KisenUtils{
16  public:
17  static Square convertSquare( int pos );
18  static Move convertMove(state::SimpleState const& state,int c0,int c1 );
19  static int convertSquare(Square pos);
20  };
21 
22  class IKisenStream : public IRecordStream{
23  private:
24  CArray<unsigned char, 512> cbuf;
27  public:
28  IKisenStream(char const readbuf[]) : state(HIRATE) {
29  std::copy(&readbuf[0],&readbuf[512],&cbuf[0]);
30  }
31  state::SimpleState getState() const { return state;}
32  virtual void load(Record*);
33  virtual ~IKisenStream(){};
34  };
39  class KisenFile{
40  private:
41  std::ifstream ifs;
42  size_t numberOfGames;
44  const std::string fileName;
45  public:
46  static const size_t maxMoves=256;
47  explicit KisenFile(const std::string& fileName);
48  ~KisenFile();
49 
50  size_t size() const{ return numberOfGames; }
51  const NumEffectState getInitialState() const{ return NumEffectState(initialState); }
52  const vector<Move> getMoves(size_t index);
53  const std::string& getFileName() const { return fileName; }
54  const std::string ipxFileName() const { return ipxFileName(fileName); }
55  static const std::string ipxFileName(const std::string&);
56  };
82  class KisenIpxFile{
83  std::ifstream ifs;
84  size_t numberOfGames;
85  const std::string file_name;
86  public:
87  enum{
97  };
98  explicit KisenIpxFile(std::string const& fileName);
99  ~KisenIpxFile();
100 
101  size_t size() const{ return numberOfGames; }
102  const std::string getPlayer(size_t index,Player pl);
103  const std::string getTitle(size_t index,Player pl);
104  unsigned int getRating(size_t index,Player pl);
105  unsigned int getResult(size_t index);
106  const std::string& getFileName() const { return file_name; }
110  boost::gregorian::date getStartDate(size_t index);
111  };
117  private:
118  std::ifstream ifs;
120  SimpleState const initialState;
121  public:
122  static const size_t maxMoves=256;
123  explicit KisenPlusFile(const std::string& fileName);
124  size_t size() const{ return numberOfGames; }
125  SimpleState const& getInitialState() const{ return initialState; }
126  const vector<Move> getMoves(size_t index);
127  void getMoves(size_t index, vector<Move>&, vector<int>&);
128  };
129 
130  class OKisenStream : public ORecordStream {
131  public:
132  OKisenStream(std::ostream &ostream) : os(ostream) { }
133  void save(const SimpleState& state, const vector<Move> &moves);
134  virtual void save(Record *);
135  virtual ~OKisenStream() { }
136  private:
137  std::ostream &os;
138  };
139 
147  {
148  public:
149  KisenIpxWriter(std::ostream &ostream) : os(ostream) { }
150  void save(const Record &,
151  int black_rating, int white_rating,
152  const std::string &black_title,
153  const std::string &white_title);
154  private:
155  void writeString(const std::string &name, size_t length);
156  void writeRating(int rating);
157  void writeStartDate(int year, int month, int day, int hour, int min);
158  std::ostream &os;
159  };
160  } // namespace record
161  using record::KisenFile;
162  using record::KisenIpxFile;
163 } // namespace osl
164 #endif // OSL_KISEN_H
165 // ;;; Local Variables:
166 // ;;; mode:c++
167 // ;;; c-basic-offset:2
168 // ;;; End: