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