OGS  v6.3.3
BaseLib::ConfigTree Class Referencefinal

Detailed Description

Wrapper around a Boost Property Tree with some basic error reporting features.

Features. This class:

  • makes sure that every configuration setting in a Property Tree is read exactly once. If some settings is not read (e.g. due to a typo), a warning message is generated. The message contains a hint where it occured.
  • enforces a naming scheme of settings: letters a-z, numbers 0-9, underscore
  • provides some functionality to read lists of values using range-based for loops.
  • has rather long method names that are easily greppable from the source code. So a list of supported configuration options can be easily obtained from the source code.

The purpose of this class is to reduce or completely avoid the amount of error-handling code in routines that take configuration parameters.

Most methods of this class check that they have not been called before for the same ConfigTree and the same parameter. This behaviour helps to enforce that every parameter is read exactly once during parsing of the configuration settings.

The most notable restriction of this class when compared to plain tree traversal is, that one must know all the XML tags (i.e. configuration parameters) at compile time. It is not possible to read from this class, which configuration parameters are present in the tree. This restriction, however, is intended, because it provides the possibility to get all existing configuration parameters from the source code.

This class maintains a read counter for each parameter accessed through any of its methods. Read counters are increased with every read (the only exception being the peekConfigParameter() method). The destructor finally decreases the read counter for every tag/attribute it find on the current level of the XML tree. If the increases/decreases don't cancel each other, warning messages are generated. This check can also be enforced before destruction by using the BaseLib::checkAndInvalidate() functions.

The design of this class entails some limitations compared to traversing a plain tree, e.g., it is not possible to obtain a list of tags or attributes from the tree, but one has to explicitly query the specific tags/attributes one is interested in. That way it is possible to get all used configuration parameters directly from the source code where this class is used, and to maintain the quality of the configuration parameter documentation.

Instances of this class only keep a reference to the underlying boost::property_tree. Therefore it is necessary that the underlying property tree stays intact as long as any instance—i.e. the top level ConfigTree and any of its children—reference it. In order to simplify the handling of this dependence, the class ConfigTreeTopLevel can be used.

The construction of a ConfigTree from the content of an XML file can be done with the function BaseLib::makeConfigTree(), which performs many error checks. For limitations of the used XML parser, please have a look at that function's documentation.

Definition at line 95 of file ConfigTree.h.

#include <ConfigTree.h>

Classes

struct  CountType
 
class  ParameterIterator
 
class  SubtreeIterator
 
class  ValueIterator
 

Public Types

using PTree = boost::property_tree::ptree
 The tree being wrapped by this class. More...
 
using Callback = std::function< void(const std::string &filename, const std::string &path, const std::string &message)>
 

Public Member Functions

 ConfigTree (PTree const &tree, std::string filename, Callback error_cb, Callback warning_cb)
 
 ConfigTree (PTree &&, std::string const &, Callback const &, Callback const &)=delete
 
 ConfigTree (ConfigTree const &)=delete
 copying is not compatible with the semantics of this class More...
 
 ConfigTree (ConfigTree &&other)
 
ConfigTreeoperator= (ConfigTree const &)=delete
 copying is not compatible with the semantics of this class More...
 
ConfigTreeoperator= (ConfigTree &&other)
 
std::string const & getProjectFileName () const
 Used to get the project file name. More...
 
 ~ConfigTree ()
 
Methods for directly accessing parameter values
template<typename T >
getConfigParameter (std::string const &param) const
 
template<typename T >
getConfigParameter (std::string const &param, T const &default_value) const
 
template<typename T >
boost::optional< T > getConfigParameterOptional (std::string const &param) const
 
template<typename T >
Range< ValueIterator< T > > getConfigParameterList (std::string const &param) const
 
Methods for accessing parameters that have attributes

The getConfigParameter...() methods in this group—note: they do not have template parameters—check that the queried parameters do not have any children (apart from XML attributes); if they do, error() is called.

The support for parameters with attributes is limited in the sense that it is not possible to peek/check them. However, such functionality can easily be added on demand.

ConfigTree getConfigParameter (std::string const &root) const
 
boost::optional< ConfigTreegetConfigParameterOptional (std::string const &root) const
 
Range< ParameterIteratorgetConfigParameterList (std::string const &param) const
 
template<typename T >
getValue () const
 
template<typename T >
getConfigAttribute (std::string const &attr) const
 
template<typename T >
getConfigAttribute (std::string const &attr, T const &default_value) const
 
template<typename T >
boost::optional< T > getConfigAttributeOptional (std::string const &attr) const
 
Methods for peeking and checking parameters

To be used in builder/factory functions: E.g., one can peek a parameter denoting the type of an object to generate in the builder, and check the type parameter in the constructor of the generated object.

template<typename T >
peekConfigParameter (std::string const &param) const
 
template<typename T >
void checkConfigParameter (std::string const &param, T const &value) const
 
template<typename Ch >
void checkConfigParameter (std::string const &param, Ch const *value) const
 Make checkConfigParameter() work for string literals. More...
 
Methods for accessing subtrees
ConfigTree getConfigSubtree (std::string const &root) const
 
boost::optional< ConfigTreegetConfigSubtreeOptional (std::string const &root) const
 
Range< SubtreeIteratorgetConfigSubtreeList (std::string const &root) const
 
Methods for ignoring parameters
void ignoreConfigParameter (std::string const &param) const
 
void ignoreConfigParameterAll (std::string const &param) const
 
void ignoreConfigAttribute (std::string const &attr) const
 

Static Public Member Functions

static void onerror (std::string const &filename, std::string const &path, std::string const &message)
 
static void onwarning (std::string const &filename, std::string const &path, std::string const &message)
 
static void assertNoSwallowedErrors ()
 Asserts that there have not been any errors reported in the destructor. More...
 

Private Types

enum class  Attr : bool { TAG = false , ATTR = true }
 Used to indicate if dealing with XML tags or XML attributes. More...
 
using KeyType = std::pair< Attr, std::string >
 A pair (is attribute, tag/attribute name). More...
 

Private Member Functions

template<typename T >
boost::optional< T > getConfigParameterOptionalImpl (std::string const &param, T *) const
 Default implementation of reading a value of type T. More...
 
template<typename T >
boost::optional< std::vector< T > > getConfigParameterOptionalImpl (std::string const &param, std::vector< T > *) const
 Implementation of reading a vector of values of type T. More...
 
 ConfigTree (PTree const &tree, ConfigTree const &parent, std::string const &root)
 Used for wrapping a subtree. More...
 
void error (std::string const &message) const
 
void warning (std::string const &message) const
 
void checkKeyname (std::string const &key) const
 Checks if key complies with the rules [a-z0-9_]. More...
 
std::string joinPaths (std::string const &p1, std::string const &p2) const
 Used to generate the path of a subtree. More...
 
void checkUnique (std::string const &key) const
 Asserts that the key has not been read yet. More...
 
void checkUniqueAttr (std::string const &attr) const
 Asserts that the attribute attr has not been read yet. More...
 
template<typename T >
CountTypemarkVisited (std::string const &key, Attr const is_attr, bool peek_only) const
 
CountTypemarkVisited (std::string const &key, Attr const is_attr, bool const peek_only) const
 
void markVisitedDecrement (Attr const is_attr, std::string const &key) const
 
bool hasChildren () const
 Checks if this tree has any children. More...
 
void checkAndInvalidate ()
 

Static Private Member Functions

static std::string shortString (std::string const &s)
 returns a short string at suitable for error/warning messages More...
 

Private Attributes

boost::property_tree::ptree const * _tree
 The wrapped tree. More...
 
std::string _path
 A path printed in error/warning messages. More...
 
std::string _filename
 The path of the file from which this tree has been read. More...
 
std::map< KeyType, CountType_visited_params
 
bool _have_read_data = false
 Indicates if the plain data contained in this tree has already been read. More...
 
Callback _onerror
 Custom error callback. More...
 
Callback _onwarning
 Custom warning callback. More...
 

Static Private Attributes

static const char pathseparator = '/'
 Character separating two path components. More...
 
static const std::string key_chars_start = "abcdefghijklmnopqrstuvwxyz"
 Set of allowed characters as the first letter of a key name. More...
 
static const std::string key_chars = key_chars_start + "_0123456789"
 Set of allowed characters in a key name. More...
 

Friends

void checkAndInvalidate (ConfigTree *const conf)
 
void checkAndInvalidate (ConfigTree &conf)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void checkAndInvalidate (std::unique_ptr< ConfigTree > const &conf)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 

Member Typedef Documentation

◆ Callback

using BaseLib::ConfigTree::Callback = std::function<void(const std::string& filename, const std::string& path, const std::string& message)>

Type of the function objects used as callbacks.

