LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
NameStackRegistry.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_detail_NameStackRegistry_h
2 #define fhiclcpp_types_detail_NameStackRegistry_h
3 
4 // ======================================================================
5 // 'NameStackRegistry' 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 // The keys for this type of configuration are:
18 //
19 // t
20 // t.num
21 // t.list
22 //
23 // C++ , however, does not have the ability to do this. The
24 // registration system below, however, does do this by taking the Name
25 // values above ("t", "num" and "list"), and emplacing them into a
26 // container that is assembled when each fhiclcpp parameter is
27 // constructed: first 't', then 'n', then 'l'.
28 //
29 // All fhiclcpp parameters register their names/keys via the
30 // ParameterBase base class, which, itself, has a member of type
31 // ParameterMetadata that stores the name/key.
32 //
33 // If the C++ reflection facilities improve to the level that a
34 // struct's or class's members can be returned (either at
35 // compile-time, or run-time), this registry should be removed.
36 // ======================================================================
37 
38 #include <string>
39 #include <vector>
40 
41 namespace fhicl {
42 
44  public:
45  static std::string full_key(std::string const& key);
46 
47  static void end_of_ctor();
48  static void clear();
49  static bool empty();
50  static std::string current();
51 
52  private:
53  std::vector<std::string> names_{};
54 
55  static NameStackRegistry& instance_();
56  };
57 }
58 
59 #endif /* fhiclcpp_types_detail_NameStackRegistry_h */
60 
61 // Local variables:
62 // mode: c++
63 // End:
static NameStackRegistry & instance_()
static std::string current()
parameter set interface
static std::string full_key(std::string const &key)
std::vector< std::string > names_