OGS  master
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 occurred.
  • 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 96 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 >
std::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
 
std::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 >
std::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
 
std::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 >
std::optional< T > getConfigParameterOptionalImpl (std::string const &param, T *) const
 Default implementation of reading a value of type T. More...
 
template<typename T >
std::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, CountTypevisited_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 233 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 619 of file ConfigTree.h.

◆ PTree

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

The tree being wrapped by this class.

Definition at line 224 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 543 of file ConfigTree.h.

544  {
545  TAG = false, ATTR = true
546  };

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 34 of file ConfigTree.cpp.

38  : tree_(&tree),
39  filename_(std::move(filename)),
40  onerror_(std::move(error_cb)),
41  onwarning_(std::move(warning_cb))
42 {
43  if (!onerror_)
44  {
45  OGS_FATAL("ConfigTree: No valid error handler provided.");
46  }
47  if (!onwarning_)
48  {
49  OGS_FATAL("ConfigTree: No valid warning handler provided.");
50  }
51 }
#define OGS_FATAL(...)
Definition: Error.h:25
Callback onwarning_
Custom warning callback.
Definition: ConfigTree.h:634
boost::property_tree::ptree const * tree_
The wrapped tree.
Definition: ConfigTree.h:610
Callback onerror_
Custom error callback.
Definition: ConfigTree.h:633
std::string filename_
The path of the file from which this tree has been read.
Definition: ConfigTree.h:616

References OGS_FATAL, onerror_, and onwarning_.

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 64 of file ConfigTree.cpp.

65  : tree_(other.tree_),
66  path_(std::move(other.path_)),
67  filename_(std::move(other.filename_)),
68  visited_params_(std::move(other.visited_params_)),
69  have_read_data_(other.have_read_data_),
70  onerror_(std::move(other.onerror_)),
71  onwarning_(std::move(other.onwarning_))
72 {
73  other.tree_ = nullptr;
74 }
bool have_read_data_
Indicates if the plain data contained in this tree has already been read.
Definition: ConfigTree.h:631
std::map< KeyType, CountType > visited_params_
Definition: ConfigTree.h:628
std::string path_
A path printed in error/warning messages.
Definition: ConfigTree.h:613

◆ ~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 76 of file ConfigTree.cpp.

77 {
78  if (std::uncaught_exceptions() > 0)
79  {
80  /* If the stack unwinds the check below shall be suppressed in order to
81  * not accumulate false-positive configuration errors.
82  */
83  return;
84  }
85 
86  try
87  {
89  }
90  catch (std::exception& e)
91  {
92  ERR("{:s}", e.what());
93  configtree_destructor_error_messages.push_front(e.what());
94  }
95 }
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 53 of file ConfigTree.cpp.

55  : tree_(&tree),
56  path_(joinPaths(parent.path_, root)),
57  filename_(parent.filename_),
58  onerror_(parent.onerror_),
59  onwarning_(parent.onwarning_)
60 {
61  checkKeyname(root);
62 }
std::string joinPaths(std::string const &p1, std::string const &p2) const
Used to generate the path of a subtree.
Definition: ConfigTree.cpp:293
void checkKeyname(std::string const &key) const
Checks if key complies with the rules [a-z0-9_].
Definition: ConfigTree.cpp:269

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 239 of file ConfigTree.cpp.

240 {
242  {
243  return;
244  }
245 
246  ERR("ConfigTree: There have been errors when parsing the configuration "
247  "file(s):");
248 
249  for (auto const& msg : configtree_destructor_error_messages)
250  {
251  ERR("{:s}", msg);
252  }
253 
254  OGS_FATAL("There have been errors when parsing the configuration file(s).");
255 }

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 390 of file ConfigTree.cpp.

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

References ATTR, have_read_data_, markVisitedDecrement(), shortString(), TAG, tree_, visited_params_, and warning().

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

◆ 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:212

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(), MaterialPropertyLib::createClausiusClapeyron(), 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(), MaterialPropertyLib::createEffectiveThermalConductivityPorosityMixing(), MaterialLib::Solids::Ehlers::createEhlers(), MaterialPropertyLib::createEmbeddedFracturePermeability(), NumLib::createEvolutionaryPIDcontroller(), MaterialPropertyLib::createExponential(), NumLib::createFixedTimeStepping(), MaterialLib::Fluid::createFluidDensityModel(), MaterialPropertyLib::createFunction(), ParameterLib::createFunctionParameter(), MaterialPropertyLib::createGasPressureDependentPermeability(), 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(), MaterialPropertyLib::createLinearWaterVapourLatentHeat(), 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::createOrthotropicEmbeddedFracturePermeability(), MaterialPropertyLib::createParameterProperty(), MaterialPropertyLib::createPermeabilityMohrCoulombFailureIndexModel(), MaterialPropertyLib::createPermeabilityOrthotropicPowerLaw(), ProcessLib::createPhaseFieldIrreversibleDamageOracleBoundaryCondition(), ProcessLib::PhaseField::createPhaseFieldProcess(), MaterialPropertyLib::createPorosityFromMassBalance(), ProcessLib::createPrimaryVariableConstraintDirichletBoundaryCondition(), ProcessLib::createPythonBoundaryCondition(), ProcessLib::createPythonSourceTerm(), ParameterLib::createRandomFieldMeshElementParameter(), MaterialLib::PorousMedium::createRelativePermeabilityModel(), MaterialPropertyLib::createRelPermBrooksCorey(), MaterialPropertyLib::createRelPermBrooksCoreyNonwettingPhase(), MaterialPropertyLib::createRelPermLiakopoulos(), MaterialPropertyLib::createRelPermNonWettingPhaseVanGenuchtenMualem(), MaterialPropertyLib::createRelPermUdell(), MaterialPropertyLib::createRelPermUdellNonwettingPhase(), MaterialPropertyLib::createRelPermVanGenuchten(), ProcessLib::RichardsComponentTransport::createRichardsComponentTransportProcess(), ProcessLib::RichardsFlow::createRichardsFlowProcess(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), ProcessLib::createRobinBoundaryCondition(), MaterialPropertyLib::createSaturationBrooksCorey(), MaterialPropertyLib::createSaturationDependentSwelling(), MaterialPropertyLib::createSaturationDependentThermalConductivity(), MaterialPropertyLib::createSaturationExponential(), MaterialPropertyLib::createSaturationLiakopoulos(), MaterialPropertyLib::createSaturationVanGenuchten(), ProcessLib::SmallDeformationNonlocal::createSmallDeformationNonlocalProcess(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::SmallDeformation::createSmallDeformationProcess(), MaterialPropertyLib::createSoilThermalConductivitySomerton(), ProcessLib::createSolutionDependentDirichletBoundaryCondition(), ProcessLib::SteadyStateDiffusion::createSteadyStateDiffusion(), ProcessLib::StokesFlow::createStokesFlowProcess(), MaterialPropertyLib::createStrainDependentPermeability(), MaterialPropertyLib::createTemperatureDependentDiffusion(), MaterialLib::Fluid::createTemperatureDependentViscosity(), ProcessLib::TES::createTESProcess(), ProcessLib::TH2M::createTH2MProcess(), ProcessLib::ThermalTwoPhaseFlowWithPP::createThermalTwoPhaseFlowWithPPProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanicalPhaseField::createThermoMechanicalPhaseFieldProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), ProcessLib::ThermoRichardsFlow::createThermoRichardsFlowProcess(), ProcessLib::ThermoRichardsMechanics::createThermoRichardsMechanicsProcess(), ParameterLib::createTimeDependentHeterogeneousParameter(), MaterialPropertyLib::createTransportPorosityFromMassBalance(), ProcessLib::TwoPhaseFlowWithPP::createTwoPhaseFlowWithPPProcess(), ProcessLib::TwoPhaseFlowWithPrho::createTwoPhaseFlowWithPrhoProcess(), MaterialLib::PorousMedium::createVanGenuchten(), MaterialPropertyLib::createVapourDiffusionFEBEX(), MaterialPropertyLib::createVapourDiffusionPMQ(), ProcessLib::createVariableDependentNeumannBoundaryCondition(), MaterialLib::Fluid::createViscosityModel(), ProcessLib::createVolumetricSourceTerm(), MaterialPropertyLib::createWaterVapourDensity(), MaterialPropertyLib::createWaterVapourLatentHeatWithCriticalTemperature(), 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 269 of file ConfigTree.cpp.