Arguments of the callback:

  • filename the file being from which this ConfigTree has been read.
  • path the path in the tree where the message was generated.
  • message the message to be printed.

Definition at line 229 of file ConfigTree.h.

◆ KeyType

using BaseLib::ConfigTree::KeyType = std::pair<Attr, std::string>
private

A pair (is attribute, tag/attribute name).

Definition at line 614 of file ConfigTree.h.

◆ PTree

using BaseLib::ConfigTree::PTree = boost::property_tree::ptree

The tree being wrapped by this class.

Definition at line 220 of file ConfigTree.h.

Member Enumeration Documentation

◆ Attr

enum BaseLib::ConfigTree::Attr : bool
strongprivate

Used to indicate if dealing with XML tags or XML attributes.

Enumerator
TAG 
ATTR 

Definition at line 538 of file ConfigTree.h.

539  {
540  TAG = false, ATTR = true
541  };

Constructor & Destructor Documentation

◆ ConfigTree() [1/5]

BaseLib::ConfigTree::ConfigTree ( PTree const &  tree,
std::string  filename,
Callback  error_cb,
Callback  warning_cb 
)
explicit

Creates a new instance wrapping the given Boost Property Tree.

Parameters
treethe Boost Property Tree to be wrapped
filenamethe file from which the tree has been read
error_cbcallback function to be called on error.
warning_cbcallback function to be called on warning.

The callback functions must be valid callable functions, i.e. not nullptr's. They are configurable in order to make unit tests of this class easier. They should not be provided in production code!

Defaults are strict: By default, both callbacks are set to the same function, i.e., warnings will also result in program abortion!

Definition at line 35 of file ConfigTree.cpp.

39  : _tree(&tree),
40  _filename(std::move(filename)),
41  _onerror(std::move(error_cb)),
42  _onwarning(std::move(warning_cb))
43 {
44  if (!_onerror) {
45  OGS_FATAL("ConfigTree: No valid error handler provided.");
46  }
47  if (!_onwarning) {
48  OGS_FATAL("ConfigTree: No valid warning handler provided.");
49  }
50 }
#define OGS_FATAL(...)
Definition: Error.h:25
Callback _onwarning
Custom warning callback.
Definition: ConfigTree.h:629
boost::property_tree::ptree const * _tree
The wrapped tree.
Definition: ConfigTree.h:605
Callback _onerror
Custom error callback.
Definition: ConfigTree.h:628
std::string _filename
The path of the file from which this tree has been read.
Definition: ConfigTree.h:611

References _onerror, _onwarning, and OGS_FATAL.

Referenced by getConfigSubtreeOptional(), BaseLib::ConfigTree::SubtreeIterator::operator*(), and BaseLib::ConfigTree::ValueIterator< ValueType >::operator*().

◆ ConfigTree() [2/5]

BaseLib::ConfigTree::ConfigTree ( PTree &&  ,
std::string const &  ,
Callback const &  ,
Callback const &   
)
explicitdelete

This constructor is deleted in order to prevent the user from passing temporary instances of PTree. Doing so would lead to a dangling reference _tree and to program crash.

◆ ConfigTree() [3/5]

BaseLib::ConfigTree::ConfigTree ( ConfigTree const &  )
delete

copying is not compatible with the semantics of this class

◆ ConfigTree() [4/5]

BaseLib::ConfigTree::ConfigTree ( ConfigTree &&  other)

After being moved from, other is in an undefined state and must not be used anymore!

Definition at line 62 of file ConfigTree.cpp.

64  : _tree (other._tree)
65  , _path (std::move(other._path))
66  , _filename (std::move(other._filename))
67  , _visited_params(std::move(other._visited_params))
68  , _have_read_data (other._have_read_data)
69  , _onerror (std::move(other._onerror))
70  , _onwarning (std::move(other._onwarning))
71 {
72  other._tree = nullptr;
73 }
std::map< KeyType, CountType > _visited_params
Definition: ConfigTree.h:623
std::string _path
A path printed in error/warning messages.
Definition: ConfigTree.h:608
bool _have_read_data
Indicates if the plain data contained in this tree has already been read.
Definition: ConfigTree.h:626

◆ ~ConfigTree()

BaseLib::ConfigTree::~ConfigTree ( )

The destructor performs the check if all nodes at the current level of the tree have been read. Errors raised by the check are swallowed. Use assertNoSwallowedErrors() manually to check for those.

Definition at line 75 of file ConfigTree.cpp.

76 {
77  if (std::uncaught_exceptions() > 0)
78  {
79  /* If the stack unwinds the check below shall be suppressed in order to
80  * not accumulate false-positive configuration errors.
81  */
82  return;
83  }
84 
85  try {
87  } catch (std::exception& e) {
88  ERR("{:s}", e.what());
89  configtree_destructor_error_messages.push_front(e.what());
90  }
91 }
static std::forward_list< std::string > configtree_destructor_error_messages
Definition: ConfigTree.cpp:26
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42

References checkAndInvalidate(), configtree_destructor_error_messages, and ERR().

◆ ConfigTree() [5/5]

BaseLib::ConfigTree::ConfigTree ( PTree const &  tree,
ConfigTree const &  parent,
std::string const &  root 
)
explicitprivate

Used for wrapping a subtree.

Definition at line 52 of file ConfigTree.cpp.

55  : _tree(&tree), _path(joinPaths(parent._path, root)),
56  _filename(parent._filename),
57  _onerror(parent._onerror), _onwarning(parent._onwarning)
58 {
59  checkKeyname(root);
60 }
std::string joinPaths(std::string const &p1, std::string const &p2) const
Used to generate the path of a subtree.
Definition: ConfigTree.cpp:294
void checkKeyname(std::string const &key) const
Checks if key complies with the rules [a-z0-9_].
Definition: ConfigTree.cpp:276

References checkKeyname().

Member Function Documentation

◆ assertNoSwallowedErrors()

void BaseLib::ConfigTree::assertNoSwallowedErrors ( )
static

Asserts that there have not been any errors reported in the destructor.

Definition at line 246 of file ConfigTree.cpp.

247 {
249  {
250  return;
251  }
252 
253  ERR("ConfigTree: There have been errors when parsing the configuration "
254  "file(s):");
255 
256  for (auto const& msg : configtree_destructor_error_messages) {
257  ERR("{:s}", msg);
258  }
259 
260  OGS_FATAL("There have been errors when parsing the configuration file(s).");
261 }

References configtree_destructor_error_messages, ERR(), and OGS_FATAL.

Referenced by main().

◆ checkAndInvalidate()

void BaseLib::ConfigTree::checkAndInvalidate ( )
private

Checks if the top level of this tree has been read entirely (and not too often).

Postcondition
This method also invalidates the instance, i.e., afterwards it must not be used anymore!

Definition at line 387 of file ConfigTree.cpp.

388 {
389  if (!_tree)
390  {
391  return;
392  }
393 
394  // Note: due to a limitation in boost::property_tree it is not possible
395  // to discriminate between <tag></tag> and <tag/> in the input file.
396  // In both cases data() will be empty.
397  if ((!_have_read_data) && !_tree->data().empty()) {
398  warning("The immediate data `" + shortString(_tree->data())
399  +"' of this tag has not been read.");
400  }
401 
402  // iterate over children
403  for (auto const& p : *_tree) {
404  if (p.first != "<xmlattr>")
405  { // attributes are handled below
407  }
408  }
409 
410  // iterate over attributes
411  if (auto attrs = _tree->get_child_optional("<xmlattr>")) {
412  for (auto const& p : *attrs) {
414  }
415  }
416 
417  for (auto const& p : _visited_params)
418  {
419  auto const& tag = p.first.second;
420  auto const& count = p.second.count;
421 
422  switch (p.first.first) {
423  case Attr::ATTR:
424  if (count > 0) {
425  warning("XML attribute '" + tag + "' has been read " +
426  std::to_string(count) +
427  " time(s) more than it was present in the "
428  "configuration tree.");
429  } else if (count < 0) {
430  warning("XML attribute '" + tag + "' has been read " +
431  std::to_string(-count) +
432  " time(s) less than it was present in the "
433  "configuration tree.");
434  }
435  break;
436  case Attr::TAG:
437  if (count > 0) {
438  warning("Key <" + tag + "> has been read " + std::to_string(count)
439  + " time(s) more than it was present in the configuration tree.");
440  } else if (count < 0) {
441  warning("Key <" + tag + "> has been read " + std::to_string(-count)
442  + " time(s) less than it was present in the configuration tree.");
443  }
444  }
445  }
446 
447  // The following invalidates this instance, s.t. it can not be read from it anymore,
448  // but it also prevents double-checking.
449  _tree = nullptr;
450 }
void markVisitedDecrement(Attr const is_attr, std::string const &key) const
Definition: ConfigTree.cpp:357
static std::string shortString(std::string const &s)
returns a short string at suitable for error/warning messages
Definition: ConfigTree.cpp:263
void warning(std::string const &message) const
Definition: ConfigTree.cpp:226

