Horizon
uuid_path.hpp
1 #pragma once
2 #include "uuid.hpp"
3 #include <array>
4 #include <iostream>
5 
6 namespace horizon {
7 
13 template <unsigned int N> class UUIDPath {
14 public:
15  UUIDPath()
16  {
17  }
18  UUIDPath(const UUID &uu) : path({uu, uu})
19  {
20  }
21  UUIDPath(const UUID &uu0, const UUID &uu1) : path({uu0, uu1})
22  {
23  }
24  UUIDPath(const UUID &uu0, const UUID &uu1, const UUID &uu2) : path({uu0, uu1, uu2})
25  {
26  }
30  UUIDPath(const std::string &str)
31  {
32  if (N == 1) {
33  path[0] = str;
34  }
35  if (N == 2) {
36  path[0] = str.substr(0, 36);
37  path[1] = str.substr(37, 36);
38  }
39  }
44  operator std::string() const
45  {
46  if (N == 1) {
47  return path[0];
48  }
49  if (N == 2) {
50  return (std::string)path[0] + "/" + (std::string)path[1];
51  }
52  }
53  bool operator<(const UUIDPath<N> &other) const
54  {
55  for (unsigned int i(0); i < N; i++) {
56  if (path[i] < other.path[i]) {
57  return true;
58  }
59  if (path[i] > other.path[i]) {
60  return false;
61  }
62  }
63  return false;
64  }
65  bool operator==(const UUIDPath<N> &other) const
66  {
67  for (unsigned int i(0); i < N; i++) {
68  if (path[i] != other.path[i]) {
69  return false;
70  }
71  }
72  return true;
73  }
74  const UUID &at(unsigned int i) const
75  {
76  return path.at(i);
77  }
78 
79 private:
80  std::array<UUID, 3> path;
81 };
82 } // namespace horizon
horizon::UUIDPath::UUIDPath
UUIDPath(const std::string &str)
Constructs UUIDPath from up to two UUIDs separated by a /.
Definition: uuid_path.hpp:30
horizon::UUIDPath
Stores a sequence of up to 3 UUIDs.
Definition: uuid_path.hpp:13