OGS
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 100 of file ConfigTree.h.

#include <ConfigTree.h>

Classes

class  Child
struct  CountType
class  ParameterIterator
class  SubtreeIterator
class  ValueIterator

Public Types

using PTree = boost::property_tree::ptree
 The tree being wrapped by this class.
using Callback

Public Member Functions

 ConfigTree (PTree &&top_level_tree, std::string filename, Callback error_cb, Callback warning_cb)
 ConfigTree (ConfigTree const &)=delete
 copying is not compatible with the semantics of this class
 ConfigTree (ConfigTree &&other)
ConfigTreeoperator= (ConfigTree const &)=delete
 copying is not compatible with the semantics of this class
ConfigTreeoperator= (ConfigTree &&other)
std::filesystem::path const & projectFilePath () const
 Used to get the project file name.
std::filesystem::path projectDirectory () const
 ~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 &param) const
std::optional< ConfigTreegetConfigParameterOptional (std::string const &param) 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
void checkConfigParameter (std::string const &param, std::string_view const value) 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.

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).

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.
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.
 ConfigTree (PTree const &tree, ConfigTree const &parent, std::string const &root)
 Used for wrapping a subtree.
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_].
std::string joinPaths (std::string const &p1, std::string const &p2) const
 Used to generate the path of a subtree.
void checkUnique (std::string const &key) const
 Asserts that the key has not been read yet.
void checkUniqueAttr (std::string const &attr) const
 Asserts that the attribute attr has not been read yet.
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.
void checkAndInvalidate ()

Static Private Member Functions

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

Private Attributes

std::shared_ptr< PTree const > top_level_tree_
PTree const * tree_
 The wrapped tree.
std::string path_
 A path printed in error/warning messages.
std::filesystem::path filepath_
 The path of the file from which this tree has been read.
std::map< KeyType, CountTypevisited_params_
bool have_read_data_ = false
Callback onerror_
 Custom error callback.
Callback onwarning_
 Custom warning callback.

Static Private Attributes

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

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.
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.

Methods for accessing subtrees

using Children = std::vector<std::pair<std::string, Child>>
 Return type of getAllChildren(): an owning vector of (tag, view) pairs.
ConfigTree getConfigSubtree (std::string const &root) const
std::optional< ConfigTreegetConfigSubtreeOptional (std::string const &root) const
Range< SubtreeIteratorgetConfigSubtreeList (std::string const &root) const
Children getAllChildren () const

Member Typedef Documentation

◆ Callback

Initial value:
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 258 of file ConfigTree.h.

◆ Children

using BaseLib::ConfigTree::Children = std::vector<std::pair<std::string, Child>>

Return type of getAllChildren(): an owning vector of (tag, view) pairs.

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

◆ PTree

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

The tree being wrapped by this class.

Definition at line 249 of file ConfigTree.h.

Member Enumeration Documentation

◆ Attr

enum class BaseLib::ConfigTree::Attr : bool
strongprivate

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

Enumerator
TAG 
ATTR 

Definition at line 582 of file ConfigTree.h.

583 {
584 TAG = false,
585 ATTR = true
586 };

Constructor & Destructor Documentation

◆ ConfigTree() [1/4]

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

Creates a new instance wrapping the given Boost Property Tree.

Parameters
top_level_treethe top level Boost Property Tree
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 29 of file ConfigTree.cpp.

33 : top_level_tree_(std::make_shared<PTree>(std::move(top_level_tree))),
35 onerror_(std::move(error_cb)),
36 onwarning_(std::move(warning_cb))
37{
38 if (!onerror_)
39 {
40 OGS_FATAL("ConfigTree: No valid error handler provided.");
41 }
42 if (!onwarning_)
43 {
44 OGS_FATAL("ConfigTree: No valid warning handler provided.");
45 }
46
47 std::filesystem::path const filepath{filename};
48 std::error_code ec;
49 auto absolute_filepath = absolute(filepath, ec);
50 if (ec)
51 {
52 DBUG(
53 "ConfigTree: could not get the absolute path of '{}'. Using the "
54 "path unmodified. Error code = {}",
55 filepath.string(), ec.value());
56 absolute_filepath = filepath;
57 }
58
59 // store absolute path s.t. we are safe if somebody changes the working
60 // directory
61 filepath_ = absolute_filepath;
62 DBUG("ConfigTree: file path is {}.", filepath_.string());
63
64 if (!exists(projectDirectory()))
65 {
66 DBUG("ConfigTree: The project directory '{}' does not exist.",
67 projectDirectory().string());
68 }
69}
#define OGS_FATAL(...)
Definition Error.h:10
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
Callback onwarning_
Custom warning callback.
Definition ConfigTree.h:684
std::shared_ptr< PTree const > top_level_tree_
Definition ConfigTree.h:656
std::filesystem::path projectDirectory() const
std::filesystem::path filepath_
The path of the file from which this tree has been read.
Definition ConfigTree.h:665
Callback onerror_
Custom error callback.
Definition ConfigTree.h:683
PTree const * tree_
The wrapped tree.
Definition ConfigTree.h:659

References DBUG(), filepath_, OGS_FATAL, onerror_, onwarning_, projectDirectory(), top_level_tree_, and tree_.

Referenced by ConfigTree(), ConfigTree(), ConfigTree(), BaseLib::ConfigTree::SubtreeIterator::SubtreeIterator(), BaseLib::ConfigTree::ValueIterator< ValueType >::ValueIterator(), checkAndInvalidate, checkAndInvalidate, getAllChildren(), getConfigParameter(), getConfigSubtree(), getConfigSubtreeOptional(), BaseLib::ConfigTree::ParameterIterator::operator*(), BaseLib::ConfigTree::SubtreeIterator::operator*(), BaseLib::ConfigTree::ValueIterator< ValueType >::operator*(), operator=(), and operator=().

◆ ConfigTree() [2/4]

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

copying is not compatible with the semantics of this class

References ConfigTree().

◆ ConfigTree() [3/4]

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

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

Definition at line 83 of file ConfigTree.cpp.

84 : top_level_tree_(std::move(other.top_level_tree_)),
85 tree_(other.tree_),
86 path_(std::move(other.path_)),
87 filepath_(std::move(other.filepath_)),
88 visited_params_(std::move(other.visited_params_)),
89 have_read_data_(other.have_read_data_),
90 onerror_(std::move(other.onerror_)),
91 onwarning_(std::move(other.onwarning_))
92{
93 other.tree_ = nullptr;
94}
std::map< KeyType, CountType > visited_params_
Definition ConfigTree.h:677
std::string path_
A path printed in error/warning messages.
Definition ConfigTree.h:662

References ConfigTree(), filepath_, have_read_data_, onerror_, onwarning_, path_, top_level_tree_, tree_, and visited_params_.

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

97{
98 if (std::uncaught_exceptions() > 0)
99 {
100 /* If the stack unwinds the check below shall be suppressed in order to
101 * not accumulate false-positive configuration errors.
102 */
103 return;
104 }
105
106 try
107 {
109 }
110 catch (std::exception& e)
111 {
112 ERR("{:s}", e.what());
113 configtree_destructor_error_messages.emplace_front(e.what());
114 }
115}
static std::forward_list< std::string > configtree_destructor_error_messages
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40

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

◆ ConfigTree() [4/4]

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

Used for wrapping a subtree.

Definition at line 71 of file ConfigTree.cpp.

73 : top_level_tree_(parent.top_level_tree_),
74 tree_(&tree),
75 path_(joinPaths(parent.path_, root)),
76 filepath_(parent.filepath_),
77 onerror_(parent.onerror_),
78 onwarning_(parent.onwarning_)
79{
80 checkKeyname(root);
81}
std::string joinPaths(std::string const &p1, std::string const &p2) const
Used to generate the path of a subtree.
void checkKeyname(std::string const &key) const
Checks if key complies with the rules [a-z0-9_].

References ConfigTree(), checkKeyname(), filepath_, joinPaths(), onerror_, onwarning_, path_, top_level_tree_, and tree_.

Member Function Documentation

◆ assertNoSwallowedErrors()

void BaseLib::ConfigTree::assertNoSwallowedErrors ( )
static

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

Definition at line 301 of file ConfigTree.cpp.

302{
304 {
305 return;
306 }
307
308 ERR("ConfigTree: There have been errors when parsing the configuration "
309 "file(s):");
310
311 for (auto const& msg : configtree_destructor_error_messages)
312 {
313 ERR("{:s}", msg);
314 }
315
316 // Clear the error messages to avoid duplicate printing
318
319 OGS_FATAL("There have been errors when parsing the configuration file(s).");
320}

References configtree_destructor_error_messages, ERR(), and OGS_FATAL.

Referenced by OGSSimulation::finalize(), Simulation::initializeDataStructures(), and 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 455 of file ConfigTree.cpp.

456{
457 if (!tree_)
458 {
459 return;
460 }
461
462 // Note: due to a limitation in boost::property_tree it is not possible
463 // to discriminate between <tag></tag> and <tag/> in the input file.
464 // In both cases data() will be empty.
465 if ((!have_read_data_) && !tree_->data().empty())
466 {
467 warning("The immediate data `" + shortString(tree_->data()) +
468 "' of this tag has not been read.");
469 }
470
471 // iterate over children
472 for (auto const& p : *tree_)
473 {
474 if (p.first != "<xmlattr>")
475 { // attributes are handled below
477 }
478 }
479
480 // iterate over attributes
481 if (auto attrs = tree_->get_child_optional("<xmlattr>"))
482 {
483 for (auto const& p : *attrs)
484 {
486 }
487 }
488
489 for (auto const& p : visited_params_)
490 {
491 auto const& tag = p.first.second;
492 auto const& count = p.second.count;
493
494 switch (p.first.first)
495 {
496 case Attr::ATTR:
497 if (count > 0)
498 {
499 warning("XML attribute '" + tag + "' has been read " +
500 std::to_string(count) +
501 " time(s) more than it was present in the "
502 "configuration tree.");
503 }
504 else if (count < 0)
505 {
506 warning("XML attribute '" + tag + "' has been read " +
507 std::to_string(-count) +
508 " time(s) less than it was present in the "
509 "configuration tree.");
510 }
511 break;
512 case Attr::TAG:
513 if (count > 0)
514 {
515 warning("Key <" + tag + "> has been read " +
516 std::to_string(count) +
517 " time(s) more than it was present in the "
518 "configuration tree.");
519 }
520 else if (count < 0)
521 {
522 warning("Key <" + tag + "> has been read " +
523 std::to_string(-count) +
524 " time(s) less than it was present in the "
525 "configuration tree.");
526 }
527 }
528 }
529
530 // The following invalidates this instance, s.t. it can not be read from it
531 // anymore, but it also prevents double-checking.
532 tree_ = nullptr;
533}
void markVisitedDecrement(Attr const is_attr, std::string const &key) const
static std::string shortString(std::string const &s)
returns a short string at suitable for error/warning messages
void warning(std::string const &message) const

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

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

◆ checkConfigParameter()

void BaseLib::ConfigTree::checkConfigParameter ( std::string const & param,
std::string_view const value ) const

Assert that param has the given value.

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

Definition at line 167 of file ConfigTree.cpp.

169{
170 auto const parameter_value = getConfigParameter<std::string>(param);
171 if (parameter_value != value)
172 {
173 error("For the tag <" + param + "> expected to read value '" +
174 value.data() + "', but got '" + parameter_value + "'.");
175 }
176}
void error(std::string const &message) const
T getConfigParameter(std::string const &param) const

References error(), and getConfigParameter().