References _have_read_data, _tree, _visited_params, ATTR, markVisitedDecrement(), shortString(), TAG, and warning().

Referenced by operator=(), and ~ConfigTree().

◆ checkConfigParameter() [1/2]

template<typename Ch >
void BaseLib::ConfigTree::checkConfigParameter ( std::string const &  param,
Ch const *  value 
) const

Make checkConfigParameter() work for string literals.

Definition at line 166 of file ConfigTree-impl.h.

168 {
169  if (getConfigParameter<std::string>(param) != value) {
170  error("The value of key <" + param + "> is not the expected one.");
171  }
172 }
void error(std::string const &message) const
Definition: ConfigTree.cpp:218

References error().

◆ checkConfigParameter() [2/2]

template<typename T >
void BaseLib::ConfigTree::checkConfigParameter ( std::string const &  param,
T const &  value 
) const

Assert that param has the given value.

Convenience method combining getConfigParameter(std::string const&) with a check.

Definition at line 156 of file ConfigTree-impl.h.

158 {
159  if (getConfigParameter<T>(param) != value) {
160  error("The value of key <" + param + "> is not the expected one.");
161  }
162 }

References error().

Referenced by MaterialPropertyLib::createAverageMolarMass(), MaterialPropertyLib::createBishopsPowerLaw(), MaterialPropertyLib::createBishopsSaturationCutoff(), MaterialLib::PorousMedium::createBrooksCorey(), MaterialLib::PorousMedium::createCapillaryPressureModel(), MaterialPropertyLib::createCapillaryPressureRegularizedVanGenuchten(), MaterialPropertyLib::createCapillaryPressureVanGenuchten(), ProcessLib::createCentralDifferencesJacobianAssembler(), MaterialLib::Fracture::CohesiveZoneModeI::createCohesiveZoneModeI(), ProcessLib::createCompareJacobiansJacobianAssembler(), ProcessLib::ComponentTransport::createComponentTransportProcess(), MaterialPropertyLib::createConstant(), ParameterLib::createConstantParameter(), MaterialLib::Fracture::Permeability::createConstantPermeability(), ProcessLib::createConstraintDirichletBoundaryCondition(), NumLib::createConvergenceCriterionDeltaX(), NumLib::createConvergenceCriterionPerComponentDeltaX(), NumLib::createConvergenceCriterionPerComponentResidual(), NumLib::createConvergenceCriterionResidual(), MaterialLib::Fracture::createCoulomb(), MaterialLib::Solids::Creep::createCreepBGRa(), MaterialLib::Fracture::Permeability::createCubicLaw(), MaterialPropertyLib::createCurve(), ParameterLib::createCurveScaledParameter(), ProcessLib::createDirichletBoundaryCondition(), ProcessLib::createDirichletBoundaryConditionWithinTimeInterval(), MaterialPropertyLib::createDupuitPermeability(), MaterialLib::Solids::Ehlers::createEhlers(), NumLib::createEvolutionaryPIDcontroller(), MaterialPropertyLib::createExponential(), NumLib::createFixedTimeStepping(), MaterialLib::Fluid::createFluidDensityModel(), ParameterLib::createFunctionParameter(), ParameterLib::createGroupBasedParameter(), ProcessLib::createHCNonAdvectiveFreeComponentFlowBoundaryCondition(), ProcessLib::HeatConduction::createHeatConductionProcess(), ProcessLib::HeatTransportBHE::createHeatTransportBHEProcess(), ProcessLib::HT::createHTProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::HydroMechanics::createHydroMechanicsProcess(), MaterialPropertyLib::createIdealGasLaw(), NumLib::createIterationNumberBasedTimeStepping(), MaterialPropertyLib::createKozenyCarmanModel(), MaterialPropertyLib::createLinear(), MaterialLib::Fluid::createLinearConcentrationAndPressureDependentDensity(), MaterialLib::Fluid::createLinearConcentrationDependentDensity(), MaterialLib::Fracture::createLinearElasticIsotropic(), MaterialLib::Solids::createLinearElasticIsotropic(), MaterialLib::Solids::createLinearElasticOrthotropic(), MaterialLib::Fluid::createLinearPressureDependentViscosity(), MaterialPropertyLib::createLinearSaturationSwellingStress(), MaterialLib::Fluid::createLinearTemperatureDependentDensity(), MaterialLib::Fluid::createLiquidDensity(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), MaterialLib::Solids::Lubby2::createLubby2(), ParameterLib::createMeshElementParameter(), ParameterLib::createMeshNodeParameter(), MaterialLib::Solids::MFront::createMFront(), ProcessLib::createNeumannBoundaryCondition(), ProcessLib::createNodalSourceTerm(), MaterialLib::PorousMedium::createNonWettingPhaseBrooksCoreyOilGas(), MaterialLib::PorousMedium::createNonWettingPhaseVanGenuchten(), ProcessLib::NormalTractionBoundaryCondition::createNormalTractionBoundaryCondition(), MaterialPropertyLib::createParameterProperty(), MaterialPropertyLib::createPermeabilityMohrCoulombFailureIndexModel(), MaterialPropertyLib::createPermeabilityOrthotropicPowerLaw(), ProcessLib::createPhaseFieldIrreversibleDamageOracleBoundaryCondition(), ProcessLib::PhaseField::createPhaseFieldProcess(), MaterialPropertyLib::createPorosityFromMassBalance(), ProcessLib::createPrimaryVariableConstraintDirichletBoundaryCondition(), ProcessLib::createPythonBoundaryCondition(), ProcessLib::createPythonSourceTerm(), MaterialLib::PorousMedium::createRelativePermeabilityModel(), MaterialPropertyLib::createRelPermBrooksCorey(), MaterialPropertyLib::createRelPermLiakopoulos(), MaterialPropertyLib::createRelPermUdell(), MaterialPropertyLib::createRelPermVanGenuchten(), ProcessLib::RichardsComponentTransport::createRichardsComponentTransportProcess(), ProcessLib::RichardsFlow::createRichardsFlowProcess(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), ProcessLib::createRobinBoundaryCondition(), MaterialPropertyLib::createSaturationBrooksCorey(), MaterialPropertyLib::createSaturationDependentHeatConduction(), MaterialPropertyLib::createSaturationDependentSwelling(), MaterialPropertyLib::createSaturationLiakopoulos(), MaterialPropertyLib::createSaturationVanGenuchten(), ProcessLib::SmallDeformationNonlocal::createSmallDeformationNonlocalProcess(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::SmallDeformation::createSmallDeformationProcess(), ProcessLib::createSolutionDependentDirichletBoundaryCondition(), ProcessLib::SteadyStateDiffusion::createSteadyStateDiffusion(), MaterialPropertyLib::createStrainDependentPermeability(), MaterialLib::Fluid::createTemperatureDependentViscosity(), ProcessLib::TES::createTESProcess(), ProcessLib::ThermalTwoPhaseFlowWithPP::createThermalTwoPhaseFlowWithPPProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanicalPhaseField::createThermoMechanicalPhaseFieldProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), ParameterLib::createTimeDependentHeterogeneousParameter(), MaterialPropertyLib::createTransportPorosityFromMassBalance(), ProcessLib::TwoPhaseFlowWithPP::createTwoPhaseFlowWithPPProcess(), ProcessLib::TwoPhaseFlowWithPrho::createTwoPhaseFlowWithPrhoProcess(), MaterialLib::PorousMedium::createVanGenuchten(), ProcessLib::createVariableDependentNeumannBoundaryCondition(), MaterialLib::Fluid::createViscosityModel(), ProcessLib::createVolumetricSourceTerm(), MaterialLib::PorousMedium::createWettingPhaseBrooksCoreyOilGas(), and MaterialLib::PorousMedium::createWettingPhaseVanGenuchten().

◆ checkKeyname()

void BaseLib::ConfigTree::checkKeyname ( std::string const &  key) const
private

Checks if key complies with the rules [a-z0-9_].

Definition at line 276 of file ConfigTree.cpp.

