root/06/libkombilo/sgfparser.h

Revision 222, 3.8 kB (checked in by ug, 1 year ago)

Make SGF parser handle long property names.

Line 
1 // File: sgfparser.h
2 // part of libkombilo, http://www.u-go.net/kombilo/
3
4 // Copyright (c) 2006 Ulrich Goertz <u@g0ertz.de>
5
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.
23
24 #ifndef _SGFPARSER_H_
25 #define _SGFPARSER_H_
26
27 #include <string>
28 #include <vector>
29 #include <utility>
30 #include <stack>
31 #include <map>
32
33 typedef std::pair<char,char> p_cc;
34
35 class SGFError {
36   public:
37     SGFError();
38 };
39
40 class ExtendedMoveNumber {
41   public:
42     int length;
43     int* data; // "even" entries: go right, "odd" entries: go down in game tree.
44
45     ExtendedMoveNumber();
46     ExtendedMoveNumber(int LENGTH, int* DATA);
47     ExtendedMoveNumber(int D);
48     ExtendedMoveNumber(const ExtendedMoveNumber& emn);
49     ~ExtendedMoveNumber();
50
51     ExtendedMoveNumber& operator=(const ExtendedMoveNumber& emn);
52     void next();
53     void down() throw(SGFError);
54     int total_move_num();
55     // void down();
56 };
57
58
59 char* SGFescape(const char* s);
60
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;
67 };
68
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);
82
83     int posyD; // used when displaying SGF structure graphically as a tree
84
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
92 };
93
94 typedef char* char_p;
95
96 std::vector<std::string>* parseRootNode(Node* n, std::vector<std::string>* tags) throw(SGFError);
97
98 class Cursor {
99   public:
100     Cursor(const char* sgf, int sloppy) throw(SGFError);
101     ~Cursor();
102
103     int atStart;
104     int atEnd;
105     int height;
106     int width;
107     Node* root;
108     Node* currentN;
109     int posx;
110     int posy;
111
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(); 
123
124   protected:
125     void delVar(Node* node);
126     void deltree(Node* node);
127
128 };
129
130 std::string nodeToString(std::map<std::string, PropValue >& data) throw(SGFError);
131 // char* rootNodeToString(PyObject* data);
132
133 #endif
134
Note: See TracBrowser for help on using the browser.