libkombilo
0.7
|
00001 00026 #ifndef _SGFPARSER_H_ 00027 #define _SGFPARSER_H_ 00028 00029 #include <string> 00030 #include <vector> 00031 #include <utility> 00032 #include <stack> 00033 #include <map> 00034 using namespace std; 00035 00036 00037 class SGFError { 00038 public: 00039 SGFError(); 00040 }; 00041 00042 class ExtendedMoveNumber { 00043 public: 00044 int length; 00045 int* data; // "even" entries: go right, "odd" entries: go down in game tree. 00046 00047 ExtendedMoveNumber(); 00048 ExtendedMoveNumber(int LENGTH, int* DATA); 00049 ExtendedMoveNumber(int D); 00050 ExtendedMoveNumber(const ExtendedMoveNumber& emn); 00051 ~ExtendedMoveNumber(); 00052 00053 ExtendedMoveNumber& operator=(const ExtendedMoveNumber& emn); 00054 void next(); 00055 void down() throw(SGFError); 00056 int total_move_num(); 00057 // void down(); 00058 }; 00059 00060 00061 char* SGFescape(const char* s); 00062 00063 class Cursor; 00064 00065 class PropValue { 00066 public: 00067 PropValue(std::string IDC, std::vector<std::string>* PV); 00068 PropValue(const PropValue& pval); 00069 ~PropValue(); 00070 std::string IDcomplete; 00071 std::vector<std::string>* pv; 00072 }; 00073 00074 class Node { 00075 public: 00076 Node* previous; 00077 Node* next; 00078 Node* up; 00079 Node* down; 00080 int numChildren; 00081 std::string SGFstring; 00082 int parsed; 00083 std::vector<std::string> gpv(const string& prop); 00084 std::vector<std::string>* get_property_value(const string& prop); 00085 void set_property_value(const string& IDcomplete, vector<string> propValue) throw(SGFError); 00086 void add_property_value(const string& IDcomplete, vector<string> propValue) throw(SGFError); 00087 void del_property_value(const string& IDcomplete) throw(SGFError); // delete data[ID] 00088 vector<string> keys(); 00089 00090 int posyD; // used when displaying SGF structure graphically as a tree 00091 00092 Node(Node* prev, char* SGFst) throw(SGFError); 00093 ~Node(); 00094 ExtendedMoveNumber get_move_number(); 00095 void parseNode() throw(SGFError); 00096 static int sloppy; 00097 int level; 00098 private: 00099 std::map<std::string, PropValue> data; // use get_property_value to access this 00100 00101 friend class Cursor; 00102 }; 00103 00104 typedef char* char_p; 00105 00106 std::vector<std::string>* parseRootNode(Node* n, std::vector<std::string>* tags) throw(SGFError); 00107 00108 class Cursor { 00109 public: 00110 Cursor(const char* sgf, int sloppy) throw(SGFError); 00111 ~Cursor(); 00112 00113 int atStart; 00114 int atEnd; 00115 int height; 00116 int width; 00117 Node* root; 00118 Node* currentN; 00119 int posx; 00120 int posy; 00121 00122 void parse(const char* s) throw(SGFError); 00123 void game(int n) throw(SGFError); 00124 Node* next(int n=0) throw(SGFError); 00125 Node* previous() throw(SGFError); 00126 Node* getRootNode(int n) throw(SGFError); 00127 char* outputVar(Node* node); 00128 char* output(); 00129 void add(char* st); 00130 void delVariation(Node* node); 00131 void setFlags(); 00132 00133 protected: 00134 void delVar(Node* node); 00135 void deltree(Node* node); 00136 00137 }; 00138 00139 std::string nodeToString(std::map<std::string, PropValue >& data) throw(SGFError); 00140 // char* rootNodeToString(PyObject* data); 00141 00142 #endif 00143