Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

cppdom::XMLContext Class Reference

xml parsing context class. More...

#include <cppdom.h>

Collaboration diagram for cppdom::XMLContext:

Collaboration graph
[legend]
List of all members.

Public Methods

 XMLContext ()
 ctor. More...

virtual ~XMLContext ()
 dtor. More...

std::string getEntity (const std::string &entname)
 returns the entity representation for the named entity. More...

std::string getTagname (XMLTagNameHandle handle)
 returns the tagname by the tagname handle. More...

XMLTagNameHandle insertTagname (const std::string &tagname)
 inserts a tag name and returns a tag name handle to the string. More...

XMLLocationgetLocation ()
 returns the current location in the xml stream. More...

virtual void initContext ()
 called once when the context instance starts up; overwrite to customize. More...

event handling methods
void setEventHandler (XMLEventHandlerPtr ehptr)
 sets the event handler; enables handling events. More...

XMLEventHandlergetEventHandler ()
 returns the currently used eventhandler (per reference). More...

bool handleEvents () const
 returns if a valid event handler is set. More...


Protected Attributes

bool mInit
 indicates if init_context() was already called. More...

int mNextHandle
 next available tagname handle. More...

XMLTagNameMap mTagNames
 matches XMLTagNameHandles to the real std::string's. More...

XMLEntityMap mEntities
 Contains entity codes and their string representations. More...

XMLLocation mLocation
 location of the xml input stream. More...

bool mHandleEvents
 indicates if the event handler is used. More...

XMLEventHandlerPtr mEventHandler
 current parsing event handler. More...


Detailed Description

xml parsing context class.

the class is the parsing context for the parsed xml document. the class has a tagname lookup table and an entity map

Definition at line 175 of file cppdom.h.


Constructor & Destructor Documentation

cppdom::XMLContext::XMLContext  
 

ctor.

Definition at line 138 of file cppdom.cpp.

References mHandleEvents, mInit, and mNextHandle.

00139       : mEventHandler(new XMLEventHandler)
00140    {
00141       mInit = false;
00142       mNextHandle = 0;
00143       mHandleEvents = false;
00144    }

cppdom::XMLContext::~XMLContext   [virtual]
 

dtor.

Definition at line 146 of file cppdom.cpp.

00147    {
00148    }


Member Function Documentation

std::string cppdom::XMLContext::getEntity const std::string &    entname
 

returns the entity representation for the named entity.

Definition at line 150 of file cppdom.cpp.

References initContext(), mEntities, and mInit.

00151    {
00152       if (!mInit)
00153       {
00154          initContext();
00155       }
00156 
00157       XMLEntityMap::const_iterator iter = mEntities.find(entName);
00158       return (iter == mEntities.end() ? entName : iter->second);
00159    }

XMLEventHandler & cppdom::XMLContext::getEventHandler  
 

returns the currently used eventhandler (per reference).

Definition at line 218 of file cppdom.cpp.

References cppdom_boost::shared_ptr< class XMLEventHandler >::get(), and mEventHandler.

00219    {
00220       return *mEventHandler.get();
00221    }

XMLLocation & cppdom::XMLContext::getLocation  
 

returns the current location in the xml stream.

Definition at line 202 of file cppdom.cpp.

References mLocation.

00203    {
00204       return mLocation;
00205    }

std::string cppdom::XMLContext::getTagname XMLTagNameHandle    handle
 

returns the tagname by the tagname handle.

Definition at line 161 of file cppdom.cpp.

References initContext(), mInit, mTagNames, and cppdom::XMLTagNameHandle.

00162    {
00163       if (!mInit)
00164       {
00165          initContext();
00166       }
00167       XMLTagNameMap::const_iterator iter = mTagNames.find(handle);
00168 
00169       std::string empty("");
00170       return (iter == mTagNames.end() ? empty : iter->second);
00171    }

bool cppdom::XMLContext::handleEvents   const
 

returns if a valid event handler is set.

Definition at line 223 of file cppdom.cpp.

References mHandleEvents.

00224    {
00225       return mHandleEvents;
00226    }

void cppdom::XMLContext::initContext   [virtual]
 

called once when the context instance starts up; overwrite to customize.

@note: The base member should always be called, to set init to true

Definition at line 207 of file cppdom.cpp.

References mInit.

Referenced by getEntity(), getTagname(), and insertTagname().

00208    {
00209       mInit = true;
00210    }

XMLTagNameHandle cppdom::XMLContext::insertTagname const std::string &    tagname
 

inserts a tag name and returns a tag name handle to the string.

Definition at line 173 of file cppdom.cpp.

References initContext(), mInit, mNextHandle, mTagNames, and cppdom::XMLTagNameHandle.

00174    {
00175       if (!mInit)
00176       {
00177          initContext();
00178       }
00179 
00180       // bugfix: first search, if the tagname is already in the list
00181       // since usually there are not much different tagnames, the search
00182       // shouldn't slow down parsing too much
00183       XMLTagNameMap::const_iterator iter,stop;
00184       iter = mTagNames.begin();
00185       stop = mTagNames.end();
00186 
00187       for(; iter!=stop; ++iter)
00188       {
00189          if (iter->second == tagName)
00190          {
00191             return iter->first;
00192          }
00193       }
00194 
00195       // insert new tagname
00196       XMLTagNameMap::value_type keyvaluepair(mNextHandle, tagName);
00197       mTagNames.insert(keyvaluepair);
00198 
00199       return mNextHandle++;
00200    }

void cppdom::XMLContext::setEventHandler XMLEventHandlerPtr    ehptr
 

sets the event handler; enables handling events.

Definition at line 212 of file cppdom.cpp.

References mEventHandler, and mHandleEvents.

00213    {
00214       mEventHandler = ehptr;
00215       mHandleEvents = true;
00216    }


Member Data Documentation

XMLEntityMap cppdom::XMLContext::mEntities [protected]
 

Contains entity codes and their string representations.

Definition at line 216 of file cppdom.h.

Referenced by getEntity().

XMLEventHandlerPtr cppdom::XMLContext::mEventHandler [protected]
 

current parsing event handler.

Definition at line 219 of file cppdom.h.

Referenced by getEventHandler(), and setEventHandler().

bool cppdom::XMLContext::mHandleEvents [protected]
 

indicates if the event handler is used.

Definition at line 218 of file cppdom.h.

Referenced by handleEvents(), setEventHandler(), and XMLContext().

bool cppdom::XMLContext::mInit [protected]
 

indicates if init_context() was already called.

Definition at line 213 of file cppdom.h.

Referenced by getEntity(), getTagname(), initContext(), insertTagname(), and XMLContext().

XMLLocation cppdom::XMLContext::mLocation [protected]
 

location of the xml input stream.

Definition at line 217 of file cppdom.h.

Referenced by getLocation().

int cppdom::XMLContext::mNextHandle [protected]
 

next available tagname handle.

Definition at line 214 of file cppdom.h.

Referenced by insertTagname(), and XMLContext().

XMLTagNameMap cppdom::XMLContext::mTagNames [protected]
 

matches XMLTagNameHandles to the real std::string's.

Definition at line 215 of file cppdom.h.

Referenced by getTagname(), and insertTagname().


The documentation for this class was generated from the following files:
Generated on Thu Jan 2 21:29:20 2003 for cppdom by doxygen1.2.15