LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TableMemberRegistry.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_detail_TableMemberRegistry_h
2 #define fhiclcpp_types_detail_TableMemberRegistry_h
3 
4 // ========================================================================
5 // 'TableMemberRegistry' exists solely because C++ does not have the
6 // reflection facilities required to return the members of a struct or
7 // class, which is needed to walk through the members of a table. For
8 // example, consider the following struct and associated Table<S>
9 // object:
10 //
11 // struct S {
12 // Atom<int> num{Name("num")};
13 // Sequence<int> list{Name("list")};
14 // };
15 // Table<S> t{Name("t")};
16 //
17 // C++ does not have the ability to return the list of data members
18 // for the struct 'S'. The registration system below, however, does
19 // do this by taking the Name values above ("num" and "list"), and
20 // emplacing them into a container corresponding to the table members
21 // associated with 't'.
22 //
23 // The way this registry is used is via private inheritance of a
24 // 'RegisterIfTableMember' auxiliary class. Each fhiclcpp parameter
25 // type (Atom, Sequence, etc.), inherits from the auxiliary class.
26 //
27 // If the C++ reflection facilities improve to the level that a
28 // struct's or class's members can be returned (either at
29 // compile-time, or run-time), this registry should be removed.
30 // =============================================================================
31 
32 #include "cetlib/exempt_ptr.h"
33 #include "fhiclcpp/fwd.h"
35 
36 #include <stack>
37 #include <vector>
38 
39 namespace fhicl::detail {
40 
41  class RegisterIfTableMember;
42  class TableBase;
43 
44  // All-private class that only fhicl::detail::RegisterIfTableMember
45  // and fhicl::detail::TableBase can access via friendship.
46 
48 
49  using base_ptr = cet::exempt_ptr<ParameterBase>;
50  using table_members_t = std::vector<base_ptr>;
51  std::stack<table_members_t> tables_;
52 
54 
55  // Retrieval facilities for fhicl::(Optional)Table
56  friend class TableBase;
57 
58  static std::vector<base_ptr> release_members();
59 
60  // Registration facilities
61  friend class RegisterIfTableMember;
62 
63  static void emplace_table_member(ParameterBase* pb);
64  static void new_table();
65  };
66 
67  //========================================================
69  public:
71  };
72 } // namespace fhicl::detail
73 
74 #endif /* fhiclcpp_types_detail_TableMemberRegistry_h */
75 
76 // Local variables:
77 // mode: c++
78 // End:
static TableMemberRegistry & instance_()
std::stack< table_members_t > tables_
std::vector< base_ptr > table_members_t
static void emplace_table_member(ParameterBase *pb)
static std::vector< base_ptr > release_members()
cet::exempt_ptr< ParameterBase > base_ptr