277 {
278  if (key.empty()) {
279  error("Search for empty key.");
280  } else if (key_chars_start.find(key.front()) == std::string::npos) {
281  error("Key <" + key + "> starts with an illegal character.");
282  } else if (key.find_first_not_of(key_chars, 1) != std::string::npos) {
283  error("Key <" + key + "> contains illegal characters.");
284  } else if (key.find("__") != std::string::npos) {
285  // This is illegal because we use parameter names to generate doxygen
286  // page names. Thereby "__" acts as a separator character. Choosing
287  // other separators is not possible because of observed limitations
288  // for valid doxygen page names.
289  error("Key <" + key + "> contains double underscore.");
290  }
291 }
static const std::string key_chars_start
Set of allowed characters as the first letter of a key name.
Definition: ConfigTree.h:635
static const std::string key_chars
Set of allowed characters in a key name.
Definition: ConfigTree.h:638

References error(), key_chars, and key_chars_start.

Referenced by checkUnique(), checkUniqueAttr(), ConfigTree(), and peekConfigParameter().

◆ checkUnique()

void BaseLib::ConfigTree::checkUnique ( std::string const &  key) const
private

Asserts that the key has not been read yet.

Definition at line 308 of file ConfigTree.cpp.

309 {
310  checkKeyname(key);
311 
312  if (_visited_params.find({Attr::TAG, key}) != _visited_params.end()) {
313  error("Key <" + key + "> has already been processed.");
314  }
315 }

References _visited_params, checkKeyname(), and error().

Referenced by getConfigParameterList(), getConfigParameterOptional(), getConfigSubtreeList(), getConfigSubtreeOptional(), ignoreConfigParameter(), and ignoreConfigParameterAll().

◆ checkUniqueAttr()

void BaseLib::ConfigTree::checkUniqueAttr ( std::string const &  attr) const
private

Asserts that the attribute attr has not been read yet.

Definition at line 317 of file ConfigTree.cpp.

318 {
319  // Workaround for handling attributes with xml namespaces and uppercase letters.
320  if (attr.find(':') != std::string::npos)
321  {
322  auto pos = decltype(std::string::npos){0};
323 
324  // Replace colon and uppercase letters with an allowed character 'a'.
325  // That means, attributes containing a colon are also allowed to contain
326  // uppercase letters.
327  auto attr2 = attr;
328  do {
329  pos = attr2.find_first_of(":ABCDEFGHIJKLMNOPQRSTUVWXYZ", pos);
330  if (pos != std::string::npos)
331  {
332  attr2[pos] = 'a';
333  }
334  } while (pos != std::string::npos);
335 
336  checkKeyname(attr2);
337  }
338  else
339  {
340  checkKeyname(attr);
341  }
342 
343  if (_visited_params.find({Attr::ATTR, attr}) != _visited_params.end()) {
344  error("Attribute '" + attr + "' has already been processed.");
345  }
346 }

References _visited_params, checkKeyname(), and error().

Referenced by getConfigAttributeOptional(), and ignoreConfigAttribute().

◆ error()

void BaseLib::ConfigTree::error ( std::string const &  message) const
private

Called if an error occurs. Will call the error callback.

This method only acts as a helper method and throws std::runtime_error.

Definition at line 218 of file ConfigTree.cpp.

219 {
220  _onerror(_filename, _path, message);
221  OGS_FATAL(
222  "ConfigTree: The error handler does not break out of the normal "
223  "control flow.");
224 }

References _filename, _onerror, _path, and OGS_FATAL.

Referenced by checkConfigParameter(), checkKeyname(), checkUnique(), checkUniqueAttr(), getConfigAttribute(), getConfigAttributeOptional(), getConfigParameter(), getConfigParameterOptional(), getConfigParameterOptionalImpl(), getConfigSubtree(), getValue(), joinPaths(), markVisited(), BaseLib::ConfigTree::ParameterIterator::operator*(), and peekConfigParameter().

◆ getConfigAttribute() [1/2]

template<typename T >
T BaseLib::ConfigTree::getConfigAttribute ( std::string const &  attr) const

Get XML attribute attr of type T for the current parameter.

Returns
the requested attribute's value.
Precondition
attr must not have been read before from the current parameter.

Definition at line 194 of file ConfigTree-impl.h.

196 {
197  if (auto a = getConfigAttributeOptional<T>(attr))
198  {
199  return *a;
200  }
201 
202  error("Did not find XML attribute with name '" + attr + "'.");
203 }

References error().

Referenced by MaterialLib::PorousMedium::createPorousMediaProperties().

◆ getConfigAttribute() [2/2]

template<typename T >
T BaseLib::ConfigTree::getConfigAttribute ( std::string const &  attr,
T const &  default_value 
) const

Get XML attribute attr of type T for the current parameter or the default_value.

This method has a similar behaviour as getConfigAttribute(std::string const&) except the default_value is returned if the attribute has not been found.

Returns
the requested attribute's value.
Precondition
attr must not have been read before from the current parameter.

Definition at line 206 of file ConfigTree-impl.h.

208 {
209  if (auto a = getConfigAttributeOptional<T>(attr))
210  {
211  return *a;
212  }
213 
214  return default_value;
215 }

◆ getConfigAttributeOptional()

template<typename T >
boost::optional< T > BaseLib::ConfigTree::getConfigAttributeOptional ( std::string const &  attr) const

Get XML attribute attr of type T for the current parameter if present.

Returns
the requested attribute's value.
Precondition
attr must not have been read before from the current parameter.

Definition at line 219 of file ConfigTree-impl.h.

221 {
222  checkUniqueAttr(attr);
223  auto& ct = markVisited<T>(attr, Attr::ATTR, true);
224 
225  if (auto attrs = _tree->get_child_optional("<xmlattr>")) {
226  if (auto a = attrs->get_child_optional(attr)) {
227  ++ct.count; // count only if attribute has been found
228  if (auto v = a->get_value_optional<T>()) {
229  return v;
230  }
231  error("Value for XML attribute '" + attr + "' `" +
232  shortString(a->data()) +
233  "' not convertible to the desired type.");
234  }
235  }
236 
237  return boost::none;
238 }
void checkUniqueAttr(std::string const &attr) const
Asserts that the attribute attr has not been read yet.
Definition: ConfigTree.cpp:317

References _tree, ATTR, checkUniqueAttr(), error(), and shortString().

Referenced by MaterialLib::TwoPhaseFlowWithPP::createTwoPhaseFlowMaterialProperties(), ProcessLib::TwoPhaseFlowWithPrho::createTwoPhaseFlowPrhoMaterialProperties(), and anonymous_namespace{ProjectData.cpp}::readSingleMesh().

◆ getConfigParameter() [1/3]

template<typename T >
T BaseLib::ConfigTree::getConfigParameter ( std::string const &  param) const

Get parameter param of type T from the configuration tree.

Returns
the value looked for.
Precondition
param must not have been read before from this ConfigTree.

Definition at line 40 of file ConfigTree-impl.h.

42 {
43  if (auto p = getConfigParameterOptional<T>(param))
44  {
45  return *p;
46  }
47 
48  error("Key <" + param + "> has not been found");
49 }

References error().

