Class ParameterBlock

Nested Relationships

Nested Types

Inheritance Relationships

Derived Type

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
const Varying &GetValue() 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 &param_name, ParameterBlockType type) const
void RequireParameter(const std::string &param_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 &param_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 &param_name)

Gets a parameter by name.

ParameterBlock &GetParam(size_t index)

Gets a parameter by index.

const ParameterBlock &GetParam(const std::string &param_name) const

Gets a parameter by name.

const ParameterBlock &GetParam(size_t index) const

Gets a parameter by index.

template<typename T>
inline T GetValue() const

Returns the value of the parameter.

template<typename T>
inline T GetParamValue(const std::string &param_name) const

Fetches the parameter with the given name and returns it value.

template<typename T, typename Derived = T>
inline std::shared_ptr<Derived> GetSharedPtrParam(const std::string &param_name, const bool check = true) const

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 &param_name) const

Gets a vector of primitive types from an array-type parameter block specified as a parameter of the current block.

inline Iterator begin()
inline Iterator end()
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

Public Members

const ParameterBlock &ref_block
size_t ref_id
template<typename T>
struct IsBool

Public Static Attributes

static bool value = std::is_same_v<T, bool>
template<typename T>
struct IsFloat

Public Static Attributes

static bool value = std::is_floating_point_v<T>
template<typename T>
struct IsInteger

Public Static Attributes

static bool value = std::is_integral_v<T> and not std::is_same_v<T, bool>
template<typename T>
struct IsString

Public Static Attributes

static bool value = std::is_same_v<T, std::string> or std::is_same_v<T, const char*>
template<typename T>
struct IsUserData

Public Static Attributes

static bool value = (std::is_pointer_v<T> or is_shared_ptr_v<T> or (std::is_class_v<T> and not std::is_same_v<T, std::string>)) and (not std::is_same_v<T, const char*>)
class Iterator

Public Functions

inline Iterator(ParameterBlock &block, size_t i)
inline Iterator operator++()
inline Iterator operator++(int)
inline ParameterBlock &operator*()
inline bool operator==(const Iterator &rhs) const
inline bool operator!=(const Iterator &rhs) const

Public Members

ParameterBlock &ref_block
size_t ref_id