libkombilo  0.8
/home/ug/devel/kombilo-py-dev/kombilo/libkombilo/sgfparser.h
Go to the documentation of this file.
1 
26 #ifndef _SGFPARSER_H_
27 #define _SGFPARSER_H_
28 
29 #include <string>
30 #include <vector>
31 #include <utility>
32 #include <stack>
33 #include <map>
34 using namespace std;
35 
36 
37 class SGFError {
38  public:
39  SGFError();
40 };
41 
43  public:
44  int length;
45  int* data; // "even" entries: go right, "odd" entries: go down in game tree.
46 
48  ExtendedMoveNumber(int LENGTH, int* DATA);
49  ExtendedMoveNumber(int D);
52 
53  ExtendedMoveNumber& operator=(const ExtendedMoveNumber& emn);
54  void next();
55  void down() throw(SGFError);
56  int total_move_num();
57  // void down();
58 };
59 
60 
61 char* SGFescape(const char* s);
62 
63 class Cursor;
64 
65 class PropValue {
66  public:
67  PropValue(std::string IDC, std::vector<std::string>* PV);
68  PropValue(const PropValue& pval);
69  ~PropValue();
70  std::string IDcomplete;
71  std::vector<std::string>* pv;
72 };
73 
74 class Node {
75  public:
76  Node* previous;
77  Node* next;
78  Node* up;
79  Node* down;
80  int numChildren;
81  std::string SGFstring;
82  int parsed;
83  std::vector<std::string> gpv(const string& prop);
84  std::vector<std::string>* get_property_value(const string& prop);
85  void set_property_value(const string& IDcomplete, vector<string> propValue) throw(SGFError);
86  void add_property_value(const string& IDcomplete, vector<string> propValue) throw(SGFError);
87  void del_property_value(const string& IDcomplete) throw(SGFError); // delete data[ID]
88  vector<string> keys();
89 
90  int posyD; // used when displaying SGF structure graphically as a tree
91 
92  Node(Node* prev, char* SGFst) throw(SGFError);
93  ~Node();
94  ExtendedMoveNumber get_move_number();
95  void parseNode() throw(SGFError);
96  static int sloppy;
97  int level;
98  private:
99  std::map<std::string, PropValue> data; // use get_property_value to access this
100 
101  friend class Cursor;
102 };
103 
104 typedef char* char_p;
105 
106 std::vector<std::string>* parseRootNode(Node* n, std::vector<std::string>* tags) throw(SGFError);
107 
108 class Cursor {
109  public:
110  Cursor(const char* sgf, int sloppy) throw(SGFError);
111  ~Cursor();
112 
113  int atStart;
114  int atEnd;
115  int height;
116  int width;
117  Node* root;
118  Node* currentN;
119  int posx;
120  int posy;
121 
122  void parse(const char* s) throw(SGFError);
123  void game(int n) throw(SGFError);
124  Node* next(int n=0) throw(SGFError);
125  Node* previous() throw(SGFError);
126  Node* getRootNode(int n) throw(SGFError);
127  char* outputVar(Node* node);
128  char* output();
129  void add(char* st);
130  void delVariation(Node* node);
131  void setFlags();
132 
133  protected:
134  void delVar(Node* node);
135  void deltree(Node* node);
136 
137 };
138 
139 std::string nodeToString(std::map<std::string, PropValue >& data) throw(SGFError);
140 // char* rootNodeToString(PyObject* data);
141 
142 #endif
143 
Definition: sgfparser.h:108
Definition: sgfparser.h:65
Definition: sgfparser.h:74
Definition: sgfparser.h:37
STL namespace.
Definition: sgfparser.h:42