1#ifndef CHITECH_PARAMETER_BLOCK_H
2#define CHITECH_PARAMETER_BLOCK_H
44 std::unique_ptr<chi_data_types::Varying>
value_ptr_ =
nullptr;
57 static constexpr bool value = std::is_same_v<T, bool>;
62 static constexpr bool value = std::is_floating_point_v<T>;
68 std::is_same_v<T, std::string> or std::is_same_v<T, const char*>;
74 std::is_integral_v<T> and not std::is_same_v<T, bool>;
87 for (
const T& value : array)
98 static_assert(is_supported,
"Value type not supported for parameter block");
105 value_ptr_ = std::make_unique<chi_data_types::Varying>(value);
127 std::string
Name()
const;
131 const std::vector<ParameterBlock>&
Parameters()
const;
167 template <
typename T>
179 bool Has(
const std::string& param_name)
const;
193 template <
typename T>
198 std::string(__PRETTY_FUNCTION__) +
199 ": Value not available for block type " +
205 catch (
const std::exception& exc)
213 template <
typename T>
218 const auto& param =
GetParam(param_name);
219 return param.GetValue<T>();
221 catch (
const std::out_of_range& oor)
223 throw std::out_of_range(
225 ": Parameter \"" + param_name +
"\" not present in block");
231 template <
typename T>
236 std::string(__PRETTY_FUNCTION__) +
237 ": Invalid type requested for parameter of type " +
248 if (param.Type() != front_param.Type())
249 throw std::logic_error(
251 ": Parameter \"" +
name_ +
252 "\", cannot construct vector from block because "
253 "the sub_parameters do not all have the correct type. param->" +
258 for (
size_t k = 0; k < num_params; ++k)
261 vec.push_back(param.GetValue<T>());
269 template <
typename T>
272 const auto& param =
GetParam(param_name);
273 return param.GetVectorValue<T>();
323 const std::string& offset =
"")
const;
bool operator==(const const_iterator &rhs) const
const_iterator operator++(int)
const_iterator operator++()
const ParameterBlock & operator*()
bool operator!=(const const_iterator &rhs) const
const_iterator(const ParameterBlock &in_block, size_t i)
const ParameterBlock & ref_block
bool operator!=(const iterator &rhs) const
bool operator==(const iterator &rhs) const
ParameterBlock & operator*()
iterator(ParameterBlock &in_block, size_t i)
ParameterBlock & ref_block
void SetErrorOriginScope(const std::string &scope)
void RequireBlockTypeIs(ParameterBlockType type) const
const chi_data_types::Varying & Value() const
void AddParameter(const std::string &name, T value)
void RecursiveDumpToJSON(std::string &outstr) const
bool Has(const std::string ¶m_name) const
const_iterator end() const
size_t NumParameters() const
void RequireParameterBlockTypeIs(const std::string ¶m_name, ParameterBlockType type) const
void AddParameter(ParameterBlock block)
std::string error_origin_scope_
std::vector< T > GetVectorValue() const
ParameterBlock(const std::string &name="")
std::string GetErrorOriginScope() const
void RecursiveDumpToString(std::string &outstr, const std::string &offset="") const
void RequireParameter(const std::string ¶m_name) const
const std::vector< ParameterBlock > & Parameters() const
const_iterator begin() const
ParameterBlock & operator=(const ParameterBlock &other)
std::string TypeName() const
ParameterBlock(const std::string &name, const std::vector< T > &array)
ParameterBlock(const std::string &name, T value)
T GetParamValue(const std::string ¶m_name) const
std::unique_ptr< chi_data_types::Varying > value_ptr_
void SetBlockName(const std::string &name)
std::vector< ParameterBlock > parameters_
ParameterBlockType Type() const
ParameterBlock & GetParam(const std::string ¶m_name)
std::vector< T > GetParamVectorValue(const std::string ¶m_name) const
BoolType< T > GetValue() const
std::string ParameterBlockTypeName(ParameterBlockType type)
static constexpr bool value
static constexpr bool value
static constexpr bool value
static constexpr bool value