Class ParameterBlock
Defined in File parameter_block.h
Nested Relationships
Nested Types
Inheritance Relationships
Derived Type
public opensn::InputParameters
(Class InputParameters)
Class Documentation
-
class ParameterBlock
A ParameterBlock is a conceptually simple data structure that supports a hierarchy of primitive parameters. There really are just 4 member variables on a ParameterBlock object, they are 1) the type (as an enum), 2) the name of the block, 3) a pointer to a value (which can only be a primitive type), and 4) a vector of child parameters.
If a ParameterBlock has a primitive type, i.e., BOOLEAN, FLOAT, STRING, or INTEGER, then the value_ptr will contain a pointer to the value of a primitive type. Otherwise, for types ARRAY and BLOCK, the ParameterBlock will not have a value_ptr and instead the vector member will contain sub-parameters.
Subclassed by opensn::InputParameters
Public Functions
-
void SetBlockName(const std::string &name)
Sets the name of the block.
-
explicit ParameterBlock(const std::string &name = "")
Constructs an empty parameter block with the given name and type BLOCK.
-
template<typename T>
inline ParameterBlock(const std::string &name, const std::vector<T> &array) Derived type constructor.
-
template<typename T>
inline explicit ParameterBlock(const std::string &name, T value) Constructs one of the fundamental types.
-
ParameterBlock(const ParameterBlock &other)
Copy constructor.
-
ParameterBlock &operator=(const ParameterBlock &other)
Copy assignment operator.
-
ParameterBlock(ParameterBlock &&other) noexcept
Move constructor.
-
ParameterBlock &operator=(ParameterBlock &&other) noexcept
Move assignment operator.
-
ParameterBlockType GetType() const
-
bool IsScalar() const
Returns true if the parameter block comprises a single value of any of the types BOOLEAN, FLOAT, STRING, INTEGER.
-
std::string GetTypeName() const
Returns a string version of the type.
-
std::string GetName() const
-
size_t GetNumParameters() const
Returns the number of parameters in a block. This is normally only useful for the ARRAY type.
-
const std::vector<ParameterBlock> &GetParameters() const
Returns the sub-parameters of this block.
-
bool HasValue() const
Returns whether or not the block has a value. If this block has sub-parameters it should not have a value. This is a good way to check if the block is actually a single value because some Parameter blocks can be passed as empty.
-
void ChangeToArray()
Changes the block type to array, making it accessible via integer keys.
-
void SetErrorOriginScope(const std::string &scope)
Sets a string to be displayed alongside exceptions that give some notion of the origin of the error.
-
inline std::string GetErrorOriginScope() const
Gets a string that allows error messages to print the scope of an error.
-
void RequireBlockTypeIs(ParameterBlockType type) const
Checks that the block is of the given type. If it is not it will throw an exception
std::logic_error
.
-
inline void RequireParameterBlockTypeIs(const std::string ¶m_name, ParameterBlockType type) const
-
void RequireParameter(const std::string ¶m_name) const
Check that the parameter with the given name exists otherwise throws a
std::logic_error
.
-
void AddParameter(ParameterBlock block)
Adds a parameter to the sub-parameter list.
-
template<typename T>
inline void AddParameter(const std::string &name, const T &value) Makes a ParameterBlock and adds it to the sub-parameters list.
-
void SortParameters()
Sorts the sub-parameter list according to name. This is useful for regression testing.
-
bool Has(const std::string ¶m_name) const
Returns true if a parameter with the specified name is in the list of sub-parameters. Otherwise, false.
-
ParameterBlock &GetParam(const std::string ¶m_name)
Gets a parameter by name.
-
ParameterBlock &GetParam(size_t index)
Gets a parameter by index.
-
const ParameterBlock &GetParam(const std::string ¶m_name) const
Gets a parameter by name.
-
const ParameterBlock &GetParam(size_t index) const
Gets a parameter by index.
-
template<typename T>
inline T GetParamValue(const std::string ¶m_name) const Fetches the parameter with the given name and returns it value.
Fetches the parameter of type std::shared_ptr<T> with the given name and returns its value.
Will perform checking on whether or not the pointed-to-object is null (if
check
= true)The optional second template argument can be used to attempt to cast the object to the derived type and will throw an exception if the cast fails.
-
template<typename T>
inline std::vector<T> GetVectorValue() const Converts the parameters of an array-type parameter block to a vector of primitive types and returns it.
-
template<typename T>
inline std::vector<T> GetParamVectorValue(const std::string ¶m_name) const Gets a vector of primitive types from an array-type parameter block specified as a parameter of the current block.
-
inline ConstIterator begin() const
-
inline ConstIterator end() const
-
void RecursiveDumpToString(std::string &outstr, const std::string &offset = "") const
Given a reference to a string, recursively travels the parameter tree and print values into the reference string.
-
void RecursiveDumpToJSON(std::string &outstr) const
Print the block tree structure into a designated string.
-
class ConstIterator
Public Functions
-
inline ConstIterator(const ParameterBlock &block, size_t i)
-
inline ConstIterator operator++()
-
inline ConstIterator operator++(int)
-
inline const ParameterBlock &operator*()
-
inline bool operator==(const ConstIterator &rhs) const
-
inline bool operator!=(const ConstIterator &rhs) const
-
inline ConstIterator(const ParameterBlock &block, size_t i)
-
template<typename T>
struct IsBool
-
template<typename T>
struct IsFloat
-
template<typename T>
struct IsInteger
-
template<typename T>
struct IsString
-
template<typename T>
struct IsUserData
-
void SetBlockName(const std::string &name)