Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Public Member Functions | Static Public Member Functions | Private Attributes
desaxe::Digester Class Reference

Digester helps you to create C++ objects from a SAX stream. More...

#include <digester.h>

Inheritance diagram for desaxe::Digester:
Inheritance graph
[legend]
Collaboration diagram for desaxe::Digester:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Digester ()
Digesteroperator= (const Digester &other)
virtual ~Digester ()
void addRule (const Xml_string &pattern, Action action)
void parseFile (const Xml_string &filename)
void parseMemory (const char *data, unsigned int length)
template<class ObjType >
ObjType * result ()
int nrOfErrors () const
const Xml_string getError (int i) const
void beginDoc ()
void endDoc ()
void begin (const Xml_string &tag, Xml_attr attr)
void end (const Xml_string &tag)
void chars (const Xml_string &text)
void fail ()
void error (const Xml_string &msg)
template<class ObjType >
ObjType * top (unsigned int offset=0)
template<class ObjType >
ObjType * bottom (unsigned int offset=0)
template<class ObjType >
void setResult (ObjType *res)
void pop ()
void popn (unsigned int number)
template<class ObjType >
void push (ObjType *obj)
template<class ObjType >
ObjType * lookup (const Xml_string &idref)
template<class ObjType >
void store (const Xml_string &idref, ObjType *res)
template<class LinkType >
void patchCall (const Xml_string &idref, void(*fun)(LinkType *))
template<class ObjType , class LinkType >
void patchInvoke (const Xml_string &idref, ObjType *obj, void(ObjType::*fun)(LinkType *))
void beginEnd (const Xml_string &tag, Xml_attr attr)

Static Public Member Functions

static Xml_string concat (const Xml_string &pattern1, const Xml_string &pattern2)

Private Attributes

RuleStatestate
std::vector< PRIVATE::VarPtrobjects
std::map< Xml_string,
PRIVATE::VarPtr
storage
std::map< Xml_string,
PRIVATE::Patch * > 
patches
PRIVATE::VarPtr result_
std::vector< Xml_stringerrors

Detailed Description

Digester helps you to create C++ objects from a SAX stream.

All you have to do is register actions for patterns of element tags you expect in your XML stream. These actions can create new objects, set attributes, or call methods. Actions operate on intermediate objects which are hold on a stack maintained by Digester.

Definition at line 100 of file digester.h.


Constructor & Destructor Documentation

Definition at line 95 of file digester.cpp.

                   : objects(), storage(), errors() 
{ 
       state = new RuleState();
       result_.ptr = NULL;
       result_.type = "";
}

Definition at line 103 of file digester.cpp.

                    {
       delete state;
       deletePatches(patches);
}

Here is the call graph for this function:


Member Function Documentation

void desaxe::Digester::addRule ( const Xml_string pattern,
Action  action 
)

Definition at line 132 of file digester.cpp.

{
       action.setDigester(this);
       state->addRule(pattern, action);
}

Here is the call graph for this function:

void desaxe::Digester::begin ( const Xml_string tag,
Xml_attr  attr 
) [virtual]

Implements SaxHandler.

Definition at line 151 of file digester.cpp.