Referenced by ProcessLib::createAnchorTerm(), MaterialPropertyLib::createAverageMolarMass(), MaterialPropertyLib::createBishopsPowerLaw(), MaterialPropertyLib::createBishopsSaturationCutoff(), MaterialPropertyLib::createCapillaryPressureRegularizedVanGenuchten(), MaterialPropertyLib::createCapillaryPressureVanGenuchten(), ProcessLib::createCentralDifferencesJacobianAssembler(), MaterialPropertyLib::createClausiusClapeyron(), MaterialLib::Fracture::CohesiveZoneModeI::createCohesiveZoneModeI(), ProcessLib::createCompareJacobiansJacobianAssembler(), ProcessLib::ComponentTransport::createComponentTransportProcess(), MaterialPropertyLib::createConstant(), ParameterLib::createConstantParameter(), NumLib::createConvergenceCriterionDeltaX(), NumLib::createConvergenceCriterionPerComponentDeltaX(), NumLib::createConvergenceCriterionPerComponentResidual(), NumLib::createConvergenceCriterionResidual(), MaterialLib::Fracture::createCoulomb(), MaterialLib::Solids::Creep::createCreepBGRa(), MaterialPropertyLib::createCubicLawPermeability(), MaterialPropertyLib::createCurve(), ParameterLib::createCurveScaledParameter(), MaterialPropertyLib::createDupuitPermeability(), MaterialPropertyLib::createEffectiveThermalConductivityPorosityMixing(), MaterialLib::Solids::Ehlers::createEhlers(), ProcessLib::createEmbeddedAnchor(), MaterialPropertyLib::createEmbeddedFracturePermeability(), MaterialPropertyLib::createExponential(), ProcessLib::createForwardDifferencesJacobianAssembler(), MaterialPropertyLib::createFunction(), ParameterLib::createFunctionParameter(), MaterialPropertyLib::createGasPressureDependentPermeability(), ParameterLib::createGroupBasedParameter(), ProcessLib::HeatConduction::createHeatConductionProcess(), ProcessLib::HeatTransportBHE::createHeatTransportBHEProcess(), ProcessLib::HMPhaseField::createHMPhaseFieldProcess(), ProcessLib::HT::createHTProcess(), ProcessLib::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), MaterialPropertyLib::createIdealGasLaw(), MaterialPropertyLib::createIdealGasLawBinaryMixture(), MaterialPropertyLib::createKozenyCarmanModel(), ProcessLib::LargeDeformation::createLargeDeformationProcess(), MaterialPropertyLib::createLinear(), MaterialLib::Fracture::createLinearElasticIsotropic(), MaterialLib::Solids::createLinearElasticIsotropic(), MaterialLib::Solids::createLinearElasticIsotropicSoftening(), MaterialLib::Solids::createLinearElasticOrthotropic(), MaterialLib::Solids::createLinearElasticTransverseIsotropic(), MaterialPropertyLib::createLinearSaturationSwellingStress(), MaterialPropertyLib::createLinearWaterVapourLatentHeat(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), MaterialPropertyLib::createLiquidViscosityVogels(), MaterialLib::Solids::Lubby2::createLubby2(), ParameterLib::createMeshElementParameter(), ParameterLib::createMeshNodeParameter(), MaterialLib::Solids::MFront::createMFrontConfig(), ProcessLib::createNodalSourceTerm(), MaterialPropertyLib::createOrthotropicEmbeddedFracturePermeability(), MaterialPropertyLib::createParameterProperty(), MaterialPropertyLib::createPengRobinson(), MaterialPropertyLib::createPermeabilityMohrCoulombFailureIndexModel(), MaterialPropertyLib::createPermeabilityOrthotropicPowerLaw(), ProcessLib::PhaseField::createPhaseFieldProcess(), MaterialPropertyLib::createPorosityFromMassBalance(), ProcessLib::createPythonSourceTerm(), ParameterLib::createRandomFieldMeshElementParameter(), ParameterLib::createRasterParameter(), MaterialPropertyLib::createRelPermBrooksCorey(), MaterialPropertyLib::createRelPermBrooksCoreyNonwettingPhase(), MaterialPropertyLib::createRelPermGeneralizedPower(), MaterialPropertyLib::createRelPermGeneralizedPowerNonwettingPhase(), MaterialPropertyLib::createRelPermLiakopoulos(), MaterialPropertyLib::createRelPermNonWettingPhaseVanGenuchtenMualem(), MaterialPropertyLib::createRelPermUdell(), MaterialPropertyLib::createRelPermUdellNonwettingPhase(), MaterialPropertyLib::createRelPermVanGenuchten(), ProcessLib::RichardsComponentTransport::createRichardsComponentTransportProcess(), ProcessLib::RichardsFlow::createRichardsFlowProcess(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), MaterialPropertyLib::createSaturationBrooksCorey(), MaterialPropertyLib::createSaturationDependentSwelling(), MaterialPropertyLib::createSaturationDependentThermalConductivity(), MaterialPropertyLib::createSaturationExponential(), MaterialPropertyLib::createSaturationLiakopoulos(), MaterialPropertyLib::createSaturationLuMcCartney(), MaterialPropertyLib::createSaturationVanGenuchten(), MaterialPropertyLib::createSaturationVanGenuchtenWithVolumetricStrain(), MaterialPropertyLib::createSaturationWeightedThermalConductivity(), MaterialPropertyLib::createSigmoid(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::SmallDeformation::createSmallDeformationProcess(), MaterialPropertyLib::createSoilThermalConductivitySomerton(), MaterialPropertyLib::createSpecificHeatCapacityWithLatentHeat(), ProcessLib::SteadyStateDiffusion::createSteadyStateDiffusion(), MaterialPropertyLib::createStrainDependentPermeability(), MaterialPropertyLib::createTemperatureDependentDiffusion(), ProcessLib::TH2M::createTH2MProcess(), ProcessLib::ThermalTwoPhaseFlowWithPP::createThermalTwoPhaseFlowWithPPProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), ProcessLib::ThermoRichardsFlow::createThermoRichardsFlowProcess(), ProcessLib::ThermoRichardsMechanics::createThermoRichardsMechanicsProcess(), MaterialPropertyLib::createTransportPorosityFromMassBalance(), ProcessLib::TwoPhaseFlowWithPP::createTwoPhaseFlowWithPPProcess(), MaterialPropertyLib::createVapourDiffusionDeVries(), MaterialPropertyLib::createVapourDiffusionFEBEX(), MaterialPropertyLib::createVapourDiffusionPMQ(), MaterialPropertyLib::createVermaPruessModel(), MaterialPropertyLib::createVolumeFractionAverage(), ProcessLib::createVolumetricSourceTerm(), MaterialPropertyLib::createWaterDensityIAPWSIF97Region1(), MaterialPropertyLib::createWaterEnthalpyIAPWSIF97Region1(), MaterialPropertyLib::createWaterLiquidDensityIAPWSIF97Region4(), MaterialPropertyLib::createWaterLiquidEnthalpyIAPWSIF97Region4(), MaterialPropertyLib::createWaterSaturationTemperatureIAPWSIF97Region4(), MaterialPropertyLib::createWaterTemperatureIAPWSIF97Region1(), MaterialPropertyLib::createWaterThermalConductivityIAPWS(), MaterialPropertyLib::createWaterVapourDensity(), MaterialPropertyLib::createWaterVapourDensityIAPWSIF97Region4(), MaterialPropertyLib::createWaterVapourEnthalpyIAPWSIF97Region4(), MaterialPropertyLib::createWaterVapourLatentHeatWithCriticalTemperature(), MaterialPropertyLib::createWaterViscosityIAPWS(), ProcessLib::WellboreSimulator::createWellboreSimulatorProcess(), ProcessLib::parseConstraintDirichletBoundaryCondition(), ProcessLib::parseDirichletBCConfig(), ProcessLib::parseDirichletBoundaryConditionWithinTimeIntervalConfig(), NumLib::parseEvolutionaryPIDcontroller(), NumLib::parseFixedTimeStepping(), ProcessLib::parseHCNonAdvectiveFreeComponentFlowBoundaryCondition(), NumLib::parseIterationNumberBasedTimeStepping(), ProcessLib::parseNeumannBoundaryCondition(), ProcessLib::NormalTractionBoundaryCondition::parseNormalTractionBoundaryCondition(), ProcessLib::parsePhaseFieldIrreversibleDamageOracleBoundaryCondition(), ProcessLib::parsePrimaryVariableConstraintDirichletBoundaryCondition(), ProcessLib::parsePythonBoundaryCondition(), ProcessLib::parseReleaseNodalForce(), ProcessLib::parseRobinBoundaryCondition(), ProcessLib::parseSolutionDependentDirichletBoundaryCondition(), ProcessLib::parseTimeDecayDirichletBoundaryConditionConfig(), ProcessLib::parseVariableDependentNeumannBoundaryCondition(), and ProcessLib::parseWellboreCompensateNeumannBoundaryCondition().

◆ checkKeyname()

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

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

Definition at line 334 of file ConfigTree.cpp.

335{
336 if (key.empty())
337 {
338 error("Search for empty key.");
339 }
340 else if (key_chars_start.find(key.front()) == std::string::npos)
341 {
342 error("Key <" + key + "> starts with an illegal character.");
343 }
344 else if (key.find_first_not_of(key_chars, 1) != std::string::npos)
345 {
346 error("Key <" + key + "> contains illegal characters.");
347 }
348 else if (key.find("__") != std::string::npos)
349 {
350 // This is illegal because we use parameter names to generate doxygen
351 // page names. Thereby "__" acts as a separator character. Choosing
352 // other separators is not possible because of observed limitations
353 // for valid doxygen page names.
354 error("Key <" + key + "> contains double underscore.");
355 }
356}
static const std::string key_chars_start
Set of allowed characters as the first letter of a key name.
Definition ConfigTree.h:690
static const std::string key_chars
Set of allowed characters in a key name.
Definition ConfigTree.h:693

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

375{
376 checkKeyname(key);
377
378 if (visited_params_.find({Attr::TAG, key}) != visited_params_.end())
379 {
380 error("Key <" + key + "> has already been processed.");
381 }
382}

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

385{
386 // Workaround for handling attributes with xml namespaces and uppercase
387 // letters.
388 if (attr.find(':') != std::string::npos)
389 {
390 auto pos = decltype(std::string::npos){0};
391
392 // Replace colon and uppercase letters with an allowed character 'a'.
393 // That means, attributes containing a colon are also allowed to contain
394 // uppercase letters.
395 auto attr2 = attr;
396 do
397 {
398 pos = attr2.find_first_of(":ABCDEFGHIJKLMNOPQRSTUVWXYZ", pos);
399 if (pos != std::string::npos)
400 {
401 attr2[pos] = 'a';
402 }
403 } while (pos != std::string::npos);
404
405 checkKeyname(attr2);
406 }
407 else
408 {
409 checkKeyname(attr);
410 }
411
412 if (visited_params_.find({Attr::ATTR, attr}) != visited_params_.end())
413 {
414 error("Attribute '" + attr + "' has already been processed.");
415 }
416}

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

