LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
SearchAllowedConfiguration.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_detail_SearchAllowedConfiguration_h
2 #define fhiclcpp_types_detail_SearchAllowedConfiguration_h
3 
4 // ============================================================================
5 //
6 // SearchAllowedConfiguration
7 //
8 // This class provides an interface for determining if a supplied
9 // ParameterBase object supports a specified key.
10 //
11 // Implemented behavior:
12 //
13 // - All querying of allowed configurations happens through the
14 // static member function 'supports_key' (the default c'tor of
15 // SearchAllowedConfiguration is private).
16 //
17 // - The supplied key is interpreted to be relative to the
18 // ParameterBase object's key. For example, if the key of the
19 // ParameterBase object is 'table1.table2', and the user
20 // specifies:
21 //
22 // bool const result {SearchAllowedConfiguration::supports_key(pb,
23 // "atom")};
24 //
25 // then the searched-for key is "table.table2.atom".
26 //
27 // - Specifying a ParameterBase object that is not of sequence type
28 // or table type throws an exception.
29 //
30 // - Specifying an empty searched-for key throws an exception.
31 //
32 // The searching happens by using the fhicl::detail::ParameterWalker
33 // interface. With the current implementation, if a match is found,
34 // the walker continues checking for matches for the rest of the
35 // parameters of the given nesting level, without descending further.
36 // This is an inefficiency that should be optimized if the need
37 // arises. Note, however, that the only way to completely stop a tree
38 // walk with the current implementation is to throw an exception,
39 // which we do not do.
40 //
41 // ============================================================================
42 
43 #include "fhiclcpp/type_traits.h"
46 
47 #include <string>
48 
49 namespace fhicl {
50  namespace detail {
51 
53  : public ParameterWalker<tt::const_flavor::require_const> {
54  public:
55  static bool supports_key(ParameterBase const& pb,
56  std::string const& searched_for_key);
57 
58  private:
59  std::string key_;
60  bool supportsKey_{false};
61 
63  std::string const& searched_for_key);
64 
65  bool
66  result() const
67  {
68  return supportsKey_;
69  };
70 
71  bool before_action(ParameterBase const& pb) override;
72  void
73  enter_table(TableBase const&) override
74  {}
75  void
76  enter_sequence(SequenceBase const&) override
77  {}
78  void
79  atom(AtomBase const&) override
80  {}
81  void
83  {}
84 
85  static std::string form_absolute(ParameterBase const& pb,
86  std::string const& searched_for_key);
87  };
88  }
89 }
90 
91 #endif /* fhiclcpp_types_detail_SearchAllowedConfiguration_h */
92 
93 // Local variables:
94 // mode: c++
95 // End:
static std::string form_absolute(ParameterBase const &pb, std::string const &searched_for_key)
void enter_sequence(SequenceBase const &) override
parameter set interface
bool before_action(ParameterBase const &pb) override
SearchAllowedConfiguration(ParameterBase const &pb, std::string const &searched_for_key)
void delegated_parameter(DelegateBase const &) override
static bool supports_key(ParameterBase const &pb, std::string const &searched_for_key)