LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PathSpec.h
Go to the documentation of this file.
1 #ifndef art_Persistency_Provenance_PathSpec_h
2 #define art_Persistency_Provenance_PathSpec_h
3 
4 #include <iosfwd>
5 #include <limits>
6 #include <string>
7 #include <tuple>
8 #include <utility>
9 #include <vector>
10 
11 namespace art {
12  // Process name <-> Path name
13  std::pair<std::string, std::string> split_process_and_path_names(
14  std::string path_spec);
15 
16  class PathID {
17  public:
18  constexpr explicit PathID(size_t const i) noexcept : id_{i} {}
19 
20  constexpr auto static invalid() noexcept { return PathID{}; }
21 
22  constexpr bool
23  operator==(PathID const other) const noexcept
24  {
25  return id_ == other.id_;
26  }
27 
28  constexpr bool
29  operator!=(PathID const other) const noexcept
30  {
31  return not operator==(other);
32  }
33 
34  constexpr bool
35  operator<(PathID const other) const noexcept
36  {
37  return id_ < other.id_;
38  }
39 
40  friend std::string to_string(PathID);
41 
42  private:
43  constexpr PathID() = default;
44  size_t id_{std::numeric_limits<size_t>::max()};
45  };
46 
47  struct PathSpec {
48  std::string name;
50  };
51 
52  inline auto
53  to_tuple(PathSpec const& spec) noexcept
54  {
55  return std::tie(spec.name, spec.path_id);
56  }
57 
58  inline bool
59  operator==(PathSpec const& a, PathSpec const& b)
60  {
61  return to_tuple(a) == to_tuple(b);
62  }
63 
64  inline bool
65  operator<(PathSpec const& a, PathSpec const& b)
66  {
67  return to_tuple(a) < to_tuple(b);
68  }
69 
70  // Conversion facilities for PathSpec <-> stringized form
71  std::string to_string(PathID id);
72  std::string to_string(PathSpec const& spec);
73  PathSpec path_spec(std::string const& path_spec_str);
74  std::vector<PathSpec> path_specs(
75  std::vector<std::string> const& path_spec_strs);
76  std::ostream& operator<<(std::ostream& os, PathSpec const& spec);
77 }
78 
79 #endif /* art_Persistency_Provenance_PathSpec_h */
80 
81 // Local Variables:
82 // mode: c++
83 // End:
PathID path_id
Definition: PathSpec.h:49
friend std::string to_string(PathID)
Definition: PathSpec.cc:49
auto to_tuple(PathSpec const &spec) noexcept
Definition: PathSpec.h:53
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
constexpr PathID(size_t const i) noexcept
Definition: PathSpec.h:18
std::vector< PathSpec > path_specs(std::vector< std::string > const &path_spec_strs)
Definition: PathSpec.cc:34
size_t id_
Definition: PathSpec.h:44
constexpr bool operator<(PathID const other) const noexcept
Definition: PathSpec.h:35
std::string name
Definition: PathSpec.h:48
constexpr bool operator==(PathID const other) const noexcept
Definition: PathSpec.h:23
constexpr bool operator!=(PathID const other) const noexcept
Definition: PathSpec.h:29
constexpr static auto invalid() noexcept
Definition: PathSpec.h:20
constexpr PathID()=default
Definition: MVAAlg.h:12
PathSpec path_spec(std::string const &path_spec)
Definition: PathSpec.cc:22
std::pair< std::string, std::string > split_process_and_path_names(std::string path_spec)
Definition: PathSpec.cc:11