BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Calibration/xmlBase/include/xmlBase/docMan/DocMan.h
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/xmlBase/xmlBase/docMan/DocMan.h,v 1.1.1.1 2005/10/17
2// 06:10:27 maqm Exp $
3#ifndef xmlBase_DocMan_h
4#define xmlBase_DocMan_h
5
6#include "xmlBase/XmlParser.h"
7#include <string>
8#include <vector>
9
10typedef XERCES_CPP_NAMESPACE_QUALIFIER DOMElement DomElement;
11
12namespace xmlBase {
13
14 //! DocClient is a pure virtual class which client should inherit
15 //! from (or it should own some object which does); it will provide
16 //! the handler.
17 class DocClient;
18
19 //! DocMan allows different clients to share a single xml document.
20 /*! Clients may sign up to handle particular child elements (direct
21 children only of the root element). Then when the DocMan object
22 (there is only one: it's a singleton) is asked to parse a file
23 it
24 - invokes Xerces to build the DOM
25 - calls back each registered client for first-generation
26 children of the root element
27 - resets the parser, which releases the memory for the
28 DOM and readies the parser to parse another document
29 DocMan can also be used as a base class for document managers
30 which know something about a particular docType.
31 */
32 class DocMan {
33 public:
34 //! Implements singleton.
35 static DocMan* getPointer();
36
37 //! \b parse not only parses and creates DOM; it also calls back
38 //! registered clients.
39 /*! Return \b false if something goes wrong with the parse */
40 virtual bool parse( const std::string& filename,
41 const std::string& docType = std::string( "" ) );
42
43 virtual bool regClient( const std::string& eltName, DocClient* client );
44
45 protected:
46 DocMan();
47 virtual ~DocMan();
48
49 //! Register privileged client; only available to derived classes
50 bool regMeFirst( DocClient* client );
51
52 //! Nested class to keep track of clients for one element type
53 class ClientList {
54 public:
55 ClientList( const std::string& eltName ) : m_eltName( eltName ) {}
56
58 //! Add a client to list.
59 /*! return indicates success or failure (e.g. duplicate). By
60 default new client is added to back of list, but if \a front
61 is set to \b true client will go to the front. */
62 bool add( DocClient* client, bool front = false );
63
64 //! Remove a client; return indicates success or failure (e.g.,
65 //! client not found)
66 bool remove( DocClient* client );
67
68 //! which list are we?
69 const std::string& getName() { return m_eltName; }
70
71 //! call back each client in turn
72 void invoke( DomElement* elt );
73
74 private:
75 std::string m_eltName;
76 std::vector<DocClient*> m_clients;
77 typedef std::vector<DocClient*>::const_iterator ClientsIt;
78 }; // end nested class ClientList
79
80 ClientList* findList( const std::string& eltName );
81
82 private:
83 static DocMan* m_self;
84 std::vector<ClientList*> m_lists;
85 typedef std::vector<ClientList*>::const_iterator ListsIt;
86 XmlParser* m_parser;
87 DocClient* m_meFirst;
88 }; // end DocMan class
89} // namespace xmlBase
90#endif
XERCES_CPP_NAMESPACE_QUALIFIER DOMElement DomElement
Nested class to keep track of clients for one element type.
void invoke(DomElement *elt)
call back each client in turn
bool add(DocClient *client, bool front=false)
Add a client to list.
Definition DocMan.cxx:87
bool remove(DocClient *client)
Definition DocMan.cxx:104
virtual bool regClient(const std::string &eltName, DocClient *client)
Definition DocMan.cxx:59
virtual ~DocMan()
Definition DocMan.cxx:121
static DocMan * getPointer()
Implements singleton.
Definition DocMan.cxx:23
bool regMeFirst(DocClient *client)
Register privileged client; only available to derived classes.
Definition DocMan.cxx:69
virtual bool parse(const std::string &filename, const std::string &docType=std::string(""))
Definition DocMan.cxx:28
ClientList * findList(const std::string &eltName)
Definition DocMan.cxx:76