first-draft of crop feature and problem theme
[eidogo-ojd.git] / kombilo / sgfparser.h
blob9cea4b07b2c22d483cdaa84f8724c61673ec73e7
1 // File: sgfparser.h
2 // part of libkombilo, http://www.u-go.net/kombilo/
4 // Copyright (c) 2006 Ulrich Goertz <u@g0ertz.de>
6 // Permission is hereby granted, free of charge, to any person obtaining a copy of
7 // this software and associated documentation files (the "Software"), to deal in
8 // the Software without restriction, including without limitation the rights to
9 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10 // of the Software, and to permit persons to whom the Software is furnished to do
11 // so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
24 #ifndef _SGFPARSER_H_
25 #define _SGFPARSER_H_
27 #include <string>
28 #include <vector>
29 #include <utility>
30 #include <stack>
31 #include <map>
33 typedef std::pair<char,char> p_cc;
35 class SGFError {
36 public:
37 SGFError();
40 class ExtendedMoveNumber {
41 public:
42 int length;
43 int* data; // "even" entries: go right, "odd" entries: go down in game tree.
45 ExtendedMoveNumber();
46 ExtendedMoveNumber(int LENGTH, int* DATA);
47 ExtendedMoveNumber(int D);
48 ExtendedMoveNumber(const ExtendedMoveNumber& emn);
49 ~ExtendedMoveNumber();
51 ExtendedMoveNumber& operator=(const ExtendedMoveNumber& emn);
52 void next();
53 void down() throw(SGFError);
54 int total_move_num();
55 // void down();
59 char* SGFescape(const char* s);
61 class PropValue {
62 public:
63 PropValue(std::string IDC, std::vector<std::string>* PV);
64 ~PropValue();
65 std::string IDcomplete;
66 std::vector<std::string>* pv;
69 class Node {
70 public:
71 Node* previous;
72 Node* next;
73 Node* up;
74 Node* down;
75 int numChildren;
76 int level;
77 std::string SGFstring;
78 int parsed;
79 std::vector<std::string> gpv(const std::string& prop);
80 std::vector<std::string>* get_property_value(const std::string& prop);
81 void set_property_value(std::string& IDcomplete, std::vector<std::string>* propValue) throw(SGFError);
83 int posyD; // used when displaying SGF structure graphically as a tree
85 Node(Node* prev, char* SGFst, int lvl) throw(SGFError);
86 ~Node();
87 ExtendedMoveNumber get_move_number();
88 void parseNode() throw(SGFError);
89 static int sloppy;
90 private:
91 std::map<std::string, PropValue> data; // use get_property_value to access this
94 typedef char* char_p;
96 std::vector<std::string>* parseRootNode(Node* n, std::vector<std::string>* tags) throw(SGFError);
98 class Cursor {
99 public:
100 Cursor(const char* sgf, int sloppy) throw(SGFError);
101 ~Cursor();
103 int atStart;
104 int atEnd;
105 int height;
106 int width;
107 Node* root;
108 Node* currentN;
109 int posx;
110 int posy;
112 void parse(const char* s) throw(SGFError);
113 void game(int n) throw(SGFError);
114 void next(int n=0) throw(SGFError);
115 void previous() throw(SGFError);
116 Node* getRootNode(int n) throw(SGFError);
117 // void updateRootNode(PyObject* data, int n) throw(SGFError);
118 char* outputVar(Node* node);
119 char* output();
120 void add(char* st);
121 void delVariation(Node* node);
122 void setFlags();
124 protected:
125 void delVar(Node* node);
126 void deltree(Node* node);
130 std::string nodeToString(std::map<std::string, PropValue >& data) throw(SGFError);
131 // char* rootNodeToString(PyObject* data);
133 #endif