275{
276 onerror_(filepath_.string(), path_, message);
277 OGS_FATAL(
278 "ConfigTree: The error handler does not break out of the normal "
279 "control flow.");
280}

References filepath_, OGS_FATAL, onerror_, and path_.

Referenced by checkConfigParameter(), checkKeyname(), checkUnique(), checkUniqueAttr(), getConfigAttribute(), getConfigAttributeOptional(), getConfigParameter(), getConfigParameterOptional(), getConfigParameterOptionalImpl(), getConfigSubtree(), getValue(), joinPaths(), markVisited(), and peekConfigParameter().

◆ getAllChildren()

ConfigTree::Children BaseLib::ConfigTree::getAllChildren ( ) const

Get all children of this ConfigTree.

Returns a vector of (tag, subtree) pairs for all children (subtrees and parameters) in the order they appear in the configuration tree. The return value is suitable for range-based for-loops and random access.

Definition at line 213 of file ConfigTree.cpp.

214{
215 Children children;
216
217 // Hand out every child as its own subtree, mirroring getConfigSubtree():
218 // mark each child tag as consumed in this (parent) tree so the parent does
219 // not warn about the tags, then return a ConfigTree per child. Each child
220 // validates its own content on destruction, so any child whose sub-children
221 // / attributes / immediate data are left unread warns exactly like an
222 // unread getConfigSubtree() result. <xmlattr> is skipped: attribute
223 // storage is not a child element. Duplicate tags are handled by
224 // markVisited(), which increments the consumed count once per occurrence.
225 for (auto const& [tag, subtree] : *tree_)
226 {
227 if (tag == "<xmlattr>")
228 {
229 continue;
230 }
231 markVisited(tag, Attr::TAG, false);
232 children.emplace_back(tag, Child{ConfigTree(subtree, *this, tag)});
233 }
234
235 return children;
236}
CountType & markVisited(std::string const &key, Attr const is_attr, bool peek_only) const
std::vector< std::pair< std::string, Child > > Children
Return type of getAllChildren(): an owning vector of (tag, view) pairs.
Definition ConfigTree.h:503
ConfigTree(PTree &&top_level_tree, std::string filename, Callback error_cb, Callback warning_cb)

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

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

236{
237 if (auto a = getConfigAttributeOptional<T>(attr))
238 {
239 return *a;
240 }
241
242 error("Did not find XML attribute with name '" + attr + "'.");
243}
std::optional< T > getConfigAttributeOptional(std::string const &attr) const

References error(), and getConfigAttributeOptional().

Referenced by ParameterLib::confirmThirdBaseExplicit(), ChemistryLib::PhreeqcIOData::createAqueousSolution(), and ParameterLib::createCoordinateSystemWithImplicitBase().

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

248{
249 if (auto a = getConfigAttributeOptional<T>(attr))
250 {
251 return *a;
252 }
253
254 return default_value;
255}

References getConfigAttributeOptional().

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

260{
261 checkUniqueAttr(attr);
262 auto& ct = markVisited<T>(attr, Attr::ATTR, true);
263
264 if (auto attrs = tree_->get_child_optional("<xmlattr>"))
265 {
266 if (auto a = attrs->get_child_optional(attr))
267 {
268 ++ct.count; // count only if attribute has been found
269 if (auto v = a->get_value_optional<T>())
270 {
271 return std::make_optional(*v);
272 }
273 error("Value for XML attribute '" + attr + "' `" +
274 shortString(a->data()) +
275 "' not convertible to the desired type.");
276 }
277 }
278
279 return std::nullopt;
280}
void checkUniqueAttr(std::string const &attr) const
Asserts that the attribute attr has not been read yet.

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

Referenced by getConfigAttribute(), getConfigAttribute(), parseOutputMeshConfig(), 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 113 of file ConfigTree-impl.h.

114{
115 if (auto p = getConfigParameterOptional<T>(param))
116 {
117 return *p;
118 }
119
120 error("Key <" + param + "> has not been found");
121}
std::optional< T > getConfigParameterOptional(std::string const &param) const

References error(), and getConfigParameterOptional().

