00001
00002
00003
00004
00005 #ifndef SG_GAMEREADER_H
00006 #define SG_GAMEREADER_H
00007
00008 #include <bitset>
00009 #include <map>
00010 #include <vector>
00011 #include "SgProp.h"
00012 #include "SgVector.h"
00013
00014 class SgNode;
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 class SgGameReader
00028 {
00029 public:
00030
00031
00032
00033 enum WarningFlags {
00034
00035
00036
00037
00038 INVALID_BOARDSIZE,
00039
00040 PROPERTY_WITHOUT_VALUE,
00041
00042
00043 NU_WARNING_FLAGS
00044 };
00045
00046
00047 typedef std::bitset<NU_WARNING_FLAGS> Warnings;
00048
00049
00050
00051
00052
00053
00054
00055 SgGameReader(std::istream& in, int defaultSize = 19);
00056
00057
00058 Warnings GetWarnings() const;
00059
00060
00061
00062
00063 void PrintWarnings(std::ostream& out) const;
00064
00065
00066
00067
00068 SgNode* ReadGame();
00069
00070
00071
00072
00073 void ReadGames(SgVectorOf<SgNode>* rootList);
00074
00075 private:
00076
00077 typedef std::map<std::string, std::vector<std::string> > RawProperties;
00078
00079 std::istream& m_in;
00080
00081 const int m_defaultSize;
00082
00083
00084 int m_fileFormat;
00085
00086 Warnings m_warnings;
00087
00088
00089 SgGameReader(const SgGameReader&);
00090
00091
00092 SgGameReader& operator=(const SgGameReader&);
00093
00094 static bool GetIntProp(const RawProperties& properties,
00095 const std::string& label, int& value);
00096
00097 void HandleProperties(SgNode* node, const RawProperties& properties,
00098 int& boardSize, SgPropPointFmt& fmt);
00099
00100 SgNode* ReadGame(bool resetWarnings);
00101
00102 std::string ReadLabel(int c);
00103
00104 SgNode* ReadSubtree(SgNode* node, int boardSize, SgPropPointFmt fmt);
00105
00106 bool ReadValue(std::string& value);
00107 };
00108
00109 inline SgGameReader::Warnings SgGameReader::GetWarnings() const
00110 {
00111 return m_warnings;
00112 }
00113
00114 inline SgNode* SgGameReader::ReadGame()
00115 {
00116 return ReadGame(true);
00117 }
00118
00119
00120
00121 #endif // SG_GAMEREADER_H