encode_extended_value.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // encode overload for extended_value
4 //
5 // ======================================================================
6 
9 #include "fhiclcpp/exception.h"
12 
13 using namespace fhicl;
14 
19 
20 using ps_atom_t = ParameterSet::ps_atom_t; // same as atom_t!
22 
23 std::any
25 {
26  switch (xval.tag) {
27  case NIL:
28  case BOOL:
29  case NUMBER:
30  case STRING:
31  return atom_t(xval);
32 
33  case COMPLEX: {
34  complex_t const& cmplx = complex_t(xval);
35  return '(' + cmplx.first + ',' + cmplx.second + ')';
36  }
37 
38  case SEQUENCE: {
40  sequence_t const& seq = sequence_t(xval);
41  for (sequence_t::const_iterator it = seq.begin(), e = seq.end(); it != e;
42  ++it)
43  result.push_back(std::any(encode(*it)));
44  return result;
45  }
46 
47  case TABLE: {
49  table_t const& tbl = table_t(xval);
51  for (const_iterator it = tbl.begin(), e = tbl.end(); it != e; ++it) {
52  if (!it->second.in_prolog)
53  result.put(it->first, it->second);
54  }
55  return ParameterSetRegistry::put(result);
56  }
57 
58  case TABLEID: {
59  atom_t const& tableID = atom_t(xval);
60  return ParameterSetID(tableID);
61  }
62 
63  case UNKNOWN:
64  default: {
65  throw fhicl::exception(type_mismatch, "unknown extended value");
66  }
67  }
68 } // encode()
intermediate_table::complex_t complex_t
iterator begin()
Definition: stdmap_shims.h:150
static ParameterSetID const & put(ParameterSet const &ps)
static QCString result
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
intermediate_table::const_iterator const_iterator
intermediate_table::table_t table_t
std::vector< std::any > ps_sequence_t
Definition: coding.h:45
intermediate_table::sequence_t sequence_t
iterator end()
Definition: stdmap_shims.h:171
const double e
extended_value::complex_t complex_t
extended_value::sequence_t sequence_t
fhicl::detail::ps_atom_t ps_atom_t
Definition: ParameterSet.h:38
fhicl::detail::ps_sequence_t ps_sequence_t
Definition: ParameterSet.h:39
extended_value::table_t table_t
ParameterSet::ps_atom_t ps_atom_t
fhicl::extended_value::sequence_t sequence_t
intermediate_table::atom_t atom_t
ParameterSet::ps_sequence_t ps_sequence_t
extended_value::atom_t atom_t
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33