KeyAssembler.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_detail_KeyAssembler_h
2 #define fhiclcpp_detail_KeyAssembler_h
3 
4 /*
5  ======================================================================
6 
7  KeyAssembler
8 
9  ======================================================================
10 
11  Class used when
12 
13  'ParameterSet::get_all_keys()'
14 
15  is called. This class provides an 'std::vector<std::string>' representing
16  the entire (nested) list of keys corresponding to a ParameterSet object.
17 
18  For a FHiCL configuration of the type:
19 
20  p1: {}
21  p3: {
22  a: else
23  b: []
24  d: [ 11, 12 ]
25  p4: { e: f }
26  g: [ {h1: i1}, {h2: i2} ]
27  }
28 
29  The following list of keys will be returned (in some order):
30 
31  p1
32  p3
33  p3.a
34  p3.b
35  p3.d
36  p3.d[0]
37  p3.d[1]
38  p3.p4
39  p3.p4.e
40  p3.g
41  p3.g[0]
42  p3.g[0].h1
43  p3.g[1]
44  p3.g[1].h2
45 
46  Maintenance notes:
47  ==================
48 
49  [1] The std::vector<name_t> object is used to keep track of the
50  stacked FHiCL names. This series of names is stitched together
51  to form the full key. The reason this object is not of type
52  std::stack is that we need to be able to iterate through each of
53  the stack elements to create the full key, which is not doable
54  with an std::stack object.
55 
56  To use this class correctly, the name stack must be updated
57  during each {enter,exit}_table call.
58 
59 */
60 
62 
63 #include <any>
64 #include <string>
65 #include <vector>
66 
67 namespace fhicl::detail {
68 
69  using key_t = std::string;
71 
73  public:
74  std::vector<key_t> const&
76  {
77  return keys_;
78  }
79 
80  private:
81  void enter_table(key_t const&, std::any const&) override;
82  void exit_table(key_t const&, std::any const&) override;
83 
84  void enter_sequence(key_t const&, std::any const&) override;
85  void atom(key_t const&, std::any const&) override;
86 
87  std::string full_key_(name_t const&) const;
88 
89  std::vector<key_t> keys_{};
90  std::vector<name_t> name_stack_{};
91  };
92 }
93 
94 #endif /* fhiclcpp_detail_KeyAssembler_h */
95 
96 // Local variables:
97 // mode: c++
98 // End:
std::string string
Definition: nybbler.cc:12
std::vector< name_t > name_stack_
Definition: KeyAssembler.h:90
std::string name_t
Definition: KeyAssembler.h:70
void atom(key_t const &, std::any const &) override
Definition: KeyAssembler.cc:38
void exit_table(key_t const &, std::any const &) override
Definition: KeyAssembler.cc:26
std::string full_key_(name_t const &) const
Definition: KeyAssembler.cc:10
std::vector< key_t > const & result()
Definition: KeyAssembler.h:75
void enter_sequence(key_t const &, std::any const &) override
Definition: KeyAssembler.cc:32
std::string key_t
Definition: KeyAssembler.h:69
std::vector< key_t > keys_
Definition: KeyAssembler.h:89
void enter_table(key_t const &, std::any const &) override
Definition: KeyAssembler.cc:19