Chi-Tech
|
#include <parameter_block.h>
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) | |
ParameterBlock & | operator= (const ParameterBlock &other) |
ParameterBlock (ParameterBlock &&other) noexcept | |
ParameterBlock & | operator= (ParameterBlock &&other) noexcept |
ParameterBlockType | Type () const |
bool | IsScalar () const |
std::string | TypeName () const |
std::string | Name () const |
const chi_data_types::Varying & | Value () 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 ¶m_name, ParameterBlockType type) const |
void | RequireParameter (const std::string ¶m_name) const |
void | AddParameter (ParameterBlock block) |
template<typename T > | |
void | AddParameter (const std::string &name, T value) |
void | SortParameters () |
bool | Has (const std::string ¶m_name) const |
ParameterBlock & | GetParam (const std::string ¶m_name) |
ParameterBlock & | GetParam (size_t index) |
const ParameterBlock & | GetParam (const std::string ¶m_name) const |
const ParameterBlock & | GetParam (size_t index) const |
template<typename T > | |
T | GetValue () const |
template<typename T > | |
T | GetParamValue (const std::string ¶m_name) const |
template<typename T > | |
std::vector< T > | GetVectorValue () const |
template<typename T > | |
std::vector< T > | GetParamVectorValue (const std::string ¶m_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::Varying > | value_ptr_ = nullptr |
std::vector< ParameterBlock > | parameters_ |
std::string | error_origin_scope_ = "Unknown Scope" |
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.
|
explicit |
Constructs an empty parameter block with the given name and type BLOCK.
Definition at line 35 of file paramater_block.cc.
|
inline |
Derived type constructor
Definition at line 83 of file parameter_block.h.
|
inlineexplicit |
Constructs one of the fundamental types.
Definition at line 93 of file parameter_block.h.
chi::ParameterBlock::ParameterBlock | ( | const ParameterBlock & | other | ) |
Copy constructor
Definition at line 42 of file paramater_block.cc.
|
noexcept |
Move constructor
Definition at line 77 of file paramater_block.cc.
|
inline |
Makes a ParameterBlock and adds it to the sub-parameters list.
Definition at line 168 of file parameter_block.h.
void chi::ParameterBlock::AddParameter | ( | ParameterBlock | block | ) |
Adds a parameter to the sub-parameter list.
Definition at line 222 of file paramater_block.cc.
|
inline |
Definition at line 314 of file parameter_block.h.
|
inline |
Definition at line 317 of file parameter_block.h.
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.
|
inline |
Definition at line 315 of file parameter_block.h.
|
inline |
Definition at line 318 of file parameter_block.h.
|
inline |
Gets a string that allows error messages to print the scope of an error.
Definition at line 148 of file parameter_block.h.
ParameterBlock & chi::ParameterBlock::GetParam | ( | const std::string & | param_name | ) |
Gets a parameter by name.
Definition at line 282 of file paramater_block.cc.
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.
ParameterBlock & chi::ParameterBlock::GetParam | ( | size_t | index | ) |
Gets a parameter by index.
Definition at line 294 of file paramater_block.cc.
const ParameterBlock & chi::ParameterBlock::GetParam | ( | size_t | index | ) | const |
Gets a parameter by index.
Definition at line 324 of file paramater_block.cc.
|
inline |
Fetches the parameter with the given name and returns it value.
Definition at line 214 of file parameter_block.h.
|
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.
|
inline |
Returns the value of the parameter.
Definition at line 194 of file parameter_block.h.
|
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.
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.
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.
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.
std::string chi::ParameterBlock::Name | ( | ) | const |
Definition at line 115 of file paramater_block.cc.
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.
ParameterBlock & chi::ParameterBlock::operator= | ( | const ParameterBlock & | other | ) |
Copy assignment operator
Definition at line 57 of file paramater_block.cc.
|
noexcept |
const std::vector< ParameterBlock > & chi::ParameterBlock::Parameters | ( | ) | const |
Returns the sub-parameters of this block.
Definition at line 150 of file paramater_block.cc.
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.
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.
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.
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.
|
inline |
Definition at line 154 of file parameter_block.h.
void chi::ParameterBlock::SetBlockName | ( | const std::string & | name | ) |
Sets the name of the block.
Definition at line 32 of file paramater_block.cc.
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.
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.
ParameterBlockType chi::ParameterBlock::Type | ( | ) | const |
Definition at line 103 of file paramater_block.cc.
std::string chi::ParameterBlock::TypeName | ( | ) | const |
Returns a string version of the type.
Definition at line 111 of file paramater_block.cc.
const chi_data_types::Varying & chi::ParameterBlock::Value | ( | ) | const |
Definition at line 118 of file paramater_block.cc.
|
private |
Definition at line 46 of file parameter_block.h.
|
private |
Definition at line 43 of file parameter_block.h.
|
private |
Definition at line 45 of file parameter_block.h.
|
private |
Definition at line 42 of file parameter_block.h.
|
private |
Definition at line 44 of file parameter_block.h.