{
       state->open(tag);
       const std::vector<rule_t>& rules (state->rulesForCurrentState());
       std::vector<rule_t>::const_iterator it;
       for(it=rules.begin(); it!=rules.end(); ++it)
       {
#ifdef DESAXE_DEBUG
              std::cerr << "B " << it->first << " " << typeid(it->second).name() << "\n";
#endif
              const_cast<Action&>(it->second).begin(tag, attr);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void desaxe::Digester::beginDoc ( ) [virtual]

Implements SaxHandler.

Definition at line 139 of file digester.cpp.

{
       state->reset();
#ifdef DESAXE_DEBUG  
       state->dump();
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SaxHandler::beginEnd ( const Xml_string tag,
Xml_attr  attr 
) [inline, inherited]

Definition at line 32 of file saxhandler.h.

{
       begin(tag, attr);
       end(tag);
}

Here is the call graph for this function:

template<class ObjType >
ObjType * desaxe::Digester::bottom ( unsigned int  offset = 0) [inline]

Definition at line 198 of file digester.h.

{ 
#ifdef DESAXE_DEBUG
       std::cerr << "bottom(" << offset << ") of " << objects.size() << "\n";
#endif
       unsigned int count = objects.size();
       assert (offset < count); 
       PRIVATE::chkcell<ObjType> (objects[offset]);
       return static_cast<ObjType*>(objects[offset].ptr);
}
void desaxe::Digester::chars ( const Xml_string text) [virtual]

Implements SaxHandler.

Definition at line 179 of file digester.cpp.

{
       const std::vector<rule_t>& rules (state->rulesForCurrentState());
       std::vector<rule_t>::const_iterator it;
       for(it=rules.begin(); it!=rules.end(); ++it)
       {
#ifdef DESAXE_DEBUG
              std::cerr << "C " << it->first << " " << typeid(it->second).name() << "\n";
#endif
              const_cast<Action&>(it->second).chars(text);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Xml_string desaxe::Digester::concat ( const Xml_string pattern1,
const Xml_string pattern2 
) [static]

Definition at line 193 of file digester.cpp.

{
       if (pattern1 == "")
              return pattern2;
       else if (pattern2 == "")
              return pattern1;
       else if ( (pattern1[pattern1.length()-1] != '/') && (pattern2[0] != '/') )
              // insert "/" as separator
              return pattern1 + "/" + pattern2;
       else if ( (pattern1[pattern1.length()-1]=='/') || (pattern2[0]=='/') )
              return pattern1 + pattern2;
       else // cut off one "/"
              return pattern1 + std::string(static_cast<const std::string&>(pattern2), 1, std::string::npos);
}
void desaxe::Digester::end ( const Xml_string tag) [virtual]

Implements SaxHandler.

Definition at line 165 of file digester.cpp.

{
       const std::vector<rule_t>& rules (state->rulesForCurrentState());
       std::vector<rule_t>::const_reverse_iterator it;
       for(it=rules.rbegin(); it!=rules.rend(); ++it)
       {
#ifdef DESAXE_DEBUG
              std::cerr << "E " << it->first << " " << typeid(it->second).name() << "\n";
#endif
              const_cast<Action&>(it->second).end(tag);
       }
       state->close();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void desaxe::Digester::endDoc ( ) [virtual]

Implements SaxHandler.

Definition at line 147 of file digester.cpp.

{
}
void desaxe::Digester::error ( const Xml_string msg)

Definition at line 126 of file digester.cpp.

{
       return errors[i];
}
template<class ObjType >
ObjType * desaxe::Digester::lookup ( const Xml_string idref) [inline]

Definition at line 337 of file digester.h.

{ 
       using namespace PRIVATE;

       std::map<Xml_string, VarPtr>::iterator cell = storage.find(idref);
       if (cell == storage.end())
       {
#ifdef DESAXE_DEBUG
              std::cerr << "lookup[" << idref << "]-> NULL\n";
#endif
              return NULL;
       }
       else
       {
              chkcell<ObjType> (cell->second);
#ifdef DESAXE_DEBUG
              std::cerr << "lookup[" << idref << "]-> " << static_cast<ObjType*>(cell->second.ptr) << "\n";
#endif
              return static_cast<ObjType*>(cell->second.ptr);
       }
}

Definition at line 121 of file digester.cpp.

{
       return errors.size();
}
Digester & desaxe::Digester::operator= ( const Digester other)

Definition at line 109 of file digester.cpp.

{
       delete state;
       state = new RuleState(*other.state);
       objects = other.objects;
       storage = other.storage;
       result_ = other.result_;
       errors = other.errors;
       return *this;
}
void desaxe::Digester::parseFile ( const Xml_string filename)

Definition at line 53 of file digester_parse.cpp.

{
       DigesterParser* handler = new DigesterParser(this);
       QFile xmlFile( filename );
       QXmlInputSource source( &xmlFile );
       QXmlSimpleReader reader;
       reader.setContentHandler( handler );
       reader.parse( source );
}
void desaxe::Digester::parseMemory ( const char *  data,
unsigned int  length 
)

Definition at line 63 of file digester_parse.cpp.

{
       DigesterParser* handler = new DigesterParser(this);
       QXmlInputSource source;
       source.setData(QString::fromUtf8(data, length));
       QXmlSimpleReader reader;
       reader.setContentHandler( handler );
       reader.parse( source );
}
template<class LinkType >
void desaxe::Digester::patchCall ( const Xml_string idref,
void(*)(LinkType *)  fun 
)

Definition at line 376 of file digester.h.

{
       using namespace PRIVATE;
       
       std::map<Xml_string, VarPtr>::iterator cell = storage.find(idref);
       if (cell == storage.end())
       {
              patches[idref] = new Patch1<LinkType>(fun, patches[idref] );
       }
       else
       {
              Patch1<LinkType>(fun).run(cell->second);
       }
}
template<class ObjType , class LinkType >
void desaxe::Digester::patchInvoke ( const Xml_string idref,
ObjType *  obj,
void(ObjType::*)(LinkType *)  fun 
)

Definition at line 393 of file digester.h.

{
       using namespace PRIVATE;
       
       std::map<Xml_string, VarPtr>::iterator cell = storage.find(idref);
       if (cell == storage.end())
       {
              patches[idref] = new Patch2<ObjType,LinkType>(obj, fun, patches[idref] );
       }
       else
       {
              Patch2<ObjType,LinkType>(obj, fun).run(cell->second);
       }
}
void desaxe::Digester::pop ( ) [inline]

Definition at line 236 of file digester.h.

{
       unsigned int count = (unsigned int) objects.size();
       assert (1 <= count);
       objects.pop_back();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void desaxe::Digester::popn ( unsigned int  number) [inline]

Definition at line 244 of file digester.h.

{
       unsigned int count = (unsigned int) objects.size();
       assert (number <= count);
       objects.resize(count - number);
}

Here is the call graph for this function:

template<class ObjType >
void desaxe::Digester::push ( ObjType *  obj) [inline]

Definition at line 254 of file digester.h.

{
#ifdef DESAXE_DEBUG
       std::cerr << "stack<- " << obj << "\n";
#endif
       objects.push_back(PRIVATE::mkcell(obj));
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class ObjType >
ObjType * desaxe::Digester::result ( ) [inline]

Definition at line 212 of file digester.h.

{ 
       ObjType* dummy = NULL;
       if (result_.type != typeid(dummy).name())
              return NULL;
#ifdef DESAXE_DEBUG
       std::cerr << "result-> " << static_cast<ObjType*>(result_.ptr) << "\n";
#endif
       return static_cast<ObjType*>(result_.ptr);
}

Here is the caller graph for this function:

template<class ObjType >
void desaxe::Digester::setResult ( ObjType *  res) [inline]

Definition at line 226 of file digester.h.

{ 
#ifdef DESAXE_DEBUG
       std::cerr << res << " ->result\n";
#endif
       result_ = PRIVATE::mkcell(res);
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class ObjType >
void desaxe::Digester::store ( const Xml_string idref,
ObjType *  res 
) [inline]

Definition at line 363 of file digester.h.

{
       using namespace PRIVATE;
#ifdef DESAXE_DEBUG
       std::cerr << "store[" << idref << "] <- " << obj << "\n";
#endif
       storage[idref] = mkcell(obj);
       runPatches(patches[idref], storage[idref]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class ObjType >
ObjType * desaxe::Digester::top ( unsigned int  offset = 0) [inline]

Definition at line 180 of file digester.h.

{
#ifdef DESAXE_DEBUG
       std::cerr << "top(" << offset << ") of " << objects.size() << "\n";
#endif
       unsigned int count = objects.size();
       assert (offset < count); 
       PRIVATE::chkcell<ObjType>(objects[count - offset - 1], &objects);
#ifdef DESAXE_DEBUG
       std::cerr << "stack-> " << static_cast<ObjType*>(objects[count - offset - 1].ptr) << "\n";
#endif
       
       return static_cast<ObjType*>(objects[count - offset - 1].ptr);
}

Here is the caller graph for this function:


Member Data Documentation

std::vector<Xml_string> desaxe::Digester::errors [private]

Definition at line 173 of file digester.h.

Definition at line 161 of file digester.h.

Definition at line 167 of file digester.h.

Definition at line 170 of file digester.h.

Definition at line 158 of file digester.h.

Definition at line 164 of file digester.h.


The documentation for this class was generated from the following files: