26 throw std::logic_error(std::string(__PRETTY_FUNCTION__) +
27 ": No name associated with type");
79 std::swap(type_, other.type_);
80 std::swap(name_, other.name_);
81 std::swap(value_ptr_, other.value_ptr_);
82 std::swap(parameters_, other.parameters_);
83 std::swap(error_origin_scope_, other.error_origin_scope_);
92 std::swap(type_, other.type_);
93 std::swap(name_, other.name_);
94 std::swap(value_ptr_, other.value_ptr_);
95 std::swap(parameters_, other.parameters_);
96 std::swap(error_origin_scope_, other.error_origin_scope_);
120 switch (this->
Type())
128 throw std::runtime_error(
130 ": Uninitialized Varying value for block " + this->
Name());
134 throw std::logic_error(
138 " Called for block of type " +
168 const std::string fname = __PRETTY_FUNCTION__;
177 if (param.Type() != first_param.Type())
178 throw std::logic_error(
180 ": Cannot change ParameterBlock to "
181 "array. It has existing parameters and they are not of the same"
195 param.SetErrorOriginScope(scope);
206 " Is required to be of type " +
215 if (not
Has(param_name))
217 " Is required to have parameter " + param_name);
225 if (param.Name() == block.
Name())
226 throw std::invalid_argument(
228 ": Attempting to add duplicate parameter " + param.Name() +
242 struct AlphabeticFunctor
246 return paramA.
Name() < paramB.
Name();
250 struct AlphabeticNumericFunctor
254 return std::stoi(paramA.
Name()) < std::stoi(paramB.
Name());
277 { return param.name_ == param_name; });
285 if (param.Name() == param_name)
return param;
288 std::string(__PRETTY_FUNCTION__) +
": Parameter \"" +
289 param_name +
"\" not present in block");
300 catch (
const std::out_of_range& oor)
303 std::string(__PRETTY_FUNCTION__) +
304 ": Parameter with index " + std::to_string(index) +
305 " not present in block");
315 if (param.Name() == param_name)
return param;
318 std::string(__PRETTY_FUNCTION__) +
": Parameter \"" +
319 param_name +
"\" not present in block");
330 catch (
const std::out_of_range& oor)
333 std::string(__PRETTY_FUNCTION__) +
334 ": Parameter with index " + std::to_string(index) +
335 " not present in block");
343 const std::string& offset)
const
345 outstr += offset + this->
Name() +
" = \n";
346 outstr += offset +
"{\n";
353 switch (param.Type())
357 outstr += offset +
" " + param.Name() +
" = ";
358 const bool value = param.Value().BoolValue();
359 outstr += std::string(value ?
"true" :
"false") +
",\n";
364 outstr += offset +
" " + param.Name() +
" = ";
365 const double value = param.Value().FloatValue();
366 outstr += std::to_string(value) +
",\n";
371 outstr += offset +
" " + param.Name() +
" = ";
372 const auto& value = param.Value().StringValue();
373 outstr +=
"\"" + value +
"\",\n";
378 outstr += offset +
" " + param.Name() +
" = ";
379 const int64_t value = param.Value().IntegerValue();
380 outstr += std::to_string(value) +
",\n";
386 param.RecursiveDumpToString(outstr, offset +
" ");
394 outstr += offset +
"}\n";
413 switch (param.Type())
417 outstr +=
"\"" + param.Name() +
"\" = ";
418 const bool value = param.Value().BoolValue();
419 outstr += std::string(value ?
"true" :
"false") +
",\n";
424 outstr +=
"\"" + param.Name() +
"\" = ";
425 const double value = param.Value().FloatValue();
426 outstr += std::to_string(value) +
",\n";
431 outstr +=
"\"" + param.Name() +
"\" = ";
432 const auto& value = param.Value().StringValue();
433 outstr +=
"\"" + value +
"\",\n";
438 outstr +=
"\"" + param.Name() +
"\" = ";
439 const int64_t value = param.Value().IntegerValue();
440 outstr += std::to_string(value) +
",\n";
446 param.RecursiveDumpToJSON(outstr);
void SetErrorOriginScope(const std::string &scope)
void RequireBlockTypeIs(ParameterBlockType type) const
const chi_data_types::Varying & Value() const
void RecursiveDumpToJSON(std::string &outstr) const
bool Has(const std::string ¶m_name) const
size_t NumParameters() const
void AddParameter(ParameterBlock block)
std::string error_origin_scope_
ParameterBlock(const std::string &name="")
void RecursiveDumpToString(std::string &outstr, const std::string &offset="") const
void RequireParameter(const std::string ¶m_name) const
const std::vector< ParameterBlock > & Parameters() const
ParameterBlock & operator=(const ParameterBlock &other)
std::string TypeName() 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::string ParameterBlockTypeName(ParameterBlockType type)