OGS 6.2.0-97-g4a610c866
ConfigTreeUtil.cpp
Go to the documentation of this file.
1 
10 #include "ConfigTreeUtil.h"
11 
12 #include <boost/property_tree/xml_parser.hpp>
13 #include <logog/include/logog.hpp>
14 
15 #include "Error.h"
16 
17 namespace BaseLib
18 {
19 
21  const std::string& filepath,
22  const bool be_ruthless,
23  ConfigTree::PTree&& ptree)
24  : _ptree(std::move(ptree))
25  , _ctree(_ptree, filepath,
26  ConfigTree::onerror,
27  be_ruthless ? ConfigTree::onerror : ConfigTree::onwarning)
28 {
29 }
30 
31 ConfigTree const&
33 {
34  return _ctree;
35 }
36 
37 ConfigTree const*
39 {
40  return &_ctree;
41 }
42 
43 void
45 {
47 }
48 
50 makeConfigTree(const std::string& filepath, const bool be_ruthless,
51  const std::string& toplevel_tag)
52 {
53  ConfigTree::PTree ptree;
54 
55  // note: Trimming whitespace and ignoring comments is crucial in order
56  // for our configuration tree implementation to work!
57  try
58  {
59  read_xml(filepath, ptree,
60  boost::property_tree::xml_parser::no_comments |
61  boost::property_tree::xml_parser::trim_whitespace);
62  }
63  catch (boost::property_tree::xml_parser_error const& e)
64  {
65  OGS_FATAL("Error while parsing XML file `%s' at line %lu: %s.",
66  e.filename().c_str(), e.line(), e.message().c_str());
67  }
68 
69  DBUG("Project configuration from file '%s' read.", filepath.c_str());
70 
71  if (auto child = ptree.get_child_optional(toplevel_tag)) {
72  return ConfigTreeTopLevel(filepath, be_ruthless, std::move(*child));
73  }
74  OGS_FATAL("Tag <%s> has not been found in file `%s'.", toplevel_tag.c_str(),
75  filepath.c_str());
76 }
77 
78 } // namespace BaseLib
ConfigTree _ctree
ConfigTree depending on _ptree.
ConfigTree const & operator*() const
ConfigTreeTopLevel makeConfigTree(const std::string &filepath, const bool be_ruthless, const std::string &toplevel_tag)
ConfigTree const * operator->() const
boost::property_tree::ptree PTree
The tree being wrapped by this class.
Definition: ConfigTree.h:219
ConfigTreeTopLevel(std::string const &filepath, bool const be_ruthless, ConfigTree::PTree &&ptree)
void checkAndInvalidate(ConfigTree &conf)
Definition: ConfigTree.cpp:449
Build information.
#define OGS_FATAL(fmt,...)
Definition: Error.h:63