Referenced by checkConfigParameter(), ProcessLib::createAnchorTerm(), ChemistryLib::PhreeqcIOData::createAqueousSolution(), ChemistryLib::PhreeqcKernelData::createAqueousSolution(), MaterialPropertyLib::createBishopsPowerLaw(), MaterialPropertyLib::createBishopsSaturationCutoff(), ProcessLib::HeatTransportBHE::BHE::createBoreholeGeometry(), MaterialPropertyLib::createCapillaryPressureRegularizedVanGenuchten(), MaterialPropertyLib::createCapillaryPressureVanGenuchten(), ProcessLib::createCentralDifferencesJacobianAssembler(), ChemistryLib::createChemicalSolverInterface< ChemicalSolver::Phreeqc >(), MaterialPropertyLib::createClausiusClapeyron(), MaterialLib::Fracture::CohesiveZoneModeI::createCohesiveZoneModeI(), ProcessLib::createCompareJacobiansJacobianAssembler(), anonymous_namespace{CreateComponent.cpp}::createComponent(), ProcessLib::ComponentTransport::createComponentTransportProcess(), NumLib::createConvergenceCriterionDeltaX(), NumLib::createConvergenceCriterionPerComponentDeltaX(), NumLib::createConvergenceCriterionPerComponentResidual(), NumLib::createConvergenceCriterionResidual(), MaterialLib::Fracture::createCoulomb(), MaterialPropertyLib::createCubicLawPermeability(), MaterialPropertyLib::createCurve(), ParameterLib::createCurveScaledParameter(), ProcessLib::createDeactivatedSubdomain(), MaterialPropertyLib::createDupuitPermeability(), MaterialLib::Solids::Ehlers::createEhlers(), MaterialPropertyLib::createEmbeddedFracturePermeability(), MaterialPropertyLib::createExponential(), ProcessLib::HeatTransportBHE::BHE::createFlowAndTemperatureControl(), ProcessLib::createForwardDifferencesJacobianAssembler(), MaterialPropertyLib::createGasPressureDependentPermeability(), ParameterLib::createGroupBasedParameter(), ProcessLib::HeatTransportBHE::BHE::createGroutParameters(), ProcessLib::HeatConduction::createHeatConductionProcess(), ProcessLib::HeatTransportBHE::createHeatTransportBHEProcess(), ProcessLib::HMPhaseField::createHMPhaseFieldProcess(), ProcessLib::HT::createHTProcess(), ProcessLib::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ChemistryLib::PhreeqcIOData::createKnobs(), MaterialPropertyLib::createKozenyCarmanModel(), ProcessLib::LargeDeformation::createLargeDeformationProcess(), MaterialPropertyLib::createLinear(), MaterialLib::Fracture::createLinearElasticIsotropic(), MaterialPropertyLib::createLinearSaturationSwellingStress(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), ParameterLib::createMeshElementParameter(), ParameterLib::createMeshNodeParameter(), MaterialLib::Solids::MFront::createMFrontConfig(), NumLib::createNewtonRaphsonSolverParameters(), ProcessLib::createNodalSourceTerm(), NumLib::createNonlinearSolver(), MaterialPropertyLib::createOrthotropicEmbeddedFracturePermeability(), ProcessLib::createOutputConfig(), ParameterLib::createParameter(), MaterialPropertyLib::createParameterProperty(), MaterialPropertyLib::createPengRobinson(), MaterialPropertyLib::createPermeabilityMohrCoulombFailureIndexModel(), MaterialPropertyLib::createPermeabilityOrthotropicPowerLaw(), anonymous_namespace{CreatePhase.cpp}::createPhase(), ProcessLib::PhaseField::createPhaseFieldProcess(), ProcessLib::HeatTransportBHE::BHE::createPipe(), MaterialPropertyLib::createPorosityFromMassBalance(), ProcessLib::createPythonSourceTerm(), ParameterLib::createRandomFieldMeshElementParameter(), ProcessLib::HeatTransportBHE::BHE::createRefrigerantProperties(), MaterialPropertyLib::createRelPermBrooksCorey(), MaterialPropertyLib::createRelPermBrooksCoreyNonwettingPhase(), MaterialPropertyLib::createRelPermGeneralizedPower(), MaterialPropertyLib::createRelPermGeneralizedPowerNonwettingPhase(), MaterialPropertyLib::createRelPermNonWettingPhaseVanGenuchtenMualem(), MaterialPropertyLib::createRelPermUdell(), MaterialPropertyLib::createRelPermUdellNonwettingPhase(), MaterialPropertyLib::createRelPermVanGenuchten(), ProcessLib::WellboreSimulator::createReservoirProperties(), ProcessLib::RichardsComponentTransport::createRichardsComponentTransportProcess(), ProcessLib::RichardsFlow::createRichardsFlowProcess(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), MaterialPropertyLib::createSaturationBrooksCorey(), MaterialPropertyLib::createSaturationDependentSwelling(), MaterialPropertyLib::createSaturationExponential(), MaterialPropertyLib::createSaturationLuMcCartney(), MaterialPropertyLib::createSaturationVanGenuchten(), MaterialPropertyLib::createSaturationVanGenuchtenWithVolumetricStrain(), MaterialPropertyLib::createSaturationWeightedThermalConductivity(), MaterialPropertyLib::createSigmoid(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::SmallDeformation::createSmallDeformationProcess(), MaterialPropertyLib::createSpecificHeatCapacityWithLatentHeat(), MaterialPropertyLib::createStrainDependentPermeability(), ProcessLib::SurfaceFluxData::createSurfaceFluxData(), MaterialPropertyLib::createTemperatureDependentDiffusion(), ProcessLib::TH2M::createTH2MProcess(), ProcessLib::ThermalTwoPhaseFlowWithPP::createThermalTwoPhaseFlowWithPPProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), ProcessLib::ThermoRichardsFlow::createThermoRichardsFlowProcess(), ProcessLib::ThermoRichardsMechanics::createThermoRichardsMechanicsProcess(), ProcessLib::ThermoRichardsMechanics::createThermoRichardsMechanicsProcessStage2(), ParameterLib::createTimeDependentHeterogeneousParameter(), NumLib::createTimeDiscretization(), NumLib::createTimeInterval(), MaterialPropertyLib::createTransportPorosityFromMassBalance(), ProcessLib::TwoPhaseFlowWithPP::createTwoPhaseFlowWithPPProcess(), MaterialPropertyLib::createVapourDiffusionDeVries(), MaterialPropertyLib::createVapourDiffusionFEBEX(), MaterialPropertyLib::createVapourDiffusionPMQ(), MaterialPropertyLib::createVermaPruessModel(), ProcessLib::createVolumetricSourceTerm(), ProcessLib::WellboreSimulator::createWellboreGeometry(), ProcessLib::WellboreSimulator::createWellboreSimulatorProcess(), anonymous_namespace{ProcessVariable.cpp}::findMeshInConfig(), ParameterLib::findParameter(), ProcessLib::findProcessVariable(), ProcessLib::parseBall(), ProcessLib::HeatTransportBHE::BHE::parseBHE1PTypeConfig(), ProcessLib::HeatTransportBHE::BHE::parseBHECoaxialConfig(), ProcessLib::HeatTransportBHE::BHE::parseBHEUTypeConfig(), ProcessLib::parseConstraintDirichletBoundaryCondition(), ProcessLib::parseDirichletBCConfig(), ProcessLib::parseDirichletBoundaryConditionWithinTimeIntervalConfig(), NumLib::parseEvolutionaryPIDcontroller(), NumLib::parseFixedTimeStepping(), ProcessLib::parseHCNonAdvectiveFreeComponentFlowBoundaryCondition(), NumLib::parseIterationNumberBasedTimeStepping(), ProcessLib::parseLineSegment(), ProcessLib::parseNeumannBoundaryCondition(), ProcessLib::NormalTractionBoundaryCondition::parseNormalTractionBoundaryCondition(), MathLib::parsePiecewiseLinearCurveConfig(), ProcessLib::parsePrimaryVariableConstraintDirichletBoundaryCondition(), ProcessLib::parsePythonBoundaryCondition(), ProcessLib::parseRobinBoundaryCondition(), ProcessLib::parseSolutionDependentDirichletBoundaryCondition(), ProcessLib::parseTimeDecayDirichletBoundaryConditionConfig(), ProcessLib::parseVariableDependentNeumannBoundaryCondition(), ProcessLib::parseWellboreCompensateNeumannBoundaryCondition(), anonymous_namespace{ProjectData.cpp}::readMeshes(), and GeoLib::IO::readRaster().

◆ getConfigParameter() [2/3]

ConfigTree BaseLib::ConfigTree::getConfigParameter ( std::string const & param) 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 134 of file ConfigTree.cpp.

135{
136 auto ct = getConfigSubtree(param);
137 if (ct.hasChildren())
138 {
139 error("Requested parameter <" + param + "> actually is a subtree.");
140 }
141 return ct;
142}
ConfigTree getConfigSubtree(std::string const &root) const

References ConfigTree(), error(), and getConfigSubtree().

