BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
xmlBase::DocMan Class Reference

DocMan allows different clients to share a single xml document. More...

#include <DocMan.h>

Classes

class  ClientList
 Nested class to keep track of clients for one element type. More...
 

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)
 
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 DocMangetPointer ()
 Implements singleton.
 
static DocMangetPointer ()
 Implements singleton.
 

Protected Member Functions

 DocMan ()
 
virtual ~DocMan ()
 
bool regMeFirst (DocClient *client)
 Register privileged client; only available to derived classes.
 
ClientListfindList (const std::string &eltName)
 
 DocMan ()
 
virtual ~DocMan ()
 
bool regMeFirst (DocClient *client)
 Register privileged client; only available to derived classes.
 
ClientListfindList (const std::string &eltName)
 

Detailed Description

DocMan allows different clients to share a single xml document.

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

  • invokes Xerces to build the DOM
  • calls back each registered client for first-generation children of the root element
  • resets the parser, which releases the memory for the DOM and readies the parser to parse another document DocMan can also be used as a base class for document managers which know something about a particular docType.

Definition at line 31 of file Calibration/xmlBase/xmlBase-00-00-03/xmlBase/docMan/DocMan.h.

Constructor & Destructor Documentation

◆ DocMan() [1/2]

xmlBase::DocMan::DocMan ( )
protected

Definition at line 16 of file DocMan.cxx.

16 {
17 m_self = this;
18 m_meFirst = 0;
19 m_parser = new xmlBase::XmlParser();
20 }

Referenced by getPointer().

◆ ~DocMan() [1/2]

xmlBase::DocMan::~DocMan ( )
protectedvirtual

Definition at line 119 of file DocMan.cxx.

119 {
120 ListsIt it = m_lists.begin();
121 while (it != m_lists.end()) {
122 delete (*it);
123 ++it;
124 }
125 delete m_parser;
126 }

◆ DocMan() [2/2]

xmlBase::DocMan::DocMan ( )
protected

◆ ~DocMan() [2/2]

virtual xmlBase::DocMan::~DocMan ( )
protectedvirtual

Member Function Documentation

◆ findList() [1/2]

DocMan::ClientList * xmlBase::DocMan::findList ( const std::string &  eltName)
protected

Definition at line 75 of file DocMan.cxx.

75 {
76 unsigned int ix;
77
78 for (ix = 0; ix < m_lists.size(); ix++) {
79 ClientList* cur = m_lists[ix];
80 if (eltName.compare(cur->getName()) == 0) return cur;
81 }
82 return 0;
83 }
#define ix(i)
Definition: minoreval.cpp:387

Referenced by parse(), and regClient().

◆ findList() [2/2]

ClientList * xmlBase::DocMan::findList ( const std::string &  eltName)
protected

◆ getPointer() [1/2]

DocMan * xmlBase::DocMan::getPointer ( )
static

Implements singleton.

Definition at line 22 of file DocMan.cxx.

22 {
23 if (m_self == 0) {
24 m_self = new DocMan();
25 }
26 return m_self;
27 }

◆ getPointer() [2/2]

static DocMan * xmlBase::DocMan::getPointer ( )
static

Implements singleton.

◆ parse() [1/2]

bool xmlBase::DocMan::parse ( const std::string &  filename,
const std::string &  docType = std::string("") 
)
virtual

parse not only parses and creates DOM; it also calls back registered clients.

Return false if something goes wrong with the parse

Definition at line 29 of file DocMan.cxx.

29 {
30 // using xercesc::DOMDocument;
31 // using xercesc::DOMElement;
32
33 DOMDocument* doc = m_parser->parse(filename.c_str(), docType);
34 if (doc == 0) return false;
35
36 if (m_meFirst != 0) m_meFirst->handleChild(doc);
37
38 DOMElement* root = doc->getDocumentElement();
39
40 DOMElement* child = xmlBase::Dom::getFirstChildElement(root);
41
42 while (child != 0) {
43 std::string eltName = Dom::getTagName(child);
44 if (m_meFirst != 0) m_meFirst->handleChild(child);
45
46 ClientList* list = findList(eltName);
47 if (list) list->invoke(child);
48
50 }
51
52 // Clean up call for privileged client
53 if (m_meFirst != 0) m_meFirst->handleChild(0);
54
55 m_parser->reset();
56 return true;
57 }
std::string root
Definition: CalibModel.cxx:39
virtual void handleChild(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node)=0
Must be overridden by derived classes.
ClientList * findList(const std::string &eltName)
Definition: DocMan.cxx:75
static std::string getTagName(const DOMElement *node)
Definition: Dom.cxx:142
static DOMElement * getSiblingElement(const DOMNode *child)
Return next element sibling, if any.
Definition: Dom.cxx:96
static DOMElement * getFirstChildElement(const DOMNode *parent)
Get first child which is an element node, if any.
Definition: Dom.cxx:115
DOMDocument * parse(const char *const filename, const std::string &docType=std::string(""))
Parse an xml file, returning document node if successful.
Definition: XmlParser.cxx:108

◆ parse() [2/2]

virtual bool xmlBase::DocMan::parse ( const std::string &  filename,
const std::string &  docType = std::string("") 
)
virtual

parse not only parses and creates DOM; it also calls back registered clients.

Return false if something goes wrong with the parse

◆ regClient() [1/2]

bool xmlBase::DocMan::regClient ( const std::string &  eltName,
DocClient client 
)
virtual

Definition at line 59 of file DocMan.cxx.

59 {
60 ClientList* curList = findList(eltName);
61 if (curList == 0) {
62 curList = new ClientList(eltName);
63 m_lists.push_back(curList);
64 }
65 return curList->add(client);
66 }

◆ regClient() [2/2]

virtual bool xmlBase::DocMan::regClient ( const std::string &  eltName,
DocClient client 
)
virtual

◆ regMeFirst() [1/2]

bool xmlBase::DocMan::regMeFirst ( DocClient client)
protected

Register privileged client; only available to derived classes.

Definition at line 68 of file DocMan.cxx.

68 {
69 if (m_meFirst != 0) return false;
70
71 m_meFirst = client;
72 return true;
73 }

◆ regMeFirst() [2/2]

bool xmlBase::DocMan::regMeFirst ( DocClient client)
protected

Register privileged client; only available to derived classes.


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