270 {
271  if (key.empty())
272  {
273  error("Search for empty key.");
274  }
275  else if (key_chars_start.find(key.front()) == std::string::npos)
276  {
277  error("Key <" + key + "> starts with an illegal character.");
278  }
279  else if (key.find_first_not_of(key_chars, 1) != std::string::npos)
280  {
281  error("Key <" + key + "> contains illegal characters.");
282  }
283  else if (key.find("__") != std::string::npos)
284  {
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:640
static const std::string key_chars
Set of allowed characters in a key name.
Definition: ConfigTree.h:643

References error(), key_chars, and key_chars_start.

Referenced by ConfigTree(), checkUnique(), checkUniqueAttr(), 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 309 of file ConfigTree.cpp.

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

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

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 319 of file ConfigTree.cpp.

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

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

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 212 of file ConfigTree.cpp.

213 {
214  onerror_(filename_, path_, message);
215  OGS_FATAL(
216  "ConfigTree: The error handler does not break out of the normal "
217  "control flow.");
218 }

References filename_, OGS_FATAL, onerror_, and path_.

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 196 of file ConfigTree-impl.h.

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

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 208 of file ConfigTree-impl.h.

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

◆ getConfigAttributeOptional()

template<typename T >
std::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 220 of file ConfigTree-impl.h.

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

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

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 >(), MaterialPropertyLib::createClausiusClapeyron(), 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(), MaterialPropertyLib::createEmbeddedFracturePermeability(), NumLib::createEvolutionaryPIDcontroller(), MaterialPropertyLib::createExponential(), NumLib::createFixedTimeStepping(), ProcessLib::HeatTransportBHE::BHE::createFlowAndTemperatureControl(), MaterialLib::Fluid::createFluidDensityModel(), MaterialLib::Fluid::createFluidThermalConductivityModel(), MaterialPropertyLib::createFunction(), MaterialPropertyLib::createGasPressureDependentPermeability(), 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(), NumLib::createNewtonRaphsonSolverParameters(), ProcessLib::createNodalSourceTerm(), NumLib::createNonlinearSolver(), MaterialLib::PorousMedium::createNonWettingPhaseBrooksCoreyOilGas(), MaterialLib::PorousMedium::createNonWettingPhaseVanGenuchten(), ProcessLib::NormalTractionBoundaryCondition::createNormalTractionBoundaryCondition(), MaterialPropertyLib::createOrthotropicEmbeddedFracturePermeability(), 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(), ParameterLib::createRandomFieldMeshElementParameter(), ProcessLib::HeatTransportBHE::BHE::createRefrigerantProperties(), MaterialPropertyLib::createRelPermBrooksCorey(), MaterialPropertyLib::createRelPermBrooksCoreyNonwettingPhase(), MaterialPropertyLib::createRelPermNonWettingPhaseVanGenuchtenMualem(), MaterialPropertyLib::createRelPermUdell(), MaterialPropertyLib::createRelPermUdellNonwettingPhase(), MaterialPropertyLib::createRelPermVanGenuchten(), ProcessLib::RichardsComponentTransport::createRichardsComponentTransportProcess(), ProcessLib::RichardsFlow::createRichardsFlowProcess(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), ProcessLib::createRobinBoundaryCondition(), MaterialPropertyLib::createSaturationBrooksCorey(), MaterialPropertyLib::createSaturationDependentSwelling(), MaterialPropertyLib::createSaturationDependentThermalConductivity(), MaterialPropertyLib::createSaturationExponential(), MaterialPropertyLib::createSaturationVanGenuchten(), ProcessLib::SmallDeformationNonlocal::createSmallDeformationNonlocalProcess(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::SmallDeformation::createSmallDeformationProcess(), MaterialPropertyLib::createSoilThermalConductivitySomerton(), ProcessLib::createSolutionDependentDirichletBoundaryCondition(), MaterialLib::Fluid::createSpecificFluidHeatCapacityModel(), ProcessLib::StokesFlow::createStokesFlowProcess(), MaterialLib::PorousMedium::createStorageModel(), MaterialPropertyLib::createStrainDependentPermeability(), ProcessLib::SurfaceFluxData::createSurfaceFluxData(), MaterialPropertyLib::createTemperatureDependentDiffusion(), MaterialLib::Fluid::createTemperatureDependentViscosity(), ProcessLib::TH2M::createTH2MProcess(), ProcessLib::ThermalTwoPhaseFlowWithPP::createThermalTwoPhaseFlowWithPPProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanicalPhaseField::createThermoMechanicalPhaseFieldProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), ProcessLib::ThermoRichardsFlow::createThermoRichardsFlowProcess(), ProcessLib::ThermoRichardsMechanics::createThermoRichardsMechanicsProcess(), NumLib::createTimeDiscretization(), BaseLib::createTimeInterval(), MaterialPropertyLib::createTransportPorosityFromMassBalance(), ProcessLib::TwoPhaseFlowWithPP::createTwoPhaseFlowWithPPProcess(), ProcessLib::TwoPhaseFlowWithPrho::createTwoPhaseFlowWithPrhoProcess(), MaterialLib::PorousMedium::createVanGenuchten(), MaterialPropertyLib::createVapourDiffusionFEBEX(), 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(), ProcessLib::parseLineSegment(), 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 113 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:146

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:309

References checkUnique(), TAG, and tree_.

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 134 of file ConfigTree.cpp.

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

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

◆ getConfigParameterOptional() [1/2]

template<typename T >
std::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 }
std::optional< T > getConfigParameterOptionalImpl(std::string const &param, T *) const
Default implementation of reading a value of type T.

References checkUnique(), and getConfigParameterOptionalImpl().

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

◆ getConfigParameterOptional() [2/2]

std::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 123 of file ConfigTree.cpp.

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

References error(), and getConfigSubtreeOptional().

◆ getConfigParameterOptionalImpl() [1/2]

template<typename T >
std::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 std::nullopt;
107  }
108 
109  return std::make_optional(result);
110  }
111 
112  return std::nullopt;
113 }

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

