Go to the documentation of this file.00001 #ifndef OSL_KISEN_H
00002 #define OSL_KISEN_H
00003
00004 #include "osl/record/record.h"
00005 #include "osl/state/numEffectState.h"
00006 #include "osl/misc/carray.h"
00007 #include <boost/date_time/gregorian/gregorian_types.hpp>
00008 #include <string>
00009 #include <iosfwd>
00010 #include <fstream>
00011 namespace osl
00012 {
00013 namespace record
00014 {
00015 class KisenUtils{
00016 public:
00017 static Square convertSquare( int pos );
00018 static Move convertMove(state::SimpleState const& state,int c0,int c1 );
00019 static int convertSquare(Square pos);
00020 };
00021
00022 class IKisenStream : public IRecordStream{
00023 private:
00024 CArray<unsigned char, 512> cbuf;
00025 state::SimpleState state;
00026 RecordVisitor rv;
00027 public:
00028 IKisenStream(char const readbuf[]) : state(HIRATE) {
00029 std::copy(&readbuf[0],&readbuf[512],&cbuf[0]);
00030 }
00031 state::SimpleState getState() const { return state;}
00032 virtual void load(Record*);
00033 virtual ~IKisenStream(){};
00034 };
00039 class KisenFile{
00040 private:
00041 std::ifstream ifs;
00042 size_t numberOfGames;
00043 state::SimpleState const initialState;
00044 const std::string fileName;
00045 public:
00046 static const size_t maxMoves=256;
00047 explicit KisenFile(const std::string& fileName);
00048 ~KisenFile();
00049
00050 size_t size() const{ return numberOfGames; }
00051 const NumEffectState getInitialState() const{ return NumEffectState(initialState); }
00052 const vector<Move> getMoves(size_t index);
00053 const std::string& getFileName() const { return fileName; }
00054 const std::string ipxFileName() const { return ipxFileName(fileName); }
00055 static const std::string ipxFileName(const std::string&);
00056 };
00082 class KisenIpxFile{
00083 std::ifstream ifs;
00084 size_t numberOfGames;
00085 const std::string file_name;
00086 public:
00087 enum{
00088 BY_PARITY=0,
00089 BLACK_WIN=1,
00090 WHITE_WIN=2,
00091 SENNNICHITE=3,
00092 JISHOGI=4,
00093 BLACK_WIN_256=5,
00094 WHITE_WIN_256=6,
00095 SENNNICHITE_256=7,
00096 JISHOGI_256=8,
00097 };
00098 explicit KisenIpxFile(std::string const& fileName);
00099 ~KisenIpxFile();
00100
00101 size_t size() const{ return numberOfGames; }
00102 const std::string getPlayer(size_t index,Player pl);
00103 const std::string getTitle(size_t index,Player pl);
00104 unsigned int getRating(size_t index,Player pl);
00105 unsigned int getResult(size_t index);
00106 const std::string& getFileName() const { return file_name; }
00110 boost::gregorian::date getStartDate(size_t index);
00111 };
00116 class KisenPlusFile{
00117 private:
00118 std::ifstream ifs;
00119 size_t numberOfGames;
00120 SimpleState const initialState;
00121 public:
00122 static const size_t maxMoves=256;
00123 explicit KisenPlusFile(const std::string& fileName);
00124 size_t size() const{ return numberOfGames; }
00125 SimpleState const& getInitialState() const{ return initialState; }
00126 const vector<Move> getMoves(size_t index);
00127 void getMoves(size_t index, vector<Move>&, vector<int>&);
00128 };
00129
00130 class OKisenStream : public ORecordStream {
00131 public:
00132 OKisenStream(std::ostream &ostream) : os(ostream) { }
00133 void save(const SimpleState& state, const vector<Move> &moves);
00134 virtual void save(Record *);
00135 virtual ~OKisenStream() { }
00136 private:
00137 std::ostream &os;
00138 };
00139
00146 class KisenIpxWriter
00147 {
00148 public:
00149 KisenIpxWriter(std::ostream &ostream) : os(ostream) { }
00150 void save(const Record &,
00151 int black_rating, int white_rating,
00152 const std::string &black_title,
00153 const std::string &white_title);
00154 private:
00155 void writeString(const std::string &name, size_t length);
00156 void writeRating(int rating);
00157 void writeStartDate(int year, int month, int day, int hour, int min);
00158 std::ostream &os;
00159 };
00160 }
00161 using record::KisenFile;
00162 using record::KisenIpxFile;
00163 }
00164 #endif // OSL_KISEN_H
00165
00166
00167
00168