Go to the documentation of this file.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 class SgGameReader
00027 {
00028 public:
00029
00030
00031 enum WarningFlags {
00032
00033
00034
00035 INVALID_BOARDSIZE,
00036
00037 PROPERTY_WITHOUT_VALUE,
00038
00039
00040 NU_WARNING_FLAGS
00041 };
00042
00043
00044 typedef std::bitset<NU_WARNING_FLAGS> Warnings;
00045
00046
00047
00048
00049
00050
00051 SgGameReader(std::istream& in, int defaultSize = 19);
00052
00053
00054 Warnings GetWarnings() const;
00055
00056
00057
00058 void PrintWarnings(std::ostream& out) const;
00059
00060
00061
00062 SgNode* ReadGame();
00063
00064
00065
00066 void ReadGames(SgVectorOf<SgNode>* rootList);
00067
00068 private:
00069
00070 typedef std::map<std::string, std::vector<std::string> > RawProperties;
00071
00072 std::istream& m_in;
00073
00074 const int m_defaultSize;
00075
00076
00077 int m_fileFormat;
00078
00079 Warnings m_warnings;
00080
00081
00082 SgGameReader(const SgGameReader&);
00083
00084
00085 SgGameReader& operator=(const SgGameReader&);
00086
00087 static bool GetIntProp(const RawProperties& properties,
00088 const std::string& label, int& value);
00089
00090 void HandleProperties(SgNode* node, const RawProperties& properties,
00091 int& boardSize, SgPropPointFmt& fmt);
00092
00093 SgNode* ReadGame(bool resetWarnings);
00094
00095 std::string ReadLabel(int c);
00096
00097 SgNode* ReadSubtree(SgNode* node, int boardSize, SgPropPointFmt fmt);
00098
00099 bool ReadValue(std::string& value);
00100 };
00101
00102 inline SgGameReader::Warnings SgGameReader::GetWarnings() const
00103 {
00104 return m_warnings;
00105 }
00106
00107 inline SgNode* SgGameReader::ReadGame()
00108 {
00109 return ReadGame(true);
00110 }
00111
00112
00113
00114 #endif // SG_GAMEREADER_H