21 bool Setting::_encodeUseDefault =
false;
23 bool SettingChecker::operator()(boost::blank, boost::blank)
const {
27 bool SettingChecker::operator()(
bool a,
bool b)
const {
31 bool SettingChecker::operator()(
int a,
int b)
const {
35 bool SettingChecker::operator()(
double a,
double b)
const {
39 bool SettingChecker::operator()(complex<double> a, complex<double> b)
const {
43 bool SettingChecker::operator()(
const string& a,
const string& b)
const {
47 bool SettingChecker::operator()(
const vector<double>& a,
const vector<double>& b)
const {
48 if (a.size() != b.size()) {
51 return equal(a.begin(), a.end(), b.begin(), [](
double n1,
double n2) ->
bool {
return isZero(n1 - n2); });
54 bool SettingChecker::operator()(
const vector<string>& a,
const vector<string>& b)
const {
63 SettingWriter::SettingWriter(flatbuffers::FlatBufferBuilder* builder) : _builder{builder} { }
66 auto resc = Serial::FBSBool{
false};
67 auto out =
_builder->CreateStruct(resc);
68 return make_pair(out.Union(), Serial::FBSettingTypes::FBSBool);
72 auto resc = Serial::FBSBool{a};
73 auto out =
_builder->CreateStruct(resc);
74 return make_pair(out.Union(), Serial::FBSettingTypes::FBSBool);
78 auto resc = Serial::FBSInt{a};
79 auto out =
_builder->CreateStruct(resc);
80 return make_pair(out.Union(), Serial::FBSettingTypes::FBSInt);
84 auto resc = Serial::FBSDouble{a};
85 auto out =
_builder->CreateStruct(resc);
86 return make_pair(out.Union(), Serial::FBSettingTypes::FBSDouble);
91 auto resc = Serial::FBComplex{a.real(), a.imag()};
92 auto out =
_builder->CreateStruct(resc);
93 return make_pair(out.Union(), Serial::FBSettingTypes::FBComplex);
98 auto serialval =
_builder->CreateString(a);
99 Serial::FBSStringBuilder serialBuilder{*
_builder};
100 serialBuilder.add_value(serialval);
101 auto out = serialBuilder.Finish();
102 return make_pair(out.Union(), Serial::FBSettingTypes::FBSString);
107 auto serialvals =
_builder->CreateVector(a);
108 Serial::FBVecDoubleBuilder serialBuilder{*
_builder};
109 serialBuilder.add_value(serialvals);
110 auto out = serialBuilder.Finish();
111 return make_pair(out.Union(), Serial::FBSettingTypes::FBVecDouble);
116 auto serialvals =
_builder->CreateVectorOfStrings(a);
117 Serial::FBVecStringBuilder serialBuilder{*
_builder};
118 serialBuilder.add_value(serialvals);
119 auto out = serialBuilder.Finish();
120 return make_pair(out.Union(), Serial::FBSettingTypes::FBVecString);
125 vector<flatbuffers::Offset<Serial::FBVecDouble>> vecs;
126 for (
auto& elem : a) {
127 auto serialvals =
_builder->CreateVector(elem);
128 Serial::FBVecDoubleBuilder serialBuilder{*
_builder};
129 serialBuilder.add_value(serialvals);
130 vecs.push_back(serialBuilder.Finish());
132 auto serialvecs =
_builder->CreateVector(vecs);
133 Serial::FBSVecVecDoubleBuilder serialBuilder{*
_builder};
134 serialBuilder.add_value(serialvecs);
135 auto out = serialBuilder.Finish();
136 return make_pair(out.Union(), Serial::FBSettingTypes::FBSVecVecDouble);
164 node.push_back(a.real());
165 node.push_back(a.imag());
166 node.SetStyle(YAML::EmitterStyle::Flow);
179 node.push_back(elem);
181 node.SetStyle(YAML::EmitterStyle::Flow);
187 for (
auto elem : a) {
188 node.push_back(elem);
190 node.SetStyle(YAML::EmitterStyle::Flow);
196 for (
auto elem : a) {
198 for(
auto elem2: elem) {
199 tmpNode.push_back(elem2);
201 tmpNode.SetStyle(YAML::EmitterStyle::Flow);
202 node.push_back(tmpNode);
204 node.SetStyle(YAML::EmitterStyle::Flow);
213 return (a ?
"On" :
"Off");
226 tmp += to_string(a.real());
228 tmp += to_string(a.imag());
239 for (
auto elem : a) {
240 tmp += to_string(elem) +
", ";
248 for (
auto& elem : a) {
257 for (
auto& elem : a) {
259 for (
auto& elem2 : elem) {
260 tmp += to_string(elem2) +
", ";
301 return boost::apply_visitor(checker,
_value, other.
_value);
312 bool updateDefault = (
_value.which() == 0);
322 return boost::apply_visitor(writer,
_value);
326 switch (msgreader->value_type()) {
327 case Serial::FBSettingTypes::FBSBool:
328 setValue<bool>(msgreader->value_as_FBSBool()->value());
330 case Serial::FBSettingTypes::FBSInt:
331 setValue<int>(msgreader->value_as_FBSInt()->value());
333 case Serial::FBSettingTypes::FBSDouble:
334 setValue<double>(msgreader->value_as_FBSDouble()->value());
336 case Serial::FBSettingTypes::FBSString:
337 setValue(
string(msgreader->value_as_FBSString()->value()->c_str()));
339 case Serial::FBSettingTypes::FBComplex: {
340 auto serialcompl = msgreader->value_as_FBComplex();
341 complex<double> val{serialcompl->re(), serialcompl->im()};
345 case Serial::FBSettingTypes::FBVecDouble: {
346 auto serialvecd = msgreader->value_as_FBVecDouble()->value();
348 for (
unsigned int j = 0; j < serialvecd->size(); ++j) {
349 vecd.push_back(serialvecd->Get(j));
354 case Serial::FBSettingTypes::FBVecString: {
355 auto serialvecs = msgreader->value_as_FBVecString()->value();
357 for (
unsigned int j = 0; j < serialvecs->size(); ++j) {
358 vecs.push_back(
string(serialvecs->Get(j)->c_str()));
363 case Serial::FBSettingTypes::FBSVecVecDouble: {
364 auto serialvecvecd = msgreader->value_as_FBSVecVecDouble()->value();
365 vector<vector<double>> vecvecd;
366 for (
unsigned int i = 0; i < serialvecvecd->size(); ++i) {
367 auto serialvecd = serialvecvecd->Get(i)->value();
369 for (
unsigned int j = 0; j < serialvecd->size(); ++j) {
370 vecd.push_back(serialvecd->Get(j));
372 vecvecd.push_back(vecd);
387 return boost::apply_visitor(strConverter, (useDefault ?
_default :
_value));
392 out << YAML::convert<Setting>::encode(s);
403 return boost::apply_visitor(encoder, value._default);
405 return boost::apply_visitor(encoder, value._value);
409 if(node.IsScalar()) {
411 bool tmp = node.as<
bool>();
414 catch (YAML::Exception&) {
416 int tmp = node.as<
int>();
419 catch (YAML::Exception&) {
421 double tmp = node.as<
double>();
424 catch (YAML::Exception&) {
425 string tmp = node.as<
string>();
432 else if(node.IsSequence()) {
433 if (node.begin()->Type() == YAML::NodeType::Sequence &&
434 node.begin()->begin()->Type() == YAML::NodeType::Scalar) {
437 for (YAML::const_iterator itvv = node.begin(); itvv != node.end(); ++itvv) {
438 vector<double> tmpvec = itvv->as<vector<double>>();
439 tmp.push_back(tmpvec);
442 }
catch (YAML::Exception&) {
446 }
else if (node.begin()->Type() != YAML::NodeType::Scalar) {
450 vector<double> tmp = node.as<vector<double>>();
451 if (tmp.size() == 2 && value.
getDefault<complex<double>>() !=
nullptr) {
452 value.
_value = complex<double>{tmp[0], tmp[1]};
457 }
catch (YAML::Exception&) {
459 vector<string> tmp = node.as<vector<string>>();
461 }
catch (YAML::Exception&) {
Setting & operator=(const Setting &other)
std::vector< std::vector< double >> MatrixType
void update(const Setting &other)
YAML::Emitter & operator<<(YAML::Emitter &out, const ProcessDefinitions &s)
static bool _encodeUseDefault
T * getDefault()
get the default value of this setting
void reset()
reset the contents of the settings
std::string operator()(boost::blank a) const
void read(const Serial::FBSetting *msgreader)
flatbuffers::FlatBufferBuilder * _builder
WrittenSettingType write(flatbuffers::FlatBufferBuilder *msgwriter) const
std::pair< flatbuffers::Offset< void >, Serial::FBSettingTypes > WrittenSettingType
void setValue(const T &value)
modify the setting value
bool isSame(const Setting &other) const
SettingType _default
setting default value
Initialization error class.
container for an Hammer run option
static bool decode(const Node &node,::Hammer::Setting &value)
static void setEncodeUseDefault(bool useDefault)
YAML::Node operator()(boost::blank a) const
bool isZero(const std::complex< double > val)
std::string toString(const bool useDefault=false) const
properly format the value of the setting (so that can be e.g.
static Node encode(const ::Hammer::Setting &value)
Various operations on Setting class.
SettingType _value
setting value
Serialization related typedefs and includes.
Setting()
default constructor
Setting::WrittenSettingType operator()(boost::blank a) const