DDS  ver. 3.4
IXMLPersist.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 // IXMLPersist is a persistence interface.
4 //
5 #ifndef IXMLPERSIST_H
6 #define IXMLPERSIST_H
7 
8 // MiscCommon
9 #include "XMLHelper.h"
10 
11 namespace MiscCommon
12 {
31 #define DECLARE_XMLPERSIST_IMPL(_T) friend class MiscCommon::IXMLPersistImpl<_T>;
32 
37  template <class _T>
39  {
40  void Read(xercesc::DOMNode* _element)
41  {
42  _T* pThis = reinterpret_cast<_T*>(this);
43  pThis->ReadXmlCfg(_element);
44  }
45  void Write(xercesc::DOMNode* _element)
46  {
47  _T* pThis = reinterpret_cast<_T*>(this);
48  pThis->WriteXmlCfg(_element);
49  }
50  };
58 #define BEGIN_READ_XML_NODE(_T, _ELEMENT_NAME) \
59  void ReadXmlCfg(xercesc::DOMNode* _element) \
60  { \
61  const std::string str("An internal error has been detected. Can't read configuration of " + std::string(#_T) + \
62  " manager, "); \
63  if (!_element) \
64  throw std::invalid_argument(str + "DOMNode is NULL."); \
65  MiscCommon::XMLHelper::smart_XMLCh ElementName(_ELEMENT_NAME); \
66  xercesc::DOMElement* config_element(dynamic_cast<xercesc::DOMElement*>(_element)); \
67  if (!config_element) \
68  throw std::runtime_error(str + "element " + std::string(#_ELEMENT_NAME) + " is missing"); \
69  xercesc::DOMNodeList* list(config_element->getElementsByTagName(ElementName)); \
70  if (!list) \
71  throw std::runtime_error(str + "element " + std::string(#_ELEMENT_NAME) + " is missing"); \
72  xercesc::DOMNode* node(list->item(0)); \
73  if (!node) \
74  throw std::runtime_error(str + "element " + std::string(#_ELEMENT_NAME) + " is missing"); \
75  xercesc::DOMElement* elementConfig(NULL); \
76  if (xercesc::DOMNode::ELEMENT_NODE == node->getNodeType()) \
77  elementConfig = dynamic_cast<xercesc::DOMElement*>(node); \
78  if (!elementConfig) \
79  throw std::runtime_error(str + "empty XML document");
80 
87 #define READ_NODE_ATTR(ELEMENT_NAME, VAR) MiscCommon::XMLHelper::get_attr_value(elementConfig, ELEMENT_NAME, &VAR);
88 
93 #define READ_NODE_VALUE(NODE_NAME, VAR) MiscCommon::XMLHelper::get_node_value(elementConfig, NODE_NAME, &VAR);
94 
100 #define END_READ_XML_NODE }
101 
127 #define BEGIN_READ_XML_CFG(_T) BEGIN_READ_XML_NODE(_T, "config")
128 
135 #define END_READ_XML_CFG }
136 
141 #define BEGIN_WRITE_XML_CFG(_T) \
142  void WriteXmlCfg(xercesc::DOMNode* /*_element*/) \
143  {
144 
149 #define END_WRITE_XML_CFG }
150 }; // namespace MiscCommon
151 
152 #endif
void Write(xercesc::DOMNode *_element)
Definition: IXMLPersist.h:45
#define _T(s)
Use TCHAR instead of char or wchar_t. It will be appropriately translated.
Definition: def.h:85
The IXMLPersistImpl interface is a class of the XML persistance.
Definition: IXMLPersist.h:38
void Read(xercesc::DOMNode *_element)
Definition: IXMLPersist.h:40
Miscellaneous functions and helpers are located here.
Definition: BOOST_FILESYSTEM.h:21