22 #include "desaxe_conf.h"
23 #include "saxhandler.h"
44 template<
class ObjType>
46 VarPtr mkcell(ObjType* obj)
50 result.type =
typeid(obj).name();
55 template<
class ObjType>
57 void chkcell(
const VarPtr& cell, std::vector<VarPtr>* stack = NULL)
59 ObjType* dummy = NULL;
60 if( cell.type !=
typeid(dummy).name() )
62 std::cerr <<
"requested type '" <<
typeid(dummy).name() <<
"' doesnt match cell type '" << cell.type <<
"'\n";
66 std::vector<VarPtr>::iterator it;
67 for (it = stack->begin(); it != stack->end(); ++it)
69 std::cerr << i++ <<
"\t" << (*it).type <<
"\t" << (*it).ptr <<
"\n";
84 virtual void run(
VarPtr lnk) = 0;
106 void addRule(
const Xml_string& pattern,
Action action);
108 void parseFile(
const Xml_string& filename);
109 void parseMemory(
const char* data,
unsigned int length);
111 template<
class ObjType>
113 int nrOfErrors()
const;
114 const Xml_string getError(
int i)
const;
119 void begin(
const Xml_string& tag, Xml_attr attr);
120 void end(
const Xml_string& tag);
121 void chars(
const Xml_string& text);
125 void error(
const Xml_string& msg);
127 template<
class ObjType>
128 ObjType* top(
unsigned int offset = 0);
130 template<
class ObjType>
131 ObjType* bottom(
unsigned int offset = 0);
133 template<
class ObjType>
134 void setResult( ObjType* res );
137 void popn(
unsigned int number);
139 template<
class ObjType>
140 void push(ObjType* obj);
143 template<
class ObjType>
144 ObjType* lookup(
const Xml_string& idref);
145 template<
class ObjType>
146 void store(
const Xml_string& idref, ObjType* res );
149 template<
class LinkType>
150 void patchCall(
const Xml_string& idref,
void (*fun)(LinkType*) );
151 template<
class ObjType,
class LinkType>
152 void patchInvoke(
const Xml_string& idref, ObjType* obj,
void (ObjType::*fun)(LinkType*) );
155 static Xml_string concat(
const Xml_string& pattern1,
const Xml_string& pattern2);
161 std::vector<PRIVATE::VarPtr>
164 std::map<Xml_string, PRIVATE::VarPtr>
167 std::map<Xml_string, PRIVATE::Patch*>
173 std::vector<Xml_string>
179 template<
class ObjType>
181 ObjType* Digester::top(
unsigned int offset)
184 std::cerr <<
"top(" << offset <<
") of " << objects.size() <<
"\n";
186 unsigned int count = objects.size();
187 assert (offset < count);
188 PRIVATE::chkcell<ObjType>(objects[count - offset - 1], &objects);
190 std::cerr <<
"stack-> " <<
static_cast<ObjType*
>(objects[count - offset - 1].ptr) <<
"\n";
193 return static_cast<ObjType*
>(objects[count - offset - 1].ptr);
197 template<
class ObjType>
199 ObjType* Digester::bottom(
unsigned int offset)
202 std::cerr <<
"bottom(" << offset <<
") of " << objects.size() <<
"\n";
205 assert (offset < objects.size());
206 PRIVATE::chkcell<ObjType> (objects[offset]);
207 return static_cast<ObjType*
>(objects[offset].ptr);
211 template<
class ObjType>
213 ObjType* Digester::result()
215 ObjType* dummy = NULL;
216 if (result_.type !=
typeid(dummy).name())
219 std::cerr <<
"result-> " <<
static_cast<ObjType*
>(result_.ptr) <<
"\n";
221 return static_cast<ObjType*
>(result_.ptr);
225 template<
class ObjType>
227 void Digester::setResult(ObjType* res)
230 std::cerr << res <<
" ->result\n";
232 result_ = PRIVATE::mkcell(res);
239 assert (1 <= (
unsigned int) objects.size());
244 void Digester::popn(
unsigned int number)
246 unsigned int count = (
unsigned int) objects.size();
247 assert (number <= count);
248 objects.resize(count - number);
252 template<
class ObjType>
254 void Digester::push(ObjType* obj)
257 std::cerr <<
"stack<- " << obj <<
"\n";
259 objects.push_back(PRIVATE::mkcell(obj));
267 template <
class LinkType>
270 typedef void (*FunType1)(LinkType*);
277 fun( static_cast<LinkType*>(link.ptr) );
282 template <
class ObjType,
class LinkType>
285 typedef void (ObjType::*FunType2)(LinkType*);
289 Patch2(ObjType* ob, FunType2 fn,
Patch* nxt = NULL) :
Patch(nxt), obj(ob), fun(fn) {}
293 (obj->*fun)( static_cast<LinkType*>(link.ptr) );
303 Patch* nxt = list->next;
311 void deletePatches(std::map<Xml_string, Patch*>& patches)
313 std::map<Xml_string, Patch*>::iterator it;
314 for (it = patches.begin(); it != patches.end(); ++it)
316 Patch* list = it->second;
319 Patch* nxt = list->next;
335 template<
class ObjType>
337 ObjType* Digester::lookup(
const Xml_string& idref)
339 using namespace PRIVATE;
341 std::map<Xml_string, VarPtr>::iterator cell = storage.find(idref);
342 if (cell == storage.end())
345 std::cerr <<
"lookup[" << idref <<
"]-> NULL\n";
351 chkcell<ObjType> (cell->second);
353 std::cerr <<
"lookup[" << idref <<
"]-> " <<
static_cast<ObjType*
>(cell->second.ptr) <<
"\n";
355 return static_cast<ObjType*
>(cell->second.ptr);
361 template<
class ObjType>
363 void Digester::store(
const Xml_string& idref, ObjType* obj)
365 using namespace PRIVATE;
367 std::cerr <<
"store[" << idref <<
"] <- " << obj <<
"\n";
369 storage[idref] = mkcell(obj);
370 runPatches(patches[idref], storage[idref]);
375 template<
class LinkType>
376 void Digester::patchCall(
const Xml_string& idref,
void (*fun)(LinkType*) )
378 using namespace PRIVATE;
380 std::map<Xml_string, VarPtr>::iterator cell = storage.find(idref);
381 if (cell == storage.end())
383 patches[idref] =
new Patch1<LinkType>(fun, patches[idref] );
387 Patch1<LinkType>(fun).run(cell->second);
392 template<
class ObjType,
class LinkType>
393 void Digester::patchInvoke(
const Xml_string& idref, ObjType* obj,
void (ObjType::*fun)(LinkType*) )
395 using namespace PRIVATE;
397 std::map<Xml_string, VarPtr>::iterator cell = storage.find(idref);
398 if (cell == storage.end())
400 patches[idref] =
new Patch2<ObjType,LinkType>(obj, fun, patches[idref] );
404 Patch2<ObjType,LinkType>(obj, fun).run(cell->second);
Definition: digester.h:78
Definition: digester.cpp:50
Definition: saxhandler.h:21
Definition: digester.h:36
Definition: digester.h:268
Definition: digester.h:100
Definition: digester.h:283