Referenced by ChemistryLib::PhreeqcIOData::createAqueousSolution(), ChemistryLib::PhreeqcKernelData::createAqueousSolution(), MaterialPropertyLib::createBishopsPowerLaw(), MaterialPropertyLib::createBishopsSaturationCutoff(), ProcessLib::HeatTransportBHE::BHE::createBoreholeGeometry(), MaterialLib::PorousMedium::createBrooksCorey(), MaterialPropertyLib::createCapillaryPressureRegularizedVanGenuchten(), MaterialPropertyLib::createCapillaryPressureVanGenuchten(), ChemistryLib::createChemicalSolverInterface< ChemicalSolver::Phreeqc >(), MaterialLib::Fracture::CohesiveZoneModeI::createCohesiveZoneModeI(), ProcessLib::createCompareJacobiansJacobianAssembler(), anonymous_namespace{CreateComponent.cpp}::createComponent(), ProcessLib::ComponentTransport::createComponentTransportProcess(), MaterialPropertyLib::createConstant(), ParameterLib::createConstantParameter(), MaterialLib::Fracture::Permeability::createConstantPermeability(), ProcessLib::createConstraintDirichletBoundaryCondition(), NumLib::createConvergenceCriterionDeltaX(), NumLib::createConvergenceCriterionPerComponentDeltaX(), NumLib::createConvergenceCriterionPerComponentResidual(), NumLib::createConvergenceCriterionResidual(), MaterialLib::Fracture::createCoulomb(), MaterialPropertyLib::createCurve(), ParameterLib::createCurveScaledParameter(), ProcessLib::createDeactivatedSubdomain(), ProcessLib::createDirichletBoundaryCondition(), ProcessLib::createDirichletBoundaryConditionWithinTimeInterval(), MaterialPropertyLib::createDupuitPermeability(), MaterialLib::Solids::Ehlers::createEhlers(), NumLib::createEvolutionaryPIDcontroller(), MaterialPropertyLib::createExponential(), NumLib::createFixedTimeStepping(), ProcessLib::HeatTransportBHE::BHE::createFlowAndTemperatureControl(), MaterialLib::Fluid::createFluidDensityModel(), MaterialLib::Fluid::createFluidThermalConductivityModel(), ParameterLib::createGroupBasedParameter(), ProcessLib::HeatTransportBHE::BHE::createGroutParameters(), ProcessLib::createHCNonAdvectiveFreeComponentFlowBoundaryCondition(), ProcessLib::HeatConduction::createHeatConductionProcess(), ProcessLib::HeatTransportBHE::createHeatTransportBHEProcess(), ProcessLib::HT::createHTProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::HydroMechanics::createHydroMechanicsProcess(), NumLib::createIterationNumberBasedTimeStepping(), ChemistryLib::PhreeqcIOData::createKnobs(), MaterialPropertyLib::createKozenyCarmanModel(), MaterialPropertyLib::createLinear(), MaterialLib::Fluid::createLinearConcentrationAndPressureDependentDensity(), MaterialLib::Fluid::createLinearConcentrationDependentDensity(), MaterialLib::Fracture::createLinearElasticIsotropic(), MaterialLib::Fluid::createLinearPressureDependentViscosity(), MaterialPropertyLib::createLinearSaturationSwellingStress(), MaterialLib::Fluid::createLinearTemperatureDependentDensity(), MaterialLib::Fluid::createLiquidDensity(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), ParameterLib::createMeshElementParameter(), ParameterLib::createMeshNodeParameter(), MaterialLib::Solids::MFront::createMFront(), ProcessLib::createNeumannBoundaryCondition(), MaterialLib::createNewtonRaphsonSolverParameters(), ProcessLib::createNodalSourceTerm(), NumLib::createNonlinearSolver(), MaterialLib::PorousMedium::createNonWettingPhaseBrooksCoreyOilGas(), MaterialLib::PorousMedium::createNonWettingPhaseVanGenuchten(), ProcessLib::NormalTractionBoundaryCondition::createNormalTractionBoundaryCondition(), ProcessLib::createOutput(), ParameterLib::createParameter(), MaterialPropertyLib::createParameterProperty(), MaterialLib::PorousMedium::createPermeabilityModel(), MaterialPropertyLib::createPermeabilityMohrCoulombFailureIndexModel(), MaterialPropertyLib::createPermeabilityOrthotropicPowerLaw(), anonymous_namespace{CreatePhase.cpp}::createPhase(), ProcessLib::PhaseField::createPhaseFieldProcess(), MathLib::createPiecewiseLinearCurve(), ProcessLib::HeatTransportBHE::BHE::createPipe(), MaterialPropertyLib::createPorosityFromMassBalance(), MaterialLib::PorousMedium::createPorosityModel(), ProcessLib::createPrimaryVariableConstraintDirichletBoundaryCondition(), ProcessLib::createPythonBoundaryCondition(), ProcessLib::createPythonSourceTerm(), ProcessLib::HeatTransportBHE::BHE::createRefrigerantProperties(), MaterialPropertyLib::createRelPermBrooksCorey(), MaterialPropertyLib::createRelPermUdell(), MaterialPropertyLib::createRelPermVanGenuchten(), ProcessLib::RichardsComponentTransport::createRichardsComponentTransportProcess(), ProcessLib::RichardsFlow::createRichardsFlowProcess(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), ProcessLib::createRobinBoundaryCondition(), MaterialPropertyLib::createSaturationBrooksCorey(), MaterialPropertyLib::createSaturationDependentHeatConduction(), MaterialPropertyLib::createSaturationDependentSwelling(), MaterialPropertyLib::createSaturationVanGenuchten(), ProcessLib::SmallDeformationNonlocal::createSmallDeformationNonlocalProcess(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::SmallDeformation::createSmallDeformationProcess(), ProcessLib::createSolutionDependentDirichletBoundaryCondition(), MaterialLib::Fluid::createSpecificFluidHeatCapacityModel(), MaterialLib::PorousMedium::createStorageModel(), MaterialPropertyLib::createStrainDependentPermeability(), ProcessLib::SurfaceFluxData::createSurfaceFluxData(), MaterialLib::Fluid::createTemperatureDependentViscosity(), ProcessLib::ThermalTwoPhaseFlowWithPP::createThermalTwoPhaseFlowWithPPProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanicalPhaseField::createThermoMechanicalPhaseFieldProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), NumLib::createTimeDiscretization(), BaseLib::createTimeInterval(), MaterialPropertyLib::createTransportPorosityFromMassBalance(), ProcessLib::TwoPhaseFlowWithPP::createTwoPhaseFlowWithPPProcess(), ProcessLib::TwoPhaseFlowWithPrho::createTwoPhaseFlowWithPrhoProcess(), MaterialLib::PorousMedium::createVanGenuchten(), ProcessLib::createVariableDependentNeumannBoundaryCondition(), MaterialLib::Fluid::createViscosityModel(), ProcessLib::createVolumetricSourceTerm(), MaterialLib::PorousMedium::createWettingPhaseBrooksCoreyOilGas(), MaterialLib::PorousMedium::createWettingPhaseVanGenuchten(), anonymous_namespace{ProcessVariable.cpp}::findMeshInConfig(), ParameterLib::findParameter(), ProcessLib::findProcessVariable(), Adsorption::Reaction::newInstance(), ProcessLib::HeatTransportBHE::BHE::parseBHE1PTypeConfig(), ProcessLib::HeatTransportBHE::BHE::parseBHECoaxialConfig(), ProcessLib::HeatTransportBHE::BHE::parseBHEUTypeConfig(), and anonymous_namespace{ProjectData.cpp}::readMeshes().

◆ getConfigParameter() [2/3]

template<typename T >
T BaseLib::ConfigTree::getConfigParameter ( std::string const &  param,
T const &  default_value 
) const

Get parameter param of type T from the configuration tree or the default_value.

This method has a similar behaviour as getConfigParameter(std::string const&) except the default_value is returned if the attribute has not been found.

Precondition
param must not have been read before from this ConfigTree.

Definition at line 53 of file ConfigTree-impl.h.

55 {
56  if (auto p = getConfigParameterOptional<T>(param))
57  {
58  return *p;
59  }
60 
61  return default_value;
62 }

◆ getConfigParameter() [3/3]

ConfigTree BaseLib::ConfigTree::getConfigParameter ( std::string const &  root) const

Get parameter param from the configuration tree.

Returns
the subtree representing the requested parameter
Precondition
param must not have been read before from this ConfigTree.

Definition at line 112 of file ConfigTree.cpp.

114 {
115  auto ct = getConfigSubtree(root);
116  if (ct.hasChildren())
117  {
118  error("Requested parameter <" + root + "> actually is a subtree.");
119  }
120  return ct;
121 }
ConfigTree getConfigSubtree(std::string const &root) const
Definition: ConfigTree.cpp:151

References error(), and getConfigSubtree().

◆ getConfigParameterList() [1/2]

template<typename T >
Range< ConfigTree::ValueIterator< T > > BaseLib::ConfigTree::getConfigParameterList ( std::string const &  param) const

Fetches all parameters with name param from the current level of the tree.

The return value is suitable to be used with range-base for-loops.

Precondition
param must not have been read before from this ConfigTree.

Definition at line 117 of file ConfigTree-impl.h.

119 {
120  checkUnique(param);
121  markVisited<T>(param, Attr::TAG, true);
122 
123  auto p = _tree->equal_range(param);
124  return Range<ValueIterator<T> >(
125  ValueIterator<T>(p.first, param, *this),
126  ValueIterator<T>(p.second, param, *this));
127 }
void checkUnique(std::string const &key) const
Asserts that the key has not been read yet.
Definition: ConfigTree.cpp:308

References _tree, checkUnique(), and TAG.

Referenced by ProcessLib::HeatTransportBHE::createHeatTransportBHEProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::findProcessVariables(), and GeoLib::IO::BoostXmlGmlInterface::readPoints().

◆ getConfigParameterList() [2/2]

Range< ConfigTree::ParameterIterator > BaseLib::ConfigTree::getConfigParameterList ( std::string const &  param) const

Fetches all parameters with name param from the current level of the tree.

The return value is suitable to be used with range-base for-loops.

Precondition
param must not have been read before from this ConfigTree.

Definition at line 136 of file ConfigTree.cpp.

138 {
139  checkUnique(param);
140  markVisited(param, Attr::TAG, true);
141 
142  auto p = _tree->equal_range(param);
143 
144  return Range<ParameterIterator>(
145  ParameterIterator(p.first, param, *this),
146  ParameterIterator(p.second, param, *this));
147 }
CountType & markVisited(std::string const &key, Attr const is_attr, bool peek_only) const

