1 #ifndef fhiclcpp_coding_h 2 #define fhiclcpp_coding_h 23 #include "boost/lexical_cast.hpp" 24 #include "boost/numeric/conversion/cast.hpp" 39 #include <type_traits> 91 void decode(std::any
const&, std::nullptr_t&);
92 void decode(std::any
const&,
bool&);
94 void decode(std::any
const&, std::uintmax_t&);
100 void decode(std::any
const&, std::intmax_t&);
109 std::enable_if_t<std::is_floating_point_v<T>>
decode(std::any
const&,
112 void decode(std::any
const&, std::complex<ldbl>&);
115 void decode(std::any
const&, std::complex<T>&);
118 void decode(std::any
const&, std::vector<T>&);
120 template <
typename U>
123 template <
typename T, std::
size_t SIZE>
129 template <
typename KEY,
typename VALUE>
135 template <
typename... ARGS>
141 template <
unsigned SIZE,
typename TUPLE>
146 template <
typename TUPLE>
163 return encode(uintmax_t(value));
170 return encode(intmax_t(value));
184 return '(' +
encode(value.real()) +
',' +
encode(value.imag()) +
')';
192 for (
auto const&
e : value) {
193 result.emplace_back(
encode(
e));
215 result = boost::numeric_cast<
T>(via);
226 result = boost::numeric_cast<
T>(via);
232 std::enable_if_t<std::is_floating_point_v<T>>
246 std::complex<ldbl> via;
248 result = std::complex<T>{boost::numeric_cast<
T>(via.real()),
249 boost::numeric_cast<T>(via.imag())};
269 << str <<
"\nat or before:\n" 275 for (
auto const&
e : seq) {
277 result.push_back(via);
285 for (
auto const&
e : seq) {
287 result.push_back(via);
297 template <
typename TUPLE>
303 std::tuple_element_t<0, TUPLE> result_elem;
304 decode(vec.at(0), result_elem);
305 std::get<0>(
result) = result_elem;
309 template <
unsigned IENTRY,
typename TUPLE>
315 std::tuple_element_t<IENTRY, TUPLE> result_elem;
316 decode(vec.at(IENTRY), result_elem);
317 std::get<IENTRY>(
result) = result_elem;
322 template <
typename U>
328 constexpr std::size_t TUPLE_SIZE = std::tuple_size_v<U>;
330 if (seq.size() != TUPLE_SIZE) {
331 std::ostringstream errmsg;
332 errmsg <<
"Number of expected arguments (" << TUPLE_SIZE
333 <<
") does not match " 334 <<
"number of FHiCL sequence entries (" << seq.size() <<
"): [ ";
335 for (
auto ca = seq.begin(); ca != seq.cend(); ++ca) {
339 if (ca != seq.cend() - 1) {
344 throw std::length_error(errmsg.str());
355 result = std::any_cast<
T>(
a);
bool parse_value_string(std::string const &s, extended_value &v, std::string &unparsed)
bool is_a(value_tag const t) const noexcept
ps_atom_t encode(std::string const &)
void decode_tuple(std::any const &, U &tuple)
void decode(std::any const &, std::string &)
std::vector< std::any > ps_sequence_t
std::vector< extended_value > sequence_t
bool is_nil(std::any const &val)
fhicl::extended_value::sequence_t sequence_t
typename disable_if< b, T >::type disable_if_t
bool is_table(std::any const &val)
cet::coded_exception< error, detail::translate > exception
bool is_sequence(std::any const &val)
static void decode_tuple_entry(ps_sequence_t const &, TUPLE &)