quantities_fhicl.h
Go to the documentation of this file.
1 /**
2  * @file lardataalg/Utilities/quantities_fhicl.h
3  * @brief Utilities to read and write quantities in FHiCL configuration.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date November 27, 2019
6  *
7  */
8 
9 #ifndef LARDATAALG_UTILITIES_QUANTITIES_FHICL_H
10 #define LARDATAALG_UTILITIES_QUANTITIES_FHICL_H
11 
12 // LArSoft libraries
14 #include "larcorealg/CoreUtils/StdUtils.h" // util::to_string()
15 
16 // support libraries
17 #include "fhiclcpp/coding.h"
18 
19 // C++ libraries
20 #include <string_view>
21 #include <string>
22 #include <any>
23 
24 
26 
27  // --- BEGIN -- FHiCL encoding ---------------------------------------------
28  /// @name FHiCL encoding
29  /// @{
30 
31  // these utilities need to be defined in the same namespace as `Quantity`
32 
33  /**
34  * @brief Decodes a quantity.
35  * @tparam Args types defining the quantity type
36  * @param src the data to decode
37  * @param q the quantity where to store the result
38  * @throw std::bad_any_cast if `src` does not provide the necessary data
39  *
40  * This function fills the object `q` with information decoded from `src`.
41  *
42  * The decoding happens with `util::quantities::makeQuantity()`.
43  *
44  * @note The signature of this function is dictated by FHiCL requirements.
45  */
46  template <typename... Args>
47  void decode(std::any const& src, Quantity<Args...>& q);
48 
49 
50  /**
51  * @brief Encodes a quantity into a FHiCL parameter set atom.
52  * @tparam Args types defining the quantity type
53  * @param q the quantity to be encoded
54  * @return the quantity encoded into a FHiCL parameter set atom
55  *
56  * This function returns a parameter set atom with the content of the quantity
57  * `q`.
58  *
59  * @note The signature of this function is dictated by FHiCL requirements.
60  */
61  template <typename... Args>
62  ::fhicl::detail::ps_atom_t encode(Quantity<Args...> const& q);
63 
64  /// @}
65  // --- END -- FHiCL encoding -----------------------------------------------
66 
67 } // namespace util::quantities::concepts
68 
69 
70 // -----------------------------------------------------------------------------
71 // --- template implementation
72 // -----------------------------------------------------------------------------
73 template <typename... Args>
75  (std::any const& src, Quantity<Args...>& q)
76 {
77  using quantity_t = Quantity<Args...>;
78 
79  std::string s;
81 
82  q = util::quantities::makeQuantity<quantity_t>(s);
83 
84 } // util::quantities::concepts::decode(Quantity)
85 
86 
87 // -----------------------------------------------------------------------------
88 template <typename... Args>
90  (Quantity<Args...> const& q)
91 {
93 } // util::quantities::concepts::encode()
94 
95 
96 // -----------------------------------------------------------------------------
97 
98 
99 #endif // LARDATAALG_UTILITIES_QUANTITIES_FHICL_H
std::string string
Definition: nybbler.cc:12
::fhicl::detail::ps_atom_t encode(Interval< Args... > const &iv)
Encodes a quantity interval into a FHiCL parameter set atom.
Infrastructure for the quantities library.
Definition: intervals.h:26
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
A value measured in the specified unit.
Definition: quantities.h:566
::fhicl::detail::ps_atom_t encode(Quantity< Args... > const &q)
Encodes a quantity into a FHiCL parameter set atom.
void decode(std::any const &src, Interval< Args... > &iv)
Decodes an interval.
Numeric variable proxies with embedded unit of measurement.
std::string ps_atom_t
Definition: coding.h:44
Functions pulling in STL customization if available.
void decode(std::any const &src, Quantity< Args... > &q)
Decodes a quantity.
static QCString * s
Definition: config.cpp:1042