ATLAS Offline Software
XMLCoreParser.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef XMLCoreParser_hpp
6 #define XMLCoreParser_hpp
7 
8 #include <string>
9 #include <map>
10 #include <memory>
11 
12 class XMLCoreParser;
13 class XMLCoreParserImpl;
14 
15 namespace CoreParser{
16  class DOMNode;
17 }
18 
20 public:
22  : m_node (node),
23  m_owns (false){
24  }
25 
26  XMLCoreNode (std::unique_ptr<CoreParser::DOMNode> node)
27  : m_node (node.release()),
28  m_owns (true){
29  }
30 
32  : m_node (other.m_node),
33  m_owns (false){
34  }
35 
37  : m_node (other.m_node),
39  other.m_node = nullptr;
40  other.m_owns = false;
41  }
42 
44 
46 
47  ~XMLCoreNode();
48 
49  operator const CoreParser::DOMNode& () const{
50  return (*m_node);
51  }
52 
53  const CoreParser::DOMNode& get_node () const{
54  return (*m_node);
55  }
56 
57 private:
59  bool m_owns{};
60 };
61 
63 public:
64 
65  virtual ~XMLCoreFactory();
66 
67  void start (XMLCoreParser& parser, const XMLCoreNode& node);
68  void end (XMLCoreParser& parser, const XMLCoreNode& node);
69  void comment (XMLCoreParser& parser, const std::string& comment);
70 
71  virtual void do_start (XMLCoreParser& parser, const XMLCoreNode& node);
72  virtual void do_end (XMLCoreParser& parser, const XMLCoreNode& node);
73  virtual void do_comment (XMLCoreParser& parser, const std::string& comment);
74 
75  std::string get_name (const XMLCoreNode& node);
76  int sibling_number (const XMLCoreNode& node);
77 
78  static int attribute_number (const XMLCoreNode& node);
79 
80  static bool has_attribute (const XMLCoreNode& node, const std::string& name);
81  static int get_int (const XMLCoreNode& node, const std::string& name);
82  static double get_double (const XMLCoreNode& node, const std::string& name);
83  static bool get_boolean (const XMLCoreNode& node, const std::string& name);
84  static std::string get_ID (const XMLCoreNode& node, const std::string& name);
85  static std::string get_value (const XMLCoreNode& node, const std::string& name);
86  static std::string get_name (const XMLCoreNode& node, int index);
87  static std::string get_token (const XMLCoreNode& node, const std::string& name);
88 
89  static bool check_int (const int n, const XMLCoreNode& node, const std::string& name);
90  static bool check_double (const int n, const XMLCoreNode& node, const std::string& name);
91 
92 protected:
93 
94  std::string m_xmlelementname;
95 };
96 
97 class XMLCoreParser {
98 public:
99 
100  XMLCoreNode parse (const std::string& file_name);
101  void visit (const std::string& file_name);
102 
103  void register_default_factory (std::unique_ptr<XMLCoreFactory> factory);
104  void register_factory (const std::string& name,
105  std::unique_ptr<XMLCoreFactory> factory);
106  void register_external_entity (const std::string& name, const std::string& file_name);
107  void register_text_entity (const std::string& name, const std::string& text);
108 
109  void up();
110  void down();
111  int level() const;
112 
113 
114 private:
115 
116  void visit (const XMLCoreNode& node);
117  void terminate ();
118  XMLCoreFactory* find_factory (const std::string& name);
119 
120  typedef std::map <std::string, std::unique_ptr<XMLCoreFactory> > FactoryMap;
122  std::unique_ptr<XMLCoreFactory> m_default_factory;
123  int m_level = 0;
124 };
125 
126 #endif
XMLCoreParser::find_factory
XMLCoreFactory * find_factory(const std::string &name)
Definition: XMLCoreParser.cxx:405
XMLCoreParser::parse
XMLCoreNode parse(const std::string &file_name)
Definition: XMLCoreParser.cxx:276
XMLCoreFactory::do_comment
virtual void do_comment(XMLCoreParser &parser, const std::string &comment)
Definition: XMLCoreParser.cxx:104
python.CaloScaleNoiseConfig.parser
parser
Definition: CaloScaleNoiseConfig.py:75
XMLCoreNode::XMLCoreNode
XMLCoreNode(const CoreParser::DOMNode *node)
Definition: XMLCoreParser.h:21
XMLCoreParser::terminate
void terminate()
XMLCoreNode::operator=
XMLCoreNode & operator=(const XMLCoreNode &other)
Definition: XMLCoreParser.cxx:28
index
Definition: index.py:1
XMLCoreFactory::has_attribute
static bool has_attribute(const XMLCoreNode &node, const std::string &name)
Definition: XMLCoreParser.cxx:117
XMLCoreFactory::start
void start(XMLCoreParser &parser, const XMLCoreNode &node)
Definition: XMLCoreParser.cxx:66
CoreParser::DOMNode
Definition: DOMNode.h:21
XMLCoreFactory::get_int
static int get_int(const XMLCoreNode &node, const std::string &name)
Definition: XMLCoreParser.cxx:125
XMLCoreNode::XMLCoreNode
XMLCoreNode(std::unique_ptr< CoreParser::DOMNode > node)
Definition: XMLCoreParser.h:26
XMLCoreFactory::get_boolean
static bool get_boolean(const XMLCoreNode &node, const std::string &name)
Definition: XMLCoreParser.cxx:141
XMLCoreFactory::check_int
static bool check_int(const int n, const XMLCoreNode &node, const std::string &name)
Definition: XMLCoreParser.cxx:211
XMLCoreNode
Definition: XMLCoreParser.h:19
XMLCoreParser::register_text_entity
void register_text_entity(const std::string &name, const std::string &text)
Definition: XMLCoreParser.cxx:395
XMLCoreParser::m_level
int m_level
Definition: XMLCoreParser.h:123
XMLCoreParser::down
void down()
Definition: XMLCoreParser.cxx:421
physics_parameters.file_name
string file_name
Definition: physics_parameters.py:32
XMLCoreParser
Definition: XMLCoreParser.h:97
XMLCoreParser::m_default_factory
std::unique_ptr< XMLCoreFactory > m_default_factory
Definition: XMLCoreParser.h:122
XMLCoreNode::m_owns
bool m_owns
Definition: XMLCoreParser.h:59
beamspotman.n
n
Definition: beamspotman.py:731
XMLCoreFactory::get_value
static std::string get_value(const XMLCoreNode &node, const std::string &name)
Definition: XMLCoreParser.cxx:154
XMLCoreFactory::attribute_number
static int attribute_number(const XMLCoreNode &node)
Definition: XMLCoreParser.cxx:111
XMLCoreFactory::do_start
virtual void do_start(XMLCoreParser &parser, const XMLCoreNode &node)
Definition: XMLCoreParser.cxx:90
XMLCoreParser::register_factory
void register_factory(const std::string &name, std::unique_ptr< XMLCoreFactory > factory)
Definition: XMLCoreParser.cxx:376
XMLCoreFactory::end
void end(XMLCoreParser &parser, const XMLCoreNode &node)
Definition: XMLCoreParser.cxx:74
XMLCoreFactory
Definition: XMLCoreParser.h:62
XMLCoreNode::XMLCoreNode
XMLCoreNode(const XMLCoreNode &other)
Definition: XMLCoreParser.h:31
XMLCoreNode::m_node
const CoreParser::DOMNode * m_node
Definition: XMLCoreParser.h:58
XMLCoreNode::XMLCoreNode
XMLCoreNode(XMLCoreNode &&other)
Definition: XMLCoreParser.h:36
XMLCoreFactory::check_double
static bool check_double(const int n, const XMLCoreNode &node, const std::string &name)
Definition: XMLCoreParser.cxx:243
python.EventInfoMgtInit.release
release
Definition: EventInfoMgtInit.py:24
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
XMLCoreParser::m_factories
FactoryMap m_factories
Definition: XMLCoreParser.h:121
XMLCoreFactory::get_ID
static std::string get_ID(const XMLCoreNode &node, const std::string &name)
Definition: XMLCoreParser.cxx:148
XMLCoreParser::register_default_factory
void register_default_factory(std::unique_ptr< XMLCoreFactory > factory)
Definition: XMLCoreParser.cxx:371
XMLCoreParser::FactoryMap
std::map< std::string, std::unique_ptr< XMLCoreFactory > > FactoryMap
Definition: XMLCoreParser.h:120
XMLCoreFactory::m_xmlelementname
std::string m_xmlelementname
Definition: XMLCoreParser.h:94
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
XMLCoreFactory::~XMLCoreFactory
virtual ~XMLCoreFactory()
Definition: XMLCoreParser.cxx:59
XMLCoreNode::get_node
const CoreParser::DOMNode & get_node() const
Definition: XMLCoreParser.h:53
CoreParser
Definition: DOMNode.h:14
XMLCoreParser::register_external_entity
void register_external_entity(const std::string &name, const std::string &file_name)
Definition: XMLCoreParser.cxx:386
XMLCoreNode::~XMLCoreNode
~XMLCoreNode()
Definition: XMLCoreParser.cxx:48
makeTransCanvas.text
text
Definition: makeTransCanvas.py:11
XMLCoreFactory::get_token
static std::string get_token(const XMLCoreNode &node, const std::string &name)
Definition: XMLCoreParser.cxx:190
XMLCoreFactory::sibling_number
int sibling_number(const XMLCoreNode &node)
Definition: XMLCoreParser.cxx:174
XMLCoreParser::level
int level() const
Definition: XMLCoreParser.cxx:427
XMLCoreFactory::get_name
std::string get_name(const XMLCoreNode &node)
Definition: XMLCoreParser.cxx:169
XMLCoreFactory::comment
void comment(XMLCoreParser &parser, const std::string &comment)
Definition: XMLCoreParser.cxx:82
XMLCoreFactory::get_double
static double get_double(const XMLCoreNode &node, const std::string &name)
Definition: XMLCoreParser.cxx:133
XMLCoreParser::up
void up()
Definition: XMLCoreParser.cxx:415
XMLCoreParser::visit
void visit(const std::string &file_name)
Definition: XMLCoreParser.cxx:289
node
Definition: memory_hooks-stdcmalloc.h:74
XMLCoreFactory::do_end
virtual void do_end(XMLCoreParser &parser, const XMLCoreNode &node)
Definition: XMLCoreParser.cxx:97