References _tree, checkUnique(), markVisited(), and TAG.

◆ getConfigParameterOptional() [1/2]

template<typename T >
boost::optional< T > BaseLib::ConfigTree::getConfigParameterOptional ( std::string const &  param) const

Get parameter param of type T from the configuration tree if present

This method has a similar behaviour as getConfigParameter(std::string const&) except no errors are raised. Rather it can be told from the return value if the parameter could be read.

Precondition
param must not have been read before from this ConfigTree.

Definition at line 65 of file ConfigTree-impl.h.

67 {
68  checkUnique(param);
69 
70  return getConfigParameterOptionalImpl(param, static_cast<T*>(nullptr));
71 }
boost::optional< T > getConfigParameterOptionalImpl(std::string const &param, T *) const
Default implementation of reading a value of type T.

References checkUnique(), and getConfigParameterOptionalImpl().

Referenced by MaterialLib::PorousMedium::createBrooksCorey(), ProcessLib::createCentralDifferencesJacobianAssembler(), ChemistryLib::createChargeBalance(), ParameterLib::createConstantParameter(), NumLib::createConvergenceCriterionDeltaX(), NumLib::createConvergenceCriterionPerComponentDeltaX(), NumLib::createConvergenceCriterionPerComponentResidual(), NumLib::createConvergenceCriterionResidual(), ProcessLib::HT::createHTProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::HydroMechanics::createHydroMechanicsProcess(), MaterialLib::Solids::MFront::createMFront(), ProcessLib::PhaseField::createPhaseFieldProcess(), ProcessLib::RichardsComponentTransport::createRichardsComponentTransportProcess(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), MaterialLib::PorousMedium::createVanGenuchten(), MathLib::ODE::CVodeSolverImpl::CVodeSolverImpl(), anonymous_namespace{ProcessVariable.cpp}::findMeshInConfig(), ParameterLib::findOptionalTagParameter(), MathLib::LisOption::LisOption(), ProjectData::ProjectData(), and ProcessLib::TES::TESProcess::TESProcess().

◆ getConfigParameterOptional() [2/2]

boost::optional< ConfigTree > BaseLib::ConfigTree::getConfigParameterOptional ( std::string const &  root) const

Get parameter param from the configuration tree if present.

Returns
the subtree representing the requested parameter
Precondition
param must not have been read before from this ConfigTree.

Definition at line 124 of file ConfigTree.cpp.

126 {
127  auto ct = getConfigSubtreeOptional(root);
128  if (ct && ct->hasChildren())
129  {
130  error("Requested parameter <" + root + "> actually is a subtree.");
131  }
132  return ct;
133 }
boost::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
Definition: ConfigTree.cpp:161

References error(), and getConfigSubtreeOptional().

◆ getConfigParameterOptionalImpl() [1/2]

template<typename T >
boost::optional< std::vector< T > > BaseLib::ConfigTree::getConfigParameterOptionalImpl ( std::string const &  param,
std::vector< T > *   
) const
private

Implementation of reading a vector of values of type T.

Definition at line 86 of file ConfigTree-impl.h.

88 {
89  if (auto p = getConfigSubtreeOptional(param))
90  {
91  std::istringstream sstr{p->getValue<std::string>()};
92  std::vector<T> result;
93  T value;
94  while (sstr >> value)
95  {
96  result.push_back(value);
97  }
98  if (!sstr.eof()) // The stream is not read until the end, must be an
99  // error. result contains number of read values.
100  {
101  error("Value for key <" + param + "> `" +
102  shortString(sstr.str()) +
103  "' not convertible to a vector of the desired type."
104  " Could not convert token no. " +
105  std::to_string(result.size() + 1) + ".");
106  return boost::none;
107  }
108 
109  return boost::make_optional(result);
110  }
111 
112  return boost::none;
113 }

References error(), getConfigSubtreeOptional(), and shortString().

◆ getConfigParameterOptionalImpl() [2/2]

template<typename T >
boost::optional< T > BaseLib::ConfigTree::getConfigParameterOptionalImpl ( std::string const &  param,
T *   
) const
private

Default implementation of reading a value of type T.

Definition at line 74 of file ConfigTree-impl.h.

76 {
77  if (auto p = getConfigSubtreeOptional(param))
78  {
79  return p->getValue<T>();
80  }
81 
82  return boost::none;
83 }

References getConfigSubtreeOptional().

Referenced by getConfigParameterOptional().

◆ getConfigSubtree()

ConfigTree BaseLib::ConfigTree::getConfigSubtree ( std::string const &  root) const

Get the subtree rooted at root

If root is not found error() is called.

Precondition
root must not have been read before from this ConfigTree.

Definition at line 150 of file ConfigTree.cpp.

152 {
153  if (auto t = getConfigSubtreeOptional(root)) {
154  return std::move(*t);
155  }
156  error("Key <" + root + "> has not been found.");
157 }

References error(), and getConfigSubtreeOptional().

Referenced by MaterialLib::PorousMedium::createCapillaryPressureModel(), ChemistryLib::PhreeqcIOData::createChemicalSystem(), ProcessLib::createCompareJacobiansJacobianAssembler(), ProcessLib::ComponentTransport::createComponentTransportProcess(), MaterialLib::Fracture::createCoulomb(), MaterialLib::Solids::Creep::createCreepBGRa(), MaterialLib::Solids::Ehlers::createEhlers(), MaterialPropertyLib::createExponential(), NumLib::createFixedTimeStepping(), MaterialLib::Fluid::createFluidProperties(), ProcessLib::HeatConduction::createHeatConductionProcess(), ProcessLib::HeatTransportBHE::createHeatTransportBHEProcess(), ProcessLib::HT::createHTProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::HydroMechanics::createHydroMechanicsProcess(), ChemistryLib::PhreeqcKernelData::createInitialAqueousSolution(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), MaterialLib::Solids::Lubby2::createLubby2(), MaterialLib::Solids::MFront::createMFront(), ProcessLib::createOutput(), ProcessLib::PhaseField::createPhaseFieldProcess(), MaterialLib::PorousMedium::createPorousMediaProperties(), MaterialLib::PorousMedium::createRelativePermeabilityModel(), ProcessLib::RichardsComponentTransport::createRichardsComponentTransportProcess(), ProcessLib::RichardsFlow::createRichardsFlowProcess(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), ProcessLib::SmallDeformationNonlocal::createSmallDeformationNonlocalProcess(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::SmallDeformation::createSmallDeformationProcess(), ChemistryLib::PhreeqcIOData::createSolutionComponents(), ProcessLib::SteadyStateDiffusion::createSteadyStateDiffusion(), ProcessLib::TES::createTESProcess(), ProcessLib::ThermalTwoPhaseFlowWithPP::createThermalTwoPhaseFlowWithPPProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanicalPhaseField::createThermoMechanicalPhaseFieldProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), ParameterLib::createTimeDependentHeterogeneousParameter(), BaseLib::createTimeInterval(), ProcessLib::createTimeLoop(), MaterialLib::TwoPhaseFlowWithPP::createTwoPhaseFlowMaterialProperties(), ProcessLib::TwoPhaseFlowWithPrho::createTwoPhaseFlowPrhoMaterialProperties(), ProcessLib::TwoPhaseFlowWithPP::createTwoPhaseFlowWithPPProcess(), ProcessLib::TwoPhaseFlowWithPrho::createTwoPhaseFlowWithPrhoProcess(), getConfigParameter(), ProcessLib::HeatTransportBHE::BHE::parseBHE1PTypeConfig(), ProcessLib::HeatTransportBHE::BHE::parseBHECoaxialConfig(), ProcessLib::HeatTransportBHE::BHE::parseBHEUTypeConfig(), ProjectData::ProjectData(), and ProcessLib::TES::TESProcess::TESProcess().

◆ getConfigSubtreeList()

Range< ConfigTree::SubtreeIterator > BaseLib::ConfigTree::getConfigSubtreeList ( std::string const &  root) const

◆ getConfigSubtreeOptional()

boost::optional< ConfigTree > BaseLib::ConfigTree::getConfigSubtreeOptional ( std::string const &  root) const

Get the subtree rooted at root if present

Precondition
root must not have been read before from this ConfigTree.

Definition at line 160 of file ConfigTree.cpp.

162 {
163  checkUnique(root);
164 
165  if (auto subtree = _tree->get_child_optional(root)) {
166  markVisited(root, Attr::TAG, false);
167  return ConfigTree(*subtree, *this, root);
168  }
169  markVisited(root, Attr::TAG, true);
170  return boost::none;
171 }
ConfigTree(PTree const &tree, std::string filename, Callback error_cb, Callback warning_cb)
Definition: ConfigTree.cpp:35

References _tree, checkUnique(), ConfigTree(), markVisited(), and TAG.

