#include <DocMan.h>
Public Member Functions | |
virtual bool | parse (const std::string &filename, const std::string &docType=std::string("")) |
virtual bool | regClient (const std::string &eltName, DocClient *client) |
Static Public Member Functions | |
static DocMan * | getPointer () |
Implements singleton. | |
Protected Member Functions | |
DocMan () | |
virtual | ~DocMan () |
bool | regMeFirst (DocClient *client) |
Register privileged client; only available to derived classes. | |
ClientList * | findList (const std::string &eltName) |
Private Types | |
typedef std::vector< ClientList * >::const_iterator | ListsIt |
Private Attributes | |
std::vector< ClientList * > | m_lists |
XmlParser * | m_parser |
DocClient * | m_meFirst |
Static Private Attributes | |
static DocMan * | m_self = 0 |
Classes | |
class | ClientList |
Nested class to keep track of clients for one element type. More... |
Clients may sign up to handle particular child elements (direct children only of the root element). Then when the DocMan object (there is only one: it's a singleton) is asked to parse a file it
Definition at line 31 of file DocMan.h.
typedef std::vector<ClientList*>::const_iterator xmlBase::DocMan::ListsIt [private] |
xmlBase::DocMan::DocMan | ( | ) | [protected] |
Definition at line 16 of file DocMan.cxx.
References m_meFirst, m_parser, and m_self.
Referenced by getPointer().
00016 { 00017 m_self = this; 00018 m_meFirst = 0; 00019 m_parser = new xmlBase::XmlParser(); 00020 }
xmlBase::DocMan::~DocMan | ( | ) | [protected, virtual] |
DocMan::ClientList * xmlBase::DocMan::findList | ( | const std::string & | eltName | ) | [protected] |
Definition at line 75 of file DocMan.cxx.
References m_lists.
Referenced by parse(), and regClient().
00075 { 00076 unsigned int ix; 00077 00078 for (ix = 0; ix < m_lists.size(); ix++) { 00079 ClientList* cur = m_lists[ix]; 00080 if (eltName.compare(cur->getName()) == 0) return cur; 00081 } 00082 return 0; 00083 }
DocMan * xmlBase::DocMan::getPointer | ( | ) | [static] |
bool xmlBase::DocMan::parse | ( | const std::string & | filename, | |
const std::string & | docType = std::string("") | |||
) | [virtual] |
Return false if something goes wrong with the parse
Definition at line 29 of file DocMan.cxx.
References findList(), xmlBase::Dom::getFirstChildElement(), xmlBase::Dom::getSiblingElement(), xmlBase::Dom::getTagName(), xmlBase::DocClient::handleChild(), xmlBase::DocMan::ClientList::invoke(), m_meFirst, m_parser, xmlBase::XmlParser::parse(), xmlBase::XmlParser::reset(), root, and deljobs::string.
00029 { 00030 // using xercesc::DOMDocument; 00031 // using xercesc::DOMElement; 00032 00033 DOMDocument* doc = m_parser->parse(filename.c_str(), docType); 00034 if (doc == 0) return false; 00035 00036 if (m_meFirst != 0) m_meFirst->handleChild(doc); 00037 00038 DOMElement* root = doc->getDocumentElement(); 00039 00040 DOMElement* child = xmlBase::Dom::getFirstChildElement(root); 00041 00042 while (child != 0) { 00043 std::string eltName = Dom::getTagName(child); 00044 if (m_meFirst != 0) m_meFirst->handleChild(child); 00045 00046 ClientList* list = findList(eltName); 00047 if (list) list->invoke(child); 00048 00049 child = xmlBase::Dom::getSiblingElement(child); 00050 } 00051 00052 // Clean up call for privileged client 00053 if (m_meFirst != 0) m_meFirst->handleChild(0); 00054 00055 m_parser->reset(); 00056 return true; 00057 }
bool xmlBase::DocMan::regClient | ( | const std::string & | eltName, | |
DocClient * | client | |||
) | [virtual] |
Definition at line 59 of file DocMan.cxx.
References xmlBase::DocMan::ClientList::add(), findList(), and m_lists.
00059 { 00060 ClientList* curList = findList(eltName); 00061 if (curList == 0) { 00062 curList = new ClientList(eltName); 00063 m_lists.push_back(curList); 00064 } 00065 return curList->add(client); 00066 }
Register privileged client; only available to derived classes.
Definition at line 68 of file DocMan.cxx.
References m_meFirst.
00068 { 00069 if (m_meFirst != 0) return false; 00070 00071 m_meFirst = client; 00072 return true; 00073 }
std::vector<ClientList*> xmlBase::DocMan::m_lists [private] |
DocClient* xmlBase::DocMan::m_meFirst [private] |
XmlParser* xmlBase::DocMan::m_parser [private] |
XERCES_CPP_NAMESPACE_USE DocMan * xmlBase::DocMan::m_self = 0 [static, private] |