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 
6  'NameStackRegistry' exists solely because C++ does not have the
7  reflection facilities required to return the members of a struct or
8  class, which is needed to walk through the members of a table. For
9  example, consider the following struct and associated Table<S>
10  object:
11 
12  struct S {
13  Atom<int> n { Name("num") };
14  Sequence<int> l { Name("list") };
15  };
16  Table<S> t { Name("t") };
17 
18  The keys for this type of configuration are:
19 
20  t
21  t.num
22  t.list
23 
24  C++ , however, does not have the ability to do this. The
25  registration system below, however, does do this by taking the Name
26  values above ("t", "num" and "list"), and emplacing them into a
27  container that is assembled when each fhiclcpp parameter is
28  constructed: first 't', then 'n', then 'l'.
29 
30  All fhiclcpp parameters register their names/keys via the
31  ParameterBase base class, which, itself, has a member of type
32  ParameterMetadata that stores the name/key.
33 
34  If the C++ reflection facilities improve to the level that a
35  struct's or class's members can be returned (either at compile-time,
36  or run-time), this registry should be removed.
37 
38 */
39 
40 #include "fhiclcpp/exception.h"
41 #include <iostream>
42 #include <numeric>
43 #include <string>
44 #include <vector>
45 
46 namespace fhicl {
47 
49  public:
51 
52  bool
53  empty() const
54  {
55  return names_.empty();
56  }
57 
59  current() const
60  {
61  return names_.back();
62  }
63 
64  static void
66  {
67  instance().names_.pop_back();
68  }
69 
70  void
72  {
73  names_.clear();
74  }
75 
76  static NameStackRegistry&
78  {
80  return registry;
81  }
82 
83  private:
84  NameStackRegistry() = default;
85  std::vector<std::string> names_{};
86  };
87 }
88 
89 #endif /* fhiclcpp_types_detail_NameStackRegistry_h */
90 
91 // Local variables:
92 // mode: c++
93 // End:
static NameStackRegistry & instance()
std::string current() const
std::string full_key(std::string const &key)
std::vector< std::string > names_
enum BeamMode string