◆ getConfigParameterOptionalImpl() [2/2]

template<typename T >
std::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 std::nullopt;
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 146 of file ConfigTree.cpp.

147 {
148  if (auto t = getConfigSubtreeOptional(root))
149  {
150  return std::move(*t);
151  }
152  error("Key <" + root + "> has not been found.");
153 }

References error(), and getConfigSubtreeOptional().

Referenced by ProjectData::ProjectData(), ProcessLib::TES::TESProcess::TESProcess(), 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(), MaterialPropertyLib::createFunction(), 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::StokesFlow::createStokesFlowProcess(), ProcessLib::TES::createTESProcess(), ProcessLib::TH2M::createTH2MProcess(), ProcessLib::ThermalTwoPhaseFlowWithPP::createThermalTwoPhaseFlowWithPPProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanicalPhaseField::createThermoMechanicalPhaseFieldProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), ProcessLib::ThermoRichardsFlow::createThermoRichardsFlowProcess(), ProcessLib::ThermoRichardsMechanics::createThermoRichardsMechanicsProcess(), 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(), and ProcessLib::HeatTransportBHE::BHE::parseBHEUTypeConfig().

◆ getConfigSubtreeList()

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

Get all subtrees that have a root root from the current level of the tree.

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

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

Definition at line 169 of file ConfigTree.cpp.

171 {
172  checkUnique(root);
173  markVisited(root, Attr::TAG, true);
174 
175  auto p = tree_->equal_range(root);
176 
177  return Range<SubtreeIterator>(SubtreeIterator(p.first, root, *this),
178  SubtreeIterator(p.second, root, *this));
179 }

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

Referenced by ApplicationsLib::TestDefinition::TestDefinition(), MaterialLib::Solids::createConstitutiveRelations(), NumLib::createFixedTimeStepping(), MaterialPropertyLib::createFunction(), ParameterLib::createFunctionParameter(), ParameterLib::createGroupBasedParameter(), MaterialPropertyLib::createLinear(), ProcessLib::createPerProcessData(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), InSituLib::Initialize(), ProjectData::parseLinearSolvers(), ProjectData::parseNonlinearSolvers(), ProjectData::parseParameters(), ProjectData::parseProcesses(), ProjectData::parseProcessVariables(), GeoLib::IO::BoostXmlGmlInterface::readPolylines(), and GeoLib::IO::BoostXmlGmlInterface::readSurfaces().

◆ getConfigSubtreeOptional()

std::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 155 of file ConfigTree.cpp.

157 {
158  checkUnique(root);
159 
160  if (auto subtree = tree_->get_child_optional(root))
161  {
162  markVisited(root, Attr::TAG, false);
163  return ConfigTree(*subtree, *this, root);
164  }
165  markVisited(root, Attr::TAG, true);
166  return std::nullopt;
167 }
ConfigTree(PTree const &tree, std::string filename, Callback error_cb, Callback warning_cb)
Definition: ConfigTree.cpp:34

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

Referenced by MathLib::PETScLinearSolver::PETScLinearSolver(), ProcessLib::ProcessVariable::ProcessVariable(), ProjectData::ProjectData(), ChemistryLib::PhreeqcIOData::createChemicalSystem(), anonymous_namespace{CreateComponent.cpp}::createComponent(), ProcessLib::ComponentTransport::createComponentTransportProcess(), ProcessLib::createDeactivatedSubdomain(), 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(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), MeshGeoToolsLib::createSearchLengthAlgorithm(), ProcessLib::createSecondaryVariables(), ProcessLib::SteadyStateDiffusion::createSteadyStateDiffusion(), ProcessLib::createTimeLoop(), getConfigParameterOptional(), getConfigParameterOptionalImpl(), getConfigSubtree(), 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 280 of file ConfigTree.h.

280 { 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  {
181  error("The data of this subtree has already been read.");
182  }
183 
184  have_read_data_ = true;
185 
186  if (auto v = tree_->get_value_optional<T>())
187  {
188  return *v;
189  }
190  error("Value `" + shortString(tree_->data()) +
191  "' is not convertible to the desired type.");
192 }

References error(), have_read_data_, shortString(), and tree_.

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 375 of file ConfigTree.cpp.

376 {
377  auto const& tree = *tree_;
378  if (tree.begin() == tree.end())
379  {
380  return false; // no children
381  }
382  if (tree.front().first == "<xmlattr>" && (++tree.begin()) == tree.end())
383  {
384  return false; // only attributes
385  }
386 
387  return true;
388 }

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 189 of file ConfigTree.cpp.

190 {
191  checkUniqueAttr(attr);
192 
193  // Exercise: Guess what not! (hint: if not found, peek only)
194  // Btw. (not a hint) tree_->find() does not seem to work here.
195  bool peek_only = !tree_->get_child_optional("<xmlattr>." + attr);
196 
197  markVisited(attr, Attr::ATTR, peek_only);
198 }

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

◆ 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 181 of file ConfigTree.cpp.

182 {
183  checkUnique(param);
184  // if not found, peek only
185  bool peek_only = tree_->find(param) == tree_->not_found();
186  markVisited(param, Attr::TAG, peek_only);
187 }

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

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 200 of file ConfigTree.cpp.

201 {
202  checkUnique(param);
203  auto& ct = markVisited(param, Attr::TAG, true);
204 
205  auto p = tree_->equal_range(param);
206  for (auto it = p.first; it != p.second; ++it)
207  {
208  ++ct.count;
209  }
210 }

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

◆ 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  {
298  error("Second path to be joined is empty.");
299  }
300 
301  if (p1.empty())
302  {
303  return p2;
304  }
305 
306  return p1 + pathseparator + p2;
307 }
static const char pathseparator
Character separating two path components.
Definition: ConfigTree.h:637

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 353 of file ConfigTree.cpp.

356 {
357  return markVisited<ConfigTree>(key, is_attr, peek_only);
358 }

◆ 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 244 of file ConfigTree-impl.h.

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

References error(), and visited_params_.

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 360 of file ConfigTree.cpp.

362 {
363  auto const type = std::type_index(typeid(nullptr));
364 
365  auto p = visited_params_.emplace(std::make_pair(is_attr, key),
366  CountType{-1, type});
367 
368  if (!p.second)
369  { // no insertion happened
370  auto& v = p.first->second;
371  --v.count;
372  }
373 }

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 225 of file ConfigTree.cpp.

227 {
228  OGS_FATAL("ConfigTree: In file `{:s}' at path <{:s}>: {:s}", filename, path,
229  message);
230 }

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 232 of file ConfigTree.cpp.

234 {
235  WARN("ConfigTree: In file `{:s}' at path <{:s}>: {:s}", filename, path,
236  message);
237 }
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 97 of file ConfigTree.cpp.

98 {
100 
101  tree_ = other.tree_;
102  other.tree_ = nullptr;
103  path_ = std::move(other.path_);
104  filename_ = std::move(other.filename_);
105  visited_params_ = std::move(other.visited_params_);
106  have_read_data_ = other.have_read_data_;
107  onerror_ = std::move(other.onerror_);
108  onwarning_ = std::move(other.onwarning_);
109 
110  return *this;
111 }

References checkAndInvalidate(), filename_, have_read_data_, onerror_, onwarning_, path_, tree_, and visited_params_.

◆ 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 checkKeyname(), error(), shortString(), and tree_.