◆ getConfigParameter() [3/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 124 of file ConfigTree-impl.h.

126{
127 if (auto p = getConfigParameterOptional<T>(param))
128 {
129 return *p;
130 }
131
132 return default_value;
133}

References getConfigParameterOptional().

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

184{
185 checkUnique(param);
186 markVisited<T>(param, Attr::TAG, true);
187
188 auto p = tree_->equal_range(param);
189 return Range<ValueIterator<T>>(ValueIterator<T>(p.first, param, *this),
190 ValueIterator<T>(p.second, param, *this));
191}
void checkUnique(std::string const &key) const
Asserts that the key has not been read yet.

References checkUnique(), markVisited(), 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 155 of file ConfigTree.cpp.

157{
158 checkUnique(param);
159 markVisited(param, Attr::TAG, true);
160
161 auto p = tree_->equal_range(param);
162
163 return Range<ParameterIterator>(ParameterIterator(p.first, param, *this),
164 ParameterIterator(p.second, param, *this));
165}

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

138{
139 checkUnique(param);
140
141 return getConfigParameterOptionalImpl(param, static_cast<T*>(nullptr));
142}
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 ProjectData::ProjectData(), ProcessLib::createCentralDifferencesJacobianAssembler(), ChemistryLib::createChargeBalance(), ProcessLib::ComponentTransport::createComponentTransportProcess(), MaterialPropertyLib::createConstant(), ParameterLib::createConstantParameter(), NumLib::createConvergenceCriterionDeltaX(), NumLib::createConvergenceCriterionPerComponentDeltaX(), NumLib::createConvergenceCriterionPerComponentResidual(), NumLib::createConvergenceCriterionResidual(), ProcessLib::createDeactivatedSubdomain(), ProcessLib::ThermoRichardsFlow::createElasticityModel(), MaterialPropertyLib::createEmbeddedFracturePermeability(), ProcessLib::createForwardDifferencesJacobianAssembler(), ProcessLib::HMPhaseField::createHMPhaseFieldProcess(), ProcessLib::HT::createHTProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), NumLib::createNewtonRaphsonSolverParameters(), NumLib::createNonlinearSolver(), ProcessLib::PhaseField::createPhaseFieldProcess(), ProcessLib::RichardsComponentTransport::createRichardsComponentTransportProcess(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), MaterialPropertyLib::createSaturationVanGenuchten(), ProcessLib::SmallDeformation::createSmallDeformationProcess(), ProcessLib::TH2M::createTH2MProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), ProcessLib::ThermoRichardsFlow::createThermoRichardsFlowProcess(), ProcessLib::ThermoRichardsMechanics::createThermoRichardsMechanicsProcessStage2(), anonymous_namespace{ProcessVariable.cpp}::findMeshInConfig(), ParameterLib::findOptionalTagParameter(), getConfigParameter(), getConfigParameter(), NumLib::parseFixedTimeStepping(), MathLib::LinearSolverOptionsParser< EigenLisLinearSolver >::parseNameAndOptions(), ProcessLib::parseNeumannBoundaryCondition(), ProcessLib::parseRobinBoundaryCondition(), and anonymous_namespace{ProjectData.cpp}::readMeshes().

◆ getConfigParameterOptional() [2/2]

std::optional< ConfigTree > BaseLib::ConfigTree::getConfigParameterOptional ( std::string const & param) 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 144 of file ConfigTree.cpp.

146{
147 auto ct = getConfigSubtreeOptional(param);
148 if (ct && ct->hasChildren())
149 {
150 error("Requested parameter <" + param + "> actually is a subtree.");
151 }
152 return ct;
153}
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const

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

159{
160 if (auto p = getConfigSubtreeOptional(param))
161 {
162 std::string const raw = p->getValue<std::string>();
163
164 std::size_t bad_idx = 0;
165 if (auto parsed = BaseLib::tryParseVector<T>(raw, &bad_idx))
166 {
167 return parsed; // OK
168 }
169
170 // preserve original error wording & token index
171 error("Value for key <" + param + "> `" + shortString(raw) +
172 "' not convertible to a vector of the desired type."
173 " Could not convert token no. " +
174 std::to_string(bad_idx) + ".");
175 return std::nullopt; // not reached
176 }
177
178 return std::nullopt;
179}
std::optional< std::vector< T > > tryParseVector(std::string const &raw, std::size_t *bad_token_idx)
Definition StringTools.h:86

References error(), getConfigSubtreeOptional(), shortString(), and BaseLib::tryParseVector().

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

147{
148 if (auto p = getConfigSubtreeOptional(param))
149 {
150 return p->getValue<T>();
151 }
152
153 return std::nullopt;
154}

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

179{
180 if (auto t = getConfigSubtreeOptional(root))
181 {
182 return std::move(*t);
183 }
184 error("Key <" + root + "> has not been found.");
185}

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

