Name.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_Name_h
2 #define fhiclcpp_types_Name_h
3 
4 #include <regex>
5 #include <string>
6 
7 namespace fhicl {
8 
10 
11  struct Name {
12 
13  explicit Name(std::string const& name = "") : value(name) {}
15 
16  static Name
17  sequence_element(std::size_t const i)
18  {
19  return Name{index(i)};
20  }
21 
22  static Name
23  sequence_element(std::string const& key_stem, std::size_t const i)
24  {
25  return Name{key_stem + index(i)};
26  }
27 
28  // Sometimes the key has '[' and ']' literals in it. Those must be
29  // padded with an escape character so the regex library doesn't
30  // think we're trying to specify a character set.
31  static std::string
33  {
34  return fhicl::get_regex_replace_str(key);
35  }
36 
37  private:
38  static std::string
39  index(std::size_t const i)
40  {
41  return "[" + std::to_string(i) + "]";
42  }
43  };
44 }
45 
46 #endif /* fhiclcpp_types_Name_h */
47 
48 // Local variables:
49 // mode: c++
50 // End:
static Name sequence_element(std::string const &key_stem, std::size_t const i)
Definition: Name.h:23
const XML_Char * name
Definition: expat.h:151
Name(std::string const &name="")
Definition: Name.h:13
const XML_Char int const XML_Char * value
Definition: expat.h:331
std::string value
Definition: Name.h:14
std::string const get_regex_replace_str(std::string const &str)
static Name sequence_element(std::size_t const i)
Definition: Name.h:17
static std::string regex_safe(std::string const &key)
Definition: Name.h:32
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
static std::string index(std::size_t const i)
Definition: Name.h:39