BOSS 8.0.0
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)
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.
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)
 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 32 of file Calibration/xmlBase/include/xmlBase/docMan/DocMan.h.

Constructor & Destructor Documentation

◆ DocMan() [1/3]

xmlBase::DocMan::DocMan ( )
protected

Definition at line 17 of file DocMan.cxx.

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

Referenced by findList(), and getPointer().

◆ ~DocMan() [1/3]

xmlBase::DocMan::~DocMan ( )
protectedvirtual

Definition at line 121 of file DocMan.cxx.

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

◆ DocMan() [2/3]

xmlBase::DocMan::DocMan ( )
protected

◆ ~DocMan() [2/3]

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

◆ DocMan() [3/3]

xmlBase::DocMan::DocMan ( )
protected

◆ ~DocMan() [3/3]

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

Member Function Documentation

◆ findList() [1/3]

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

Definition at line 76 of file DocMan.cxx.

76 {
77 unsigned int ix;
78
79 for ( ix = 0; ix < m_lists.size(); ix++ )
80 {
81 ClientList* cur = m_lists[ix];
82 if ( eltName.compare( cur->getName() ) == 0 ) return cur;
83 }
84 return 0;
85 }
Nested class to keep track of clients for one element type.
#define ix(i)

Referenced by parse(), and regClient().

◆ findList() [2/3]

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

◆ findList() [3/3]

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

◆ getPointer() [1/3]

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

Implements singleton.

Definition at line 23 of file DocMan.cxx.

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

◆ getPointer() [2/3]

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

Implements singleton.

◆ getPointer() [3/3]

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

Implements singleton.

◆ parse() [1/3]

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 28 of file DocMan.cxx.

28 {
29 // using xercesc::DOMDocument;
30 // using xercesc::DOMElement;
31
32 DOMDocument* doc = m_parser->parse( filename.c_str(), docType );
33 if ( doc == 0 ) return false;
34
35 if ( m_meFirst != 0 ) m_meFirst->handleChild( doc );
36
37 DOMElement* root = doc->getDocumentElement();
38
39 DOMElement* child = xmlBase::Dom::getFirstChildElement( root );
40
41 while ( child != 0 )
42 {
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
49 child = xmlBase::Dom::getSiblingElement( child );
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
ClientList * findList(const std::string &eltName)
Definition DocMan.cxx:76
static std::string getTagName(const DOMElement *node)
Definition Dom.cxx:134
static DOMElement * getSiblingElement(const DOMNode *child)
Return next element sibling, if any.
Definition Dom.cxx:90
static DOMElement * getFirstChildElement(const DOMNode *parent)
Get first child which is an element node, if any.
Definition Dom.cxx:109

Referenced by parse().

◆ parse() [2/3]

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

◆ parse() [3/3]

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/3]

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 {
63 curList = new ClientList( eltName );
64 m_lists.push_back( curList );
65 }
66 return curList->add( client );
67 }

◆ regClient() [2/3]

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

◆ regClient() [3/3]

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

◆ regMeFirst() [1/3]

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

Register privileged client; only available to derived classes.

Definition at line 69 of file DocMan.cxx.

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

◆ regMeFirst() [2/3]

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

Register privileged client; only available to derived classes.

◆ regMeFirst() [3/3]

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: