4 ** code for reading and writing data in an xml-like format
6 ** the output from these routines may look a lot like xml, and may even
7 ** be wel-formed xml, but I don't think you should use it as that.
10 ** Copyright (C) 2000 Kurt Van den Branden
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License as published by
14 ** the Free Software Foundation; either version 2 of the License, or
15 ** (at your option) any later version.
17 ** This program is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ** GNU General Public License for more details.
22 ** You should have received a copy of the GNU General Public License
23 ** along with this program; if not, write to the Free Software
24 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 ** the following is an example of what you should be able to store:
30 <gipfgame type="tournament">
32 <whiteplayer type="human" fulltime="1200" timeleft="1197.562988" gipf="yes">
34 <blackplayer type="computer" fulltime="1200" timeleft="1196" gipf="no">
36 <nextplayer>white</nextplayer>
38 <!-- in between state of removing rows or gipf-pieces -->
41 <whitepieces>16</whitepieces>
42 <whitelost>0</whitelost>
43 <blackpieces>16</blackpieces>
44 <blacklost>0</blacklost>
45 <position color="white" type="piece">e2</position>
46 <position color="black" type="gipf">d5</position>
50 <move nr="1" player="white" type="gipf">e1-e2</move>
51 <move nr="1" player="black" type="piece">e1-e3</move>
52 <removerow owner="white">
53 <position color="black" type="piece">e2</position>
54 <position color="white" type="piece">e3</position>
55 <position color="white" type="piece">e4</position>
56 <position color="white" type="gipf">e5</position>
68 #include <ext/hash_map>
72 using namespace __gnu_cxx
;
76 bool operator()(const string
& s1
, const string
& s2
) const
85 bool operator()(const string
& s
) const
88 return (H (s
.c_str()));
95 xmlite_entity (const char * ename
);
96 xmlite_entity (const string
& ename
);
97 xmlite_entity (const xmlite_entity
& source
)
98 { (*this) = source
; };
101 xmlite_entity
& operator= (const xmlite_entity
& source
);
103 int addcontent (xmlite_entity
* newcontent
);
104 int addattribute (const string
& aname
, const string
& avalue
);
105 int setvalue (const string
& newvalue
);
107 int writetofile (const char * filename
);
109 string
* escapechars (const string
& instring
);
110 void escapechars (string
& instring
);
111 string
* unescapechars (const string
& instring
);
112 void unescapechars (string
& instring
);
114 xmlite_entity
* getcontentbynr (const int nr
= 0);
115 xmlite_entity
* getcontentbyname (const string
& name
,
117 const string
& getvalue ()
119 const string
& getname ()
121 const string
& getattribute (const string key
)
122 { return (attributes
[key
]); };
127 vector
<xmlite_entity
*> contents
;
128 hash_map
<string
, string
, stringhash
, eqstring
> attributes
;
130 int writetostream (ostream
& ostr
);
131 void replaceall (string
& input
, const string
& from
, const string
& to
);
135 class xmlite_parser
{
137 xmlite_parser (istream
* inputstream
) :
138 mystream (false), istr (inputstream
)
139 { parseerror
= "no parsing done yet."; };
140 xmlite_parser (const char * filename
);
142 { if (mystream
) delete (istr
); };
144 xmlite_entity
* parse ();
145 xmlite_entity
* readentity (const string
& startname
);
147 void skipwhitespace ();
148 void readstring (string
& str
, const char * endchar
);
149 void readattribute (xmlite_entity
* ent
);
152 { return (parseerror
); };