Referenced by MaterialPropertyLib::createAverageMolarMass(), MaterialPropertyLib::createBishopsPowerLaw(), MaterialPropertyLib::createBishopsSaturationCutoff(), ProcessLib::createBoundaryCondition(), MaterialLib::PorousMedium::createCapillaryPressureModel(), MaterialPropertyLib::createCapillaryPressureVanGenuchten(), MaterialPropertyLib::createClausiusClapeyron(), MaterialPropertyLib::createConstant(), MaterialLib::Solids::createConstitutiveRelation(), NumLib::createConvergenceCriterion(), MaterialPropertyLib::createCurve(), ProcessLib::createDirichletBoundaryConditionWithinTimeInterval(), MaterialPropertyLib::createDupuitPermeability(), MaterialPropertyLib::createEffectiveThermalConductivityPorosityMixing(), MaterialPropertyLib::createEmbeddedFracturePermeability(), MaterialPropertyLib::createExponential(), MaterialLib::Fluid::createFluidDensityModel(), MaterialPropertyLib::createFunction(), MaterialPropertyLib::createGasPressureDependentPermeability(), MaterialPropertyLib::createIdealGasLaw(), MaterialPropertyLib::createLinear(), MaterialPropertyLib::createLinearSaturationSwellingStress(), MaterialPropertyLib::createLinearWaterVapourLatentHeat(), MaterialPropertyLib::createOrthotropicEmbeddedFracturePermeability(), 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::createRelPermBrooksCoreyNonwettingPhase(), MaterialPropertyLib::createRelPermLiakopoulos(), MaterialPropertyLib::createRelPermNonWettingPhaseVanGenuchtenMualem(), MaterialPropertyLib::createRelPermUdell(), MaterialPropertyLib::createRelPermUdellNonwettingPhase(), MaterialPropertyLib::createRelPermVanGenuchten(), MaterialPropertyLib::createSaturationBrooksCorey(), MaterialPropertyLib::createSaturationDependentSwelling(), MaterialPropertyLib::createSaturationDependentThermalConductivity(), MaterialPropertyLib::createSaturationExponential(), MaterialPropertyLib::createSaturationLiakopoulos(), MaterialPropertyLib::createSaturationVanGenuchten(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), MaterialPropertyLib::createSoilThermalConductivitySomerton(), ProcessLib::createSourceTerm(), MaterialPropertyLib::createStrainDependentPermeability(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), NumLib::createTimeStepper(), MaterialPropertyLib::createTransportPorosityFromMassBalance(), MaterialPropertyLib::createVapourDiffusionFEBEX(), MaterialPropertyLib::createVapourDiffusionPMQ(), MaterialLib::Fluid::createViscosityModel(), ProcessLib::createVolumetricSourceTerm(), MaterialPropertyLib::createWaterVapourDensity(), and MaterialPropertyLib::createWaterVapourLatentHeatWithCriticalTemperature().

◆ shortString()

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

returns a short string at suitable for error/warning messages

Definition at line 257 of file ConfigTree.cpp.

258 {
259  const std::size_t maxlen = 100;
260 
261  if (s.size() < maxlen)
262  {
263  return s;
264  }
265 
266  return s.substr(0, maxlen - 3) + "...";
267 }

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 220 of file ConfigTree.cpp.

221 {
222  onwarning_(filename_, path_, message);
223 }

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 470 of file ConfigTree.cpp.

471 {
472  conf.checkAndInvalidate();
473 }

◆ checkAndInvalidate [2/3]

void checkAndInvalidate ( ConfigTree *const  conf)
friend

Check if conf has been read entirely and invalidate it.

This method can safely be called on nullptr's.

See also
ConfigTree::checkAndInvalidate()

Definition at line 475 of file ConfigTree.cpp.

476 {
477  if (conf)
478  {
479  conf->checkAndInvalidate();
480  }
481 }

◆ 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 483 of file ConfigTree.cpp.

484 {
485  if (conf)
486  {
487  conf->checkAndInvalidate();
488  }
489 }

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 616 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 631 of file ConfigTree.h.

Referenced by checkAndInvalidate(), getValue(), 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 643 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 640 of file ConfigTree.h.

Referenced by checkKeyname().

◆ onerror_

Callback BaseLib::ConfigTree::onerror_
private

Custom error callback.

Definition at line 633 of file ConfigTree.h.

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

◆ onwarning_

Callback BaseLib::ConfigTree::onwarning_
private

Custom warning callback.

Definition at line 634 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 613 of file ConfigTree.h.

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

◆ pathseparator

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

Character separating two path components.

Definition at line 637 of file ConfigTree.h.

Referenced by joinPaths().

◆ 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 628 of file ConfigTree.h.

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


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