TableFragment.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_TableFragment_h
2 #define fhiclcpp_types_TableFragment_h
3 
4 /*
5  'TableFragment' is an auxiliary class used to support the situation
6  where a user has a parameter set that looks like:
7 
8  pset: {
9 
10  a1 : <value>
11  a2 : <value>
12 
13  b3 : <value>
14  b4 : <value>
15 
16  }
17 
18  where the "a*" parameters are used by algorithm/class 'A' and the
19  "b*" parameters are used by algorithm/class 'B'. Specifically, it
20  allows users to define separate configurations for 'A' and 'B'
21  (using shorthand):
22 
23  struct A { Atom<T> a1; Atom<T> a2; };
24  struct B { Atom<T> b1; Atom<T> b2; };
25 
26  with a full configuration that looks like:
27 
28  struct Config {
29  TableFragment<A> a;
30  TableFragment<B> b;
31  };
32 
33  In this way, the parameters used by 'A' are separated from those
34  used by 'B', even though FHiCL configuration for 'pset' is flat.
35 
36  A 'TableFragment' is not a fhiclcpp type, per se, since it does not
37  represent a meaningful FHiCL construct. It does not derive from
38  ParameterBase, nor is it registered anywhere.
39 */
40 
41 #include "fhiclcpp/type_traits.h"
43 
44 namespace fhicl {
45 
46  //========================================================
47  template <typename T>
48  class TableFragment final {
49  public:
50  static_assert(!tt::is_sequence_type_v<T>, NO_STD_CONTAINERS);
51  static_assert(!tt::is_fhicl_type_v<T>, NO_NESTED_FHICL_TYPES_IN_TABLE);
52  static_assert(!tt::is_table_fragment_v<T>, NO_NESTED_TABLE_FRAGMENTS);
53  static_assert(std::is_class_v<T>, REQUIRE_CLASS_TABLE_FRAGMENT);
54  static_assert(!tt::is_delegated_parameter_v<T>, NO_DELEGATED_PARAMETERS);
55 
56  // Compiler-produced default c'tor (and friends) is fine since 'T'
57  // is of class type.
58 
59  auto const&
60  operator()() const
61  {
62  return value_;
63  }
64 
65  private:
67  };
68 }
69 
70 #endif /* fhiclcpp_types_TableFragment_h */
71 
72 // Local variables:
73 // mode: c++
74 // End:
#define REQUIRE_CLASS_TABLE_FRAGMENT
#define NO_DELEGATED_PARAMETERS
#define NO_NESTED_FHICL_TYPES_IN_TABLE
auto const & operator()() const
Definition: TableFragment.h:60
#define NO_STD_CONTAINERS
#define NO_NESTED_TABLE_FRAGMENTS