Referenced by ChemistryLib::PhreeqcIOData::createChemicalSystem(), anonymous_namespace{CreateComponent.cpp}::createComponent(), ProcessLib::ComponentTransport::createComponentTransportProcess(), ProcessLib::createDeactivatedSubdomains(), MaterialLib::Solids::Ehlers::createEhlers(), MaterialLib::Fluid::createFluidProperties(), ProcessLib::HT::createHTProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), MaterialPropertyLib::createMedium(), ProcessLib::createOutput(), anonymous_namespace{CreatePhase.cpp}::createPhase(), MeshGeoToolsLib::createSearchLengthAlgorithm(), ProcessLib::createSecondaryVariables(), ProcessLib::SteadyStateDiffusion::createSteadyStateDiffusion(), ProcessLib::createTimeLoop(), getConfigParameterOptional(), getConfigParameterOptionalImpl(), getConfigSubtree(), MathLib::PETScLinearSolver::PETScLinearSolver(), ProcessLib::ProcessVariable::ProcessVariable(), ProjectData::ProjectData(), anonymous_namespace{ProjectData.cpp}::readMeshes(), and MathLib::EigenLinearSolver::setOption().

◆ getProjectFileName()

std::string const& BaseLib::ConfigTree::getProjectFileName ( ) const
inline

Used to get the project file name.

Definition at line 275 of file ConfigTree.h.

275 { return _filename; }

References _filename.

◆ getValue()

template<typename T >
T BaseLib::ConfigTree::getValue

Get the plain data contained in the current level of the tree.

Returns
the data converted to the type T
Precondition
The data must not have been read before.

Definition at line 176 of file ConfigTree-impl.h.

178 {
179  if (_have_read_data) {
180  error("The data of this subtree has already been read.");
181  }
182 
183  _have_read_data = true;
184 
185  if (auto v = _tree->get_value_optional<T>()) {
186  return *v;
187  }
188  error("Value `" + shortString(_tree->data()) +
189  "' is not convertible to the desired type.");
190 }

References _have_read_data, _tree, error(), and shortString().

Referenced by ChemistryLib::PhreeqcKernelData::createInitialAqueousSolution(), ChemistryLib::PhreeqcIOData::createSolutionComponents(), and anonymous_namespace{ProjectData.cpp}::readSingleMesh().

◆ hasChildren()

bool BaseLib::ConfigTree::hasChildren ( ) const
private

Checks if this tree has any children.

Definition at line 371 of file ConfigTree.cpp.

372 {
373  auto const& tree = *_tree;
374  if (tree.begin() == tree.end())
375  {
376  return false; // no children
377  }
378  if (tree.front().first == "<xmlattr>" && (++tree.begin()) == tree.end())
379  {
380  return false; // only attributes
381  }
382 
383  return true;
384 }

References _tree.

◆ ignoreConfigAttribute()

void BaseLib::ConfigTree::ignoreConfigAttribute ( std::string const &  attr) const

Tell this instance to ignore the XML attribute attr.

This method is used to avoid warning messages.

Precondition
attr must not have been read before from this ConfigTree.

Definition at line 195 of file ConfigTree.cpp.

196 {
197  checkUniqueAttr(attr);
198 
199  // Exercise: Guess what not! (hint: if not found, peek only)
200  // Btw. (not a hint) _tree->find() does not seem to work here.
201  bool peek_only = !_tree->get_child_optional("<xmlattr>." + attr);
202 
203  markVisited(attr, Attr::ATTR, peek_only);
204 }

References _tree, ATTR, checkUniqueAttr(), and markVisited().

◆ ignoreConfigParameter()

void BaseLib::ConfigTree::ignoreConfigParameter ( std::string const &  param) const

Tell this instance to ignore parameter param.

This method is used to avoid warning messages.

Precondition
param must not have been read before from this ConfigTree.

Definition at line 187 of file ConfigTree.cpp.

188 {
189  checkUnique(param);
190  // if not found, peek only
191  bool peek_only = _tree->find(param) == _tree->not_found();
192  markVisited(param, Attr::TAG, peek_only);
193 }

References _tree, checkUnique(), markVisited(), and TAG.

Referenced by NumLib::createTimeStepper(), and MathLib::ignoreOtherLinearSolvers().

◆ ignoreConfigParameterAll()

void BaseLib::ConfigTree::ignoreConfigParameterAll ( std::string const &  param) const

Tell this instance to ignore all parameters param on the current level of the tree.

This method is used to avoid warning messages.

Precondition
param must not have been read before from this ConfigTree.

Definition at line 206 of file ConfigTree.cpp.

207 {
208  checkUnique(param);
209  auto& ct = markVisited(param, Attr::TAG, true);
210 
211  auto p = _tree->equal_range(param);
212  for (auto it = p.first; it != p.second; ++it) {
213  ++ct.count;
214  }
215 }

References _tree, checkUnique(), markVisited(), and TAG.

◆ joinPaths()

std::string BaseLib::ConfigTree::joinPaths ( std::string const &  p1,
std::string const &  p2 
) const
private

Used to generate the path of a subtree.

Definition at line 293 of file ConfigTree.cpp.

295 {
296  if (p2.empty()) {
297  error("Second path to be joined is empty.");
298  }
299 
300  if (p1.empty())
301  {
302  return p2;
303  }
304 
305  return p1 + pathseparator + p2;
306 }
static const char pathseparator
Character separating two path components.
Definition: ConfigTree.h:632

References error(), and pathseparator.

◆ markVisited() [1/2]

ConfigTree::CountType & BaseLib::ConfigTree::markVisited ( std::string const &  key,
Attr const  is_attr,
bool const  peek_only 
) const
private

Keeps track of the key key and its value type ConfigTree.

This method asserts that a key is read always with the same type.

param peek_only if true, do not change the read-count of the given key.

Definition at line 349 of file ConfigTree.cpp.

351 {
352  return markVisited<ConfigTree>(key, is_attr, peek_only);
353 }

◆ markVisited() [2/2]

template<typename T >
ConfigTree::CountType & BaseLib::ConfigTree::markVisited ( std::string const &  key,
Attr const  is_attr,
bool  peek_only 
) const
private

Keeps track of the key key and its value type T.

This method asserts that a key is read always with the same type.

param peek_only if true, do not change the read-count of the given key.

Definition at line 242 of file ConfigTree-impl.h.

245 {
246  auto const type = std::type_index(typeid(T));
247 
248  auto p = _visited_params.emplace(std::make_pair(is_attr, key),
249  CountType{peek_only ? 0 : 1, type});
250 
251  if (!p.second) { // no insertion happened
252  auto& v = p.first->second;
253  if (v.type == type) {
254  if (!peek_only)
255  {
256  ++v.count;
257  }
258  } else {
259  error("There already was an attempt to obtain key <" + key +
260  "> with type '" + v.type.name() + "' (now: '" + type.name() +
261  "').");
262  }
263  }
264 
265  return p.first->second;
266 }

References _visited_params, and error().

Referenced by getConfigParameterList(), getConfigSubtreeList(), getConfigSubtreeOptional(), ignoreConfigAttribute(), ignoreConfigParameter(), ignoreConfigParameterAll(), BaseLib::ConfigTree::SubtreeIterator::operator*(), and BaseLib::ConfigTree::ValueIterator< ValueType >::operator*().

◆ markVisitedDecrement()

void BaseLib::ConfigTree::markVisitedDecrement ( Attr const  is_attr,
std::string const &  key 
) const
private

Used in the destructor to compute the difference between number of reads of a parameter and the number of times it exists in the ConfigTree

Definition at line 356 of file ConfigTree.cpp.

358 {
359  auto const type = std::type_index(typeid(nullptr));
360 
361  auto p = _visited_params.emplace(std::make_pair(is_attr, key),
362  CountType{-1, type});
363 
364  if (!p.second) { // no insertion happened
365  auto& v = p.first->second;
366  --v.count;
367  }
368 }

References _visited_params.

Referenced by checkAndInvalidate().

◆ onerror()

void BaseLib::ConfigTree::onerror ( std::string const &  filename,
std::string const &  path,
std::string const &  message 
)
static

Default error callback function Will throw std::runtime_error

Definition at line 232 of file ConfigTree.cpp.

234 {
235  OGS_FATAL("ConfigTree: In file `{:s}' at path <{:s}>: {:s}", filename, path,
236  message);
237 }

References OGS_FATAL.

◆ onwarning()

void BaseLib::ConfigTree::onwarning ( std::string const &  filename,
std::string const &  path,
std::string const &  message 
)
static

Default warning callback function Will print a warning message

Definition at line 239 of file ConfigTree.cpp.

