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