Referenced by ChemistryLib::PhreeqcIOData::createChemicalSystem(), ProcessLib::createCompareJacobiansJacobianAssembler(), ProcessLib::ComponentTransport::createComponentTransportProcess(), ParameterLib::createCoordinateSystemWithImplicitBase(), MaterialLib::Fracture::createCoulomb(), MaterialLib::Solids::Creep::createCreepBGRa(), MaterialLib::Solids::Ehlers::createEhlers(), MaterialPropertyLib::createExponential(), MaterialPropertyLib::createFunction(), ProcessLib::HeatConduction::createHeatConductionProcess(), ProcessLib::HeatTransportBHE::createHeatTransportBHEProcess(), ProcessLib::HMPhaseField::createHMPhaseFieldProcess(), ProcessLib::HT::createHTProcess(), ProcessLib::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ChemistryLib::PhreeqcKernelData::createInitialAqueousSolution(), ProcessLib::LargeDeformation::createLargeDeformationProcess(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), MaterialLib::Solids::Lubby2::createLubby2(), ProcessLib::createOutputConfig(), ProcessLib::PhaseField::createPhaseFieldProcess(), ProcessLib::RichardsComponentTransport::createRichardsComponentTransportProcess(), ProcessLib::RichardsFlow::createRichardsFlowProcess(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::SmallDeformation::createSmallDeformationProcess(), ChemistryLib::PhreeqcIOData::createSolutionComponents(), ProcessLib::SteadyStateDiffusion::createSteadyStateDiffusion(), ProcessLib::TH2M::createTH2MProcess(), ProcessLib::ThermalTwoPhaseFlowWithPP::createThermalTwoPhaseFlowWithPPProcess(), ProcessLib::ThermoHydroMechanics::createThermoHydroMechanicsProcess(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), ProcessLib::ThermoRichardsFlow::createThermoRichardsFlowProcess(), ProcessLib::ThermoRichardsMechanics::createThermoRichardsMechanicsProcessStage2(), ParameterLib::createTimeDependentHeterogeneousParameter(), NumLib::createTimeInterval(), ProcessLib::createTimeLoop(), ProcessLib::TwoPhaseFlowWithPP::createTwoPhaseFlowWithPPProcess(), ProcessLib::WellboreSimulator::createWellboreSimulatorProcess(), getConfigParameter(), ProcessLib::HeatTransportBHE::BHE::parseBHE1PTypeConfig(), ProcessLib::HeatTransportBHE::BHE::parseBHECoaxialConfig(), ProcessLib::HeatTransportBHE::BHE::parseBHEUTypeConfig(), NumLib::parseFixedTimeStepping(), and anonymous_namespace{CreateMFrontGeneric.cpp}::readMaterialProperties().

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

203{
204 checkUnique(root);
205 markVisited(root, Attr::TAG, true);
206
207 auto p = tree_->equal_range(root);
208
209 return Range<SubtreeIterator>(SubtreeIterator(p.first, root, *this),
210 SubtreeIterator(p.second, root, *this));
211}

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

Referenced by ApplicationsLib::TestDefinition::TestDefinition(), ChemistryLib::SelfContainedSolverData::createChemicalReactionData(), MaterialLib::Solids::createConstitutiveRelationsGeneric(), MaterialPropertyLib::createFunction(), ParameterLib::createFunctionParameter(), ParameterLib::createGroupBasedParameter(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), MaterialPropertyLib::createLinear(), ProcessLib::createOutputs(), ProcessLib::createPerProcessData(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), InSituLib::Initialize(), NumLib::parseFixedTimeStepping(), ProjectData::parseLinearSolvers(), NumLib::parseLocalCoupling(), 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 187 of file ConfigTree.cpp.

189{
190 checkUnique(root);
191
192 if (auto subtree = tree_->get_child_optional(root))
193 {
194 markVisited(root, Attr::TAG, false);
195 return ConfigTree(*subtree, *this, root);
196 }
197 markVisited(root, Attr::TAG, true);
198 return std::nullopt;
199}

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

Referenced by ProcessLib::ProcessVariable::ProcessVariable(), ParameterLib::checkThirdBaseExistanceFor2D(), ChemistryLib::PhreeqcIOData::createChemicalSystem(), anonymous_namespace{CreateComponent.cpp}::createComponent(), ProcessLib::ComponentTransport::createComponentTransportProcess(), MaterialLib::Solids::createConstitutiveRelationIce(), ParameterLib::createCoordinateSystemWithImplicitBase(), ProcessLib::createDeactivatedSubdomain(), ProcessLib::createDeactivatedSubdomains(), MaterialLib::Solids::Ehlers::createEhlers(), ProcessLib::HeatTransportBHE::BHE::createFlowAndTemperatureControl(), ProcessLib::HT::createHTProcess(), ProcessLib::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::LIE::HydroMechanics::createHydroMechanicsProcess(), ProcessLib::createInitialStress(), ProcessLib::LiquidFlow::createLiquidFlowProcess(), MaterialPropertyLib::createMedium(), MaterialLib::Solids::MFront::createMFrontConfig(), NumLib::createNonlinearSolver(), NumLib::createNumericalStabilization(), ProcessLib::createOutputConfig(), anonymous_namespace{CreatePhase.cpp}::createPhase(), ProcessLib::RichardsMechanics::createRichardsMechanicsProcess(), MeshGeoToolsLib::createSearchLengthAlgorithm(), ProcessLib::createSecondaryVariables(), ProcessLib::SteadyStateDiffusion::createSteadyStateDiffusion(), ProcessLib::createTimeLoop(), anonymous_namespace{ProcessVariable.cpp}::findMeshInConfig(), getConfigParameterOptional(), getConfigParameterOptionalImpl(), getConfigParameterOptionalImpl(), getConfigSubtree(), NumLib::parseCoupling(), MathLib::LinearSolverOptionsParser< EigenLinearSolver >::parseNameAndOptions(), MathLib::LinearSolverOptionsParser< PETScLinearSolver >::parseNameAndOptions(), parseOverwriteMeshData(), anonymous_namespace{ProjectData.cpp}::readMeshes(), anonymous_namespace{ProjectData.cpp}::readRasters(), and anonymous_namespace{CreateMFrontGeneric.cpp}::readStateVariablesInitialValueProperties().

◆ getValue()

template<typename T>
T BaseLib::ConfigTree::getValue ( ) const

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

218{
219 if (have_read_data_)
220 {
221 error("The data of this subtree has already been read.");
222 }
223
224 have_read_data_ = true;
225
226 if (auto v = tree_->get_value_optional<T>())
227 {
228 return *v;
229 }
230 error("Value `" + shortString(tree_->data()) +
231 "' is not convertible to the desired type.");
232}

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

Referenced by ParameterLib::parseBase1OrBase2(), MaterialPropertyLib::anonymous_namespace{CreateFunction.cpp}::parseExpressionList(), parseOutputMeshConfig(), and anonymous_namespace{ProjectData.cpp}::readSingleMesh().

◆ hasChildren()

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

Checks if this tree has any children.

Definition at line 440 of file ConfigTree.cpp.

441{
442 auto const& tree = *tree_;
443 if (tree.begin() == tree.end())
444 {
445 return false; // no children
446 }
447 if (tree.front().first == "<xmlattr>" && (++tree.begin()) == tree.end())
448 {
449 return false; // only attributes
450 }
451
452 return true;
453}

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

247{
248 checkUniqueAttr(attr);
249
250 // Exercise: Guess what not! (hint: if not found, peek only)
251 // Btw. (not a hint) tree_->find() does not seem to work here.
252 bool peek_only = !tree_->get_child_optional("<xmlattr>." + attr);
253
254 markVisited(attr, Attr::ATTR, peek_only);
255}

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

239{
240 checkUnique(param);
241 // if not found, peek only
242 bool peek_only = tree_->find(param) == tree_->not_found();
243 markVisited(param, Attr::TAG, peek_only);
244}

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

258{
259 checkUnique(param);
260 auto& ct = markVisited(param, Attr::TAG, true);
261
262 auto p = tree_->equal_range(param);
263 for (auto it = p.first; it != p.second; ++it)
264 {
265 ++ct.count;
266 }
267}

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

360{
361 if (p2.empty())
362 {
363 error("Second path to be joined is empty.");
364 }
365
366 if (p1.empty())
367 {
368 return p2;
369 }
370
371 return p1 + pathseparator + p2;
372}
static const char pathseparator
Character separating two path components.
Definition ConfigTree.h:687

References error(), and pathseparator.

Referenced by ConfigTree().

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

421{
422 return markVisited<ConfigTree>(key, is_attr, peek_only);
423}

References markVisited().

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

286{
287 auto const type = std::type_index(typeid(T));
288
289 auto p = visited_params_.emplace(std::make_pair(is_attr, key),
290 CountType{peek_only ? 0 : 1, type});
291
292 if (!p.second)
293 { // no insertion happened
294 auto& v = p.first->second;
295 if (v.type == type)
296 {
297 if (!peek_only)
298 {
299 ++v.count;
300 }
301 }
302 else
303 {
304 error("There already was an attempt to obtain key <" + key +
305 "> with type '" + BaseLib::demangle(v.type.name()) +
306 "' (now: '" + type.name() + "').");
307 }
308 }
309
310 return p.first->second;
311}
std::string demangle(const char *mangled_name)

References BaseLib::demangle(), error(), and visited_params_.

Referenced by getAllChildren(), getConfigAttributeOptional(), getConfigParameterList(), getConfigSubtreeList(), getConfigSubtreeOptional(), ignoreConfigAttribute(), ignoreConfigParameter(), ignoreConfigParameterAll(), and markVisited().

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

427{
428 auto const type = std::type_index(typeid(nullptr));
429
430 auto p = visited_params_.emplace(std::make_pair(is_attr, key),
431 CountType{-1, type});
432
433 if (!p.second)
434 { // no insertion happened
435 auto& v = p.first->second;
436 --v.count;
437 }
438}

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

289{
290 OGS_FATAL("ConfigTree: In file `{:s}' at path <{:s}>: {:s}", filename, path,
291 message);
292}

References OGS_FATAL.

Referenced by BaseLib::makeConfigTree().

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

296{
297 WARN("ConfigTree: In file `{:s}' at path <{:s}>: {:s}", filename, path,
298 message);
299}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34

References WARN().

Referenced by BaseLib::makeConfigTree().

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

118{
120
121 top_level_tree_ = std::move(other.top_level_tree_);
122 tree_ = other.tree_;
123 other.tree_ = nullptr;
124 path_ = std::move(other.path_);
125 filepath_ = std::move(other.filepath_);
126 visited_params_ = std::move(other.visited_params_);
127 have_read_data_ = other.have_read_data_;
128 onerror_ = std::move(other.onerror_);
129 onwarning_ = std::move(other.onwarning_);
130
131 return *this;
132}

References ConfigTree(), checkAndInvalidate(), filepath_, have_read_data_, onerror_, onwarning_, path_, top_level_tree_, tree_, and visited_params_.

◆ operator=() [2/2]

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

copying is not compatible with the semantics of this class

References ConfigTree().

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

195{
196 checkKeyname(param);
197
198 if (auto p = tree_->get_child_optional(param))
199 {
200 try
201 {
202 return p->get_value<T>();
203 }
204 catch (boost::property_tree::ptree_bad_data const&)
205 {
206 error("Value for key <" + param + "> `" + shortString(p->data()) +
207 "' not convertible to the desired type.");
208 }
209 }
210 else
211 {
212 error("Key <" + param + "> has not been found");
213 }
214}

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

Referenced by MaterialPropertyLib::createAverageMolarMass(), MaterialPropertyLib::createBishopsPowerLaw(), MaterialPropertyLib::createBishopsSaturationCutoff(), ProcessLib::createBoundaryCondition(), MaterialPropertyLib::createCapillaryPressureVanGenuchten(), MaterialPropertyLib::createClausiusClapeyron(), MaterialPropertyLib::createConstant(), MaterialLib::Solids::createConstitutiveRelation(), NumLib::createConvergenceCriterion(), MaterialPropertyLib::createCubicLawPermeability(), MaterialPropertyLib::createCurve(), MaterialPropertyLib::createDupuitPermeability(), MaterialPropertyLib::createEffectiveThermalConductivityPorosityMixing(), MaterialPropertyLib::createEmbeddedFracturePermeability(), MaterialPropertyLib::createExponential(), MaterialPropertyLib::createFunction(), MaterialPropertyLib::createGasPressureDependentPermeability(), MaterialPropertyLib::createIdealGasLaw(), MaterialPropertyLib::createIdealGasLawBinaryMixture(), MaterialPropertyLib::createLinear(), MaterialPropertyLib::createLinearSaturationSwellingStress(), MaterialPropertyLib::createLinearWaterVapourLatentHeat(), MaterialPropertyLib::createLiquidViscosityVogels(), MaterialPropertyLib::createOrthotropicEmbeddedFracturePermeability(), ParameterLib::createParameter(), MaterialPropertyLib::createParameterProperty(), MaterialPropertyLib::createPermeabilityMohrCoulombFailureIndexModel(), MaterialPropertyLib::createPermeabilityOrthotropicPowerLaw(), MaterialPropertyLib::createPorosityFromMassBalance(), anonymous_namespace{CreateProperty.cpp}::createProperty(), MaterialPropertyLib::createRelPermBrooksCorey(), MaterialPropertyLib::createRelPermBrooksCoreyNonwettingPhase(), MaterialPropertyLib::createRelPermGeneralizedPower(), MaterialPropertyLib::createRelPermGeneralizedPowerNonwettingPhase(), MaterialPropertyLib::createRelPermLiakopoulos(), MaterialPropertyLib::createRelPermNonWettingPhaseVanGenuchtenMualem(), MaterialPropertyLib::createRelPermUdell(), MaterialPropertyLib::createRelPermUdellNonwettingPhase(), MaterialPropertyLib::createRelPermVanGenuchten(), MaterialPropertyLib::createSaturationBrooksCorey(), MaterialPropertyLib::createSaturationDependentSwelling(), MaterialPropertyLib::createSaturationExponential(), MaterialPropertyLib::createSaturationLiakopoulos(), MaterialPropertyLib::createSaturationLuMcCartney(), MaterialPropertyLib::createSaturationVanGenuchten(), MaterialPropertyLib::createSaturationVanGenuchtenWithVolumetricStrain(), MaterialPropertyLib::createSaturationWeightedThermalConductivity(), MaterialPropertyLib::createSigmoid(), ProcessLib::LIE::SmallDeformation::createSmallDeformationProcess(), ProcessLib::createSourceTerm(), MaterialPropertyLib::createSpecificHeatCapacityWithLatentHeat(), MaterialPropertyLib::createStrainDependentPermeability(), ProcessLib::ThermoMechanics::createThermoMechanicsProcess(), NumLib::createTimeStepper(), MaterialPropertyLib::createTransportPorosityFromMassBalance(), MaterialPropertyLib::createVapourDiffusionDeVries(), MaterialPropertyLib::createVapourDiffusionFEBEX(), MaterialPropertyLib::createVapourDiffusionPMQ(), MaterialPropertyLib::createVolumeFractionAverage(), ProcessLib::createVolumetricSourceTerm(), MaterialPropertyLib::createWaterDensityIAPWSIF97Region1(), MaterialPropertyLib::createWaterEnthalpyIAPWSIF97Region1(), MaterialPropertyLib::createWaterLiquidDensityIAPWSIF97Region4(), MaterialPropertyLib::createWaterLiquidEnthalpyIAPWSIF97Region4(), MaterialPropertyLib::createWaterSaturationTemperatureIAPWSIF97Region4(), MaterialPropertyLib::createWaterTemperatureIAPWSIF97Region1(), MaterialPropertyLib::createWaterThermalConductivityIAPWS(), MaterialPropertyLib::createWaterVapourDensity(), MaterialPropertyLib::createWaterVapourDensityIAPWSIF97Region4(), MaterialPropertyLib::createWaterVapourEnthalpyIAPWSIF97Region4(), MaterialPropertyLib::createWaterVapourLatentHeatWithCriticalTemperature(), MaterialPropertyLib::createWaterViscosityIAPWS(), and ProcessLib::parseDirichletBoundaryConditionWithinTimeIntervalConfig().

◆ projectDirectory()

◆ projectFilePath()

std::filesystem::path const & BaseLib::ConfigTree::projectFilePath ( ) const
inline

Used to get the project file name.

Definition at line 297 of file ConfigTree.h.

297{ return filepath_; }

References filepath_.

◆ shortString()

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

returns a short string at suitable for error/warning messages

Definition at line 322 of file ConfigTree.cpp.

323{
324 const std::size_t maxlen = 100;
325
326 if (s.size() < maxlen)
327 {
328 return s;
329 }
330
331 return s.substr(0, maxlen - 3) + "...";
332}

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

283{
284 onwarning_(filepath_.string(), path_, message);
285}

References filepath_, onwarning_, and path_.

Referenced by checkAndInvalidate().

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

536{
537 conf.checkAndInvalidate();
538}

References ConfigTree(), and checkAndInvalidate().

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

541{
542 if (conf)
543 {
544 conf->checkAndInvalidate();
545 }
546}

References ConfigTree(), and checkAndInvalidate().

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

549{
550 if (conf)
551 {
552 conf->checkAndInvalidate();
553 }
554}

Member Data Documentation

◆ filepath_

std::filesystem::path BaseLib::ConfigTree::filepath_
private

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

Definition at line 665 of file ConfigTree.h.

Referenced by ConfigTree(), ConfigTree(), ConfigTree(), error(), operator=(), projectDirectory(), projectFilePath(), 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 681 of file ConfigTree.h.

Referenced by ConfigTree(), 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 693 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 690 of file ConfigTree.h.

Referenced by checkKeyname().

◆ onerror_

Callback BaseLib::ConfigTree::onerror_
private

Custom error callback.

Definition at line 683 of file ConfigTree.h.

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

◆ onwarning_

Callback BaseLib::ConfigTree::onwarning_
private

Custom warning callback.

Definition at line 684 of file ConfigTree.h.

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

◆ path_

std::string BaseLib::ConfigTree::path_
private

A path printed in error/warning messages.

Definition at line 662 of file ConfigTree.h.

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

◆ pathseparator

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

Character separating two path components.

Definition at line 687 of file ConfigTree.h.

Referenced by joinPaths().

◆ top_level_tree_

std::shared_ptr<PTree const> BaseLib::ConfigTree::top_level_tree_
private

Root of the tree.

Owned by all ConfigTree instances that might access any part of it.

Definition at line 656 of file ConfigTree.h.

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

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

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


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