241 {
242  WARN("ConfigTree: In file `{:s}' at path <{:s}>: {:s}", filename, path,
243  message);
244 }
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37

References WARN().

◆ operator=() [1/2]

ConfigTree & BaseLib::ConfigTree::operator= ( ConfigTree &&  other)

After being moved from, other is in an undefined state and must not be used anymore!

Definition at line 94 of file ConfigTree.cpp.

96 {
98 
99  _tree = other._tree;
100  other._tree = nullptr;
101  _path = std::move(other._path);
102  _filename = std::move(other._filename);
103  _visited_params = std::move(other._visited_params);
104  _have_read_data = other._have_read_data;
105  _onerror = std::move(other._onerror);
106  _onwarning = std::move(other._onwarning);
107 
108  return *this;
109 }

References _filename, _have_read_data, _onerror, _onwarning, _path, _tree, _visited_params, and checkAndInvalidate().

◆ operator=() [2/2]

ConfigTree& BaseLib::ConfigTree::operator= ( ConfigTree const &  )
delete

copying is not compatible with the semantics of this class

◆ peekConfigParameter()

template<typename T >
T BaseLib::ConfigTree::peekConfigParameter ( std::string const &  param) const

Peek at a parameter param of type T from the configuration tree.

This method is an exception to the single-read rule. It is meant to be used to tell from a ConfigTree instance where to pass that instance on for further processing.

But in order that the requested parameter counts as "completely parsed", it has to be read through some other method, too.

Return value and error behaviour are the same as for getConfigParameter<T>(std::string const&).

Definition at line 131 of file ConfigTree-impl.h.

133 {
134  checkKeyname(param);
135 
136  if (auto p = _tree->get_child_optional(param))
137  {
138  try
139  {
140  return p->get_value<T>();
141  }
142  catch (boost::property_tree::ptree_bad_data const&)
143  {
144  error("Value for key <" + param + "> `" + shortString(p->data()) +
145  "' not convertible to the desired type.");
146  }
147  }
148  else
149  {
150  error("Key <" + param + "> has not been found");
151  }
152 }

References _tree, checkKeyname(), error(), and shortString().

Referenced by MaterialPropertyLib::createAverageMolarMass(), MaterialPropertyLib::createBishopsPowerLaw(), MaterialPropertyLib::createBishopsSaturationCutoff(), ProcessLib::createBoundaryCondition(), MaterialLib::PorousMedium::createCapillaryPressureModel(), MaterialPropertyLib::createCapillaryPressureVanGenuchten(), MaterialPropertyLib::createConstant(), MaterialLib::Solids::createConstitutiveRelation(), NumLib::createConvergenceCriterion(), MaterialPropertyLib::createCurve(), ProcessLib::createDeactivatedSubdomain(), ProcessLib::createDirichletBoundaryConditionWithinTimeInterval(), MaterialPropertyLib::createDupuitPermeability(), MaterialPropertyLib::createExponential(), MaterialLib::Fluid::createFluidDensityModel(), MaterialPropertyLib::createIdealGasLaw(), MaterialPropertyLib::createLinear(), MaterialPropertyLib::createLinearSaturationSwellingStress(), ParameterLib::createParameter(), MaterialPropertyLib::createParameterProperty(), MaterialLib::Fracture::Permeability::createPermeabilityModel(), MaterialPropertyLib::createPermeabilityMohrCoulombFailureIndexModel(), MaterialPropertyLib::createPermeabilityOrthotropicPowerLaw(), MaterialPropertyLib::createPorosityFromMassBalance(), anonymous_namespace{CreateProperty.cpp}::createProperty(), MaterialLib::PorousMedium::createRelativePermeabilityModel(), MaterialPropertyLib::createRelPermBrooksCorey(), MaterialPropertyLib::createRelPermLiakopoulos(), MaterialPropertyLib::createRelPermUdell(), MaterialPropertyLib::createRelPermVanGenuchten(), MaterialPropertyLib::createSaturationBrooksCorey(), MaterialPropertyLib::createSaturationDependentHeatConduction(), MaterialPropertyLib::createSaturationDependentSwelling(), MaterialPropertyLib::createSaturationLiakopoulos(), MaterialPropertyLib::createSaturationVanGenuchten(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::createSourceTerm(), MaterialPropertyLib::createStrainDependentPermeability(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), NumLib::createTimeStepper(), MaterialPropertyLib::createTransportPorosityFromMassBalance(), MaterialLib::Fluid::createViscosityModel(), and ProcessLib::createVolumetricSourceTerm().

◆ shortString()

std::string BaseLib::ConfigTree::shortString ( std::string const &  s)
staticprivate

returns a short string at suitable for error/warning messages

Definition at line 263 of file ConfigTree.cpp.

264 {
265  const std::size_t maxlen = 100;
266 
267  if (s.size() < maxlen)
268  {
269  return s;
270  }
271 
272  return s.substr(0, maxlen-3) + "...";
273 }

Referenced by checkAndInvalidate(), getConfigAttributeOptional(), getConfigParameterOptionalImpl(), getValue(), and peekConfigParameter().

◆ warning()

void BaseLib::ConfigTree::warning ( std::string const &  message) const
private

Called for printing warning messages. Will call the warning callback. This method only acts as a helper method.

Definition at line 226 of file ConfigTree.cpp.

227 {
228  _onwarning(_filename, _path, message);
229 }

References _filename, _onwarning, and _path.

Referenced by checkAndInvalidate().

Friends And Related Function Documentation

◆ checkAndInvalidate [1/3]

void checkAndInvalidate ( ConfigTree conf)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 453 of file ConfigTree.cpp.

454 {
455  conf.checkAndInvalidate();
456 }

◆ checkAndInvalidate [2/3]

void checkAndInvalidate ( ConfigTree *const  conf)
friend

Check if conf has been read entirely and invalidate it.

This method can savely be called on nullptr's.

See also
ConfigTree::checkAndInvalidate()

Definition at line 458 of file ConfigTree.cpp.

459 {
460  if (conf)
461  {
462  conf->checkAndInvalidate();
463  }
464 }

◆ checkAndInvalidate [3/3]

void checkAndInvalidate ( std::unique_ptr< ConfigTree > const &  conf)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 466 of file ConfigTree.cpp.

467 {
468  if (conf)
469  {
470  conf->checkAndInvalidate();
471  }
472 }

Member Data Documentation

◆ _filename

std::string BaseLib::ConfigTree::_filename
private

The path of the file from which this tree has been read.

Definition at line 611 of file ConfigTree.h.

Referenced by error(), getProjectFileName(), operator=(), and warning().

◆ _have_read_data

bool BaseLib::ConfigTree::_have_read_data = false
mutableprivate

Indicates if the plain data contained in this tree has already been read.

Definition at line 626 of file ConfigTree.h.

Referenced by checkAndInvalidate(), getValue(), and operator=().

◆ _onerror

Callback BaseLib::ConfigTree::_onerror
private

Custom error callback.

Definition at line 628 of file ConfigTree.h.

Referenced by ConfigTree(), error(), and operator=().

◆ _onwarning

Callback BaseLib::ConfigTree::_onwarning
private

Custom warning callback.

Definition at line 629 of file ConfigTree.h.

Referenced by ConfigTree(), operator=(), and warning().

◆ _path

std::string BaseLib::ConfigTree::_path
private

A path printed in error/warning messages.

Definition at line 608 of file ConfigTree.h.

Referenced by error(), operator=(), and warning().

◆ _tree

◆ _visited_params

std::map<KeyType, CountType> BaseLib::ConfigTree::_visited_params
mutableprivate

A map KeyType -> (count, type) keeping track which parameters have been read how often and which datatype they have.

This member will be written to when reading from the config tree. Therefore it has to be mutable in order to be able to read from constant instances, e.g., those passed as constant references to temporaries.

Definition at line 623 of file ConfigTree.h.

Referenced by checkAndInvalidate(), checkUnique(), checkUniqueAttr(), markVisited(), markVisitedDecrement(), and operator=().

◆ key_chars

const std::string BaseLib::ConfigTree::key_chars = key_chars_start + "_0123456789"
staticprivate

Set of allowed characters in a key name.

Definition at line 638 of file ConfigTree.h.

Referenced by checkKeyname().

◆ key_chars_start

const std::string BaseLib::ConfigTree::key_chars_start = "abcdefghijklmnopqrstuvwxyz"
staticprivate

Set of allowed characters as the first letter of a key name.

Definition at line 635 of file ConfigTree.h.

Referenced by checkKeyname().

◆ pathseparator

const char BaseLib::ConfigTree::pathseparator = '/'
staticprivate

Character separating two path components.

Definition at line 632 of file ConfigTree.h.

Referenced by joinPaths().


The documentation for this class was generated from the following files: