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 
61 #include "boost/any.hpp"
63 #include "fhiclcpp/coding.h"
64 
65 #include <string>
66 #include <vector>
67 
68 namespace fhicl {
69  namespace detail {
70 
71  using key_t = std::string;
73 
75  public:
76  std::vector<key_t> const&
78  {
79  return keys_;
80  }
81 
82  private:
83  void enter_table(key_t const&, any_t const&) override;
84  void exit_table(key_t const&, any_t const&) override;
85 
86  void enter_sequence(key_t const&, any_t const&) override;
87  void atom(key_t const&, any_t const&) override;
88 
89  std::string full_key_(name_t const&) const;
90 
91  std::vector<key_t> keys_{};
92  std::vector<name_t> name_stack_{};
93  };
94  }
95 }
96 
97 #endif /* fhiclcpp_detail_KeyAssembler_h */
98 
99 // Local variables:
100 // mode: c++
101 // End:
std::vector< name_t > name_stack_
Definition: KeyAssembler.h:92
void exit_table(key_t const &, any_t const &) override
std::string name_t
Definition: KeyAssembler.h:72
void atom(key_t const &, any_t const &) override
void enter_table(key_t const &, any_t const &) override
std::string full_key_(name_t const &) const
void enter_sequence(key_t const &, any_t const &) override
std::vector< key_t > const & result()
Definition: KeyAssembler.h:77
std::string key_t
Definition: KeyAssembler.h:71
std::vector< key_t > keys_
Definition: KeyAssembler.h:91
enum BeamMode string