Chi-Tech
chi::ParameterBlock Class Reference

#include <parameter_block.h>

Inheritance diagram for chi::ParameterBlock:
chi::InputParameters

Data Structures

class  const_iterator
 
struct  IsBool
 
struct  IsFloat
 
struct  IsInteger
 
struct  IsString
 
class  iterator
 

Public Member Functions

void SetBlockName (const std::string &name)
 
 ParameterBlock (const std::string &name="")
 
template<typename T >
 ParameterBlock (const std::string &name, const std::vector< T > &array)
 
template<typename T >
 ParameterBlock (const std::string &name, T value)
 
 ParameterBlock (const ParameterBlock &other)
 
ParameterBlockoperator= (const ParameterBlock &other)
 
 ParameterBlock (ParameterBlock &&other) noexcept
 
ParameterBlockoperator= (ParameterBlock &&other) noexcept
 
ParameterBlockType Type () const
 
bool IsScalar () const
 
std::string TypeName () const
 
std::string Name () const
 
const chi_data_types::VaryingValue () const
 
size_t NumParameters () const
 
const std::vector< ParameterBlock > & Parameters () const
 
bool HasValue () const
 
void ChangeToArray ()
 
void SetErrorOriginScope (const std::string &scope)
 
std::string GetErrorOriginScope () const
 
void RequireBlockTypeIs (ParameterBlockType type) const
 
void RequireParameterBlockTypeIs (const std::string &param_name, ParameterBlockType type) const
 
void RequireParameter (const std::string &param_name) const
 
void AddParameter (ParameterBlock block)
 
template<typename T >
void AddParameter (const std::string &name, T value)
 
void SortParameters ()
 
bool Has (const std::string &param_name) const
 
ParameterBlockGetParam (const std::string &param_name)
 
ParameterBlockGetParam (size_t index)
 
const ParameterBlockGetParam (const std::string &param_name) const
 
const ParameterBlockGetParam (size_t index) const
 
template<typename T >
GetValue () const
 
template<typename T >
GetParamValue (const std::string &param_name) const
 
template<typename T >
std::vector< T > GetVectorValue () const
 
template<typename T >
std::vector< T > GetParamVectorValue (const std::string &param_name) const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
void RecursiveDumpToString (std::string &outstr, const std::string &offset="") const
 
void RecursiveDumpToJSON (std::string &outstr) const
 

Private Attributes

ParameterBlockType type_ = ParameterBlockType::BLOCK
 
std::string name_
 
std::unique_ptr< chi_data_types::Varyingvalue_ptr_ = nullptr
 
std::vector< ParameterBlockparameters_
 
std::string error_origin_scope_ = "Unknown Scope"
 

Detailed Description

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.

Definition at line 39 of file parameter_block.h.

Constructor & Destructor Documentation

◆ ParameterBlock() [1/5]

chi::ParameterBlock::ParameterBlock ( const std::string &  name = "")
explicit

Constructs an empty parameter block with the given name and type BLOCK.

Definition at line 35 of file paramater_block.cc.

◆ ParameterBlock() [2/5]

template<typename T >
chi::ParameterBlock::ParameterBlock ( const std::string &  name,
const std::vector< T > &  array 
)
inline

Derived type constructor

Definition at line 83 of file parameter_block.h.

◆ ParameterBlock() [3/5]

template<typename T >
chi::ParameterBlock::ParameterBlock ( const std::string &  name,
value 
)
inlineexplicit

Constructs one of the fundamental types.

Definition at line 93 of file parameter_block.h.

◆ ParameterBlock() [4/5]

chi::ParameterBlock::ParameterBlock ( const ParameterBlock other)

Copy constructor

Definition at line 42 of file paramater_block.cc.

◆ ParameterBlock() [5/5]

chi::ParameterBlock::ParameterBlock ( ParameterBlock &&  other)
noexcept

Move constructor

Definition at line 77 of file paramater_block.cc.

Member Function Documentation

◆ AddParameter() [1/2]

template<typename T >
void chi::ParameterBlock::AddParameter ( const std::string &  name,
value 
)
inline

Makes a ParameterBlock and adds it to the sub-parameters list.

Definition at line 168 of file parameter_block.h.

◆ AddParameter() [2/2]

void chi::ParameterBlock::AddParameter ( ParameterBlock  block)

Adds a parameter to the sub-parameter list.

Definition at line 222 of file paramater_block.cc.

◆ begin() [1/2]

iterator chi::ParameterBlock::begin ( )
inline

Definition at line 314 of file parameter_block.h.

◆ begin() [2/2]

const_iterator chi::ParameterBlock::begin ( ) const
inline

Definition at line 317 of file parameter_block.h.

◆ ChangeToArray()

void chi::ParameterBlock::ChangeToArray ( )

Changes the block type to array, making it accessible via integer keys.

Definition at line 166 of file paramater_block.cc.

◆ end() [1/2]

iterator chi::ParameterBlock::end ( )
inline

Definition at line 315 of file parameter_block.h.

◆ end() [2/2]

const_iterator chi::ParameterBlock::end ( ) const
inline

Definition at line 318 of file parameter_block.h.

◆ GetErrorOriginScope()

std::string chi::ParameterBlock::GetErrorOriginScope ( ) const
inline

Gets a string that allows error messages to print the scope of an error.

Definition at line 148 of file parameter_block.h.

◆ GetParam() [1/4]

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

Gets a parameter by name.

Definition at line 282 of file paramater_block.cc.

◆ GetParam() [2/4]

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

Gets a parameter by name.

Definition at line 312 of file paramater_block.cc.

◆ GetParam() [3/4]

ParameterBlock & chi::ParameterBlock::GetParam ( size_t  index)

Gets a parameter by index.

Definition at line 294 of file paramater_block.cc.

◆ GetParam() [4/4]

const ParameterBlock & chi::ParameterBlock::GetParam ( size_t  index) const

Gets a parameter by index.

Definition at line 324 of file paramater_block.cc.

◆ GetParamValue()

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

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

Definition at line 214 of file parameter_block.h.

◆ GetParamVectorValue()

template<typename T >
std::vector< T > chi::ParameterBlock::GetParamVectorValue ( const std::string &  param_name) const
inline

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

Definition at line 270 of file parameter_block.h.

◆ GetValue()

template<typename T >
T chi::ParameterBlock::GetValue ( ) const
inline

Returns the value of the parameter.

Definition at line 194 of file parameter_block.h.

◆ GetVectorValue()

template<typename T >
std::vector< T > chi::ParameterBlock::GetVectorValue ( ) const
inline

Converts the parameters of an array-type parameter block to a vector of primitive types and returns it.

Definition at line 232 of file parameter_block.h.

◆ Has()

bool chi::ParameterBlock::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.

Definition at line 272 of file paramater_block.cc.

◆ HasValue()

bool chi::ParameterBlock::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.

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.

Definition at line 160 of file paramater_block.cc.

◆ IsScalar()

bool chi::ParameterBlock::IsScalar ( ) const

Returns true if the parameter block comprises a single value of any of the types BOOLEAN, FLOAT, STRING, INTEGER.

Definition at line 106 of file paramater_block.cc.

◆ Name()

std::string chi::ParameterBlock::Name ( ) const

Definition at line 115 of file paramater_block.cc.

◆ NumParameters()

size_t chi::ParameterBlock::NumParameters ( ) const

Returns the number of parameters in a block. This is normally only useful for the ARRAY type.

Definition at line 146 of file paramater_block.cc.

◆ operator=() [1/2]

ParameterBlock & chi::ParameterBlock::operator= ( const ParameterBlock other)

Copy assignment operator

Definition at line 57 of file paramater_block.cc.

◆ operator=() [2/2]

ParameterBlock & chi::ParameterBlock::operator= ( ParameterBlock &&  other)
noexcept

Move assignment operator

Move assigment operator.

Definition at line 88 of file paramater_block.cc.

◆ Parameters()

const std::vector< ParameterBlock > & chi::ParameterBlock::Parameters ( ) const

Returns the sub-parameters of this block.

Definition at line 150 of file paramater_block.cc.

◆ RecursiveDumpToJSON()

void chi::ParameterBlock::RecursiveDumpToJSON ( std::string &  outstr) const

Print the block tree structure into a designated string.

Definition at line 401 of file paramater_block.cc.

◆ RecursiveDumpToString()

void chi::ParameterBlock::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.

Print the block tree structure into a designated string.

Definition at line 342 of file paramater_block.cc.

◆ RequireBlockTypeIs()

void chi::ParameterBlock::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.

Definition at line 202 of file paramater_block.cc.

◆ RequireParameter()

void chi::ParameterBlock::RequireParameter ( const std::string &  param_name) const

Check that the parameter with the given name exists otherwise throws a std::logic_error.

Definition at line 213 of file paramater_block.cc.

◆ RequireParameterBlockTypeIs()

void chi::ParameterBlock::RequireParameterBlockTypeIs ( const std::string &  param_name,
ParameterBlockType  type 
) const
inline

Definition at line 154 of file parameter_block.h.

◆ SetBlockName()

void chi::ParameterBlock::SetBlockName ( const std::string &  name)

Sets the name of the block.

Definition at line 32 of file paramater_block.cc.

◆ SetErrorOriginScope()

void chi::ParameterBlock::SetErrorOriginScope ( const std::string &  scope)

Sets a string to be displayed alongside exceptions that give some notion of the origin of the error.

Definition at line 191 of file paramater_block.cc.

◆ SortParameters()

void chi::ParameterBlock::SortParameters ( )

Sorts the sub-parameter list according to name. This is useful for regression testing.

Definition at line 240 of file paramater_block.cc.

◆ Type()

ParameterBlockType chi::ParameterBlock::Type ( ) const

Definition at line 103 of file paramater_block.cc.

◆ TypeName()

std::string chi::ParameterBlock::TypeName ( ) const

Returns a string version of the type.

Definition at line 111 of file paramater_block.cc.

◆ Value()

const chi_data_types::Varying & chi::ParameterBlock::Value ( ) const

Definition at line 118 of file paramater_block.cc.

Field Documentation

◆ error_origin_scope_

std::string chi::ParameterBlock::error_origin_scope_ = "Unknown Scope"
private

Definition at line 46 of file parameter_block.h.

◆ name_

std::string chi::ParameterBlock::name_
private

Definition at line 43 of file parameter_block.h.

◆ parameters_

std::vector<ParameterBlock> chi::ParameterBlock::parameters_
private

Definition at line 45 of file parameter_block.h.

◆ type_

ParameterBlockType chi::ParameterBlock::type_ = ParameterBlockType::BLOCK
private

Definition at line 42 of file parameter_block.h.

◆ value_ptr_

std::unique_ptr<chi_data_types::Varying> chi::ParameterBlock::value_ptr_ = nullptr
private

Definition at line 44 of file parameter_block.h.


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