zookeeper-cpp
ZooKeeper Client for C++
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
types.cpp
1 #include "types.hpp"
2 
3 #include <ostream>
4 #include <sstream>
5 #include <utility>
6 
7 namespace zk
8 {
9 
11 // event_type //
13 
14 std::ostream& operator<<(std::ostream& os, const event_type& self)
15 {
16  switch (self)
17  {
18  case event_type::error: return os << "error";
19  case event_type::created: return os << "created";
20  case event_type::erased: return os << "erased";
21  case event_type::changed: return os << "changed";
22  case event_type::child: return os << "child";
23  case event_type::session: return os << "session";
24  case event_type::not_watching: return os << "not_watching";
25  default: return os << "event_type(" << static_cast<int>(self) << ')';
26  };
27 }
28 
29 std::string to_string(const event_type& self)
30 {
31  std::ostringstream os;
32  os << self;
33  return os.str();
34 }
35 
37 // version //
39 
40 std::ostream& operator<<(std::ostream& os, const version& self)
41 {
42  os << "version(";
43  if (self == version::any())
44  os << "any";
45  else if (self == version::invalid())
46  os << "invalid";
47  else
48  os << self.value;
49  return os << ')';
50 }
51 
52 std::string to_string(const version& self)
53 {
54  std::ostringstream os;
55  os << self;
56  return os.str();
57 }
58 
60 // acl_version //
62 
63 std::ostream& operator<<(std::ostream& os, const acl_version& self)
64 {
65  os << "acl_version(";
66  if (self == acl_version::any())
67  os << "any";
68  else if (self == acl_version::invalid())
69  os << "invalid";
70  else
71  os << self.value;
72  return os << ')';
73 }
74 
75 std::string to_string(const acl_version& self)
76 {
77  std::ostringstream os;
78  os << self;
79  return os.str();
80 }
81 
83 // child_version //
85 
86 std::ostream& operator<<(std::ostream& os, const child_version& self)
87 {
88  os << "child_version(";
89  if (self == child_version::any())
90  os << "any";
91  else if (self == child_version::invalid())
92  os << "invalid";
93  else
94  os << self.value;
95  return os << ')';
96 }
97 
98 std::string to_string(const child_version& self)
99 {
100  std::ostringstream os;
101  os << self;
102  return os.str();
103 }
104 
106 // transaction_id //
108 
109 std::ostream& operator<<(std::ostream& os, const transaction_id& self)
110 {
111  return os << "transaction_id(" << self.value << ')';
112 }
113 
114 std::string to_string(const transaction_id& self)
115 {
116  std::ostringstream os;
117  os << self;
118  return os.str();
119 }
120 
122 // stat //
124 
125 std::ostream& operator<<(std::ostream& os, const stat& self)
126 {
127  os << "{data_version=" << self.data_version.value;
128  os << " child_version=" << self.child_version.value;
129  os << " acl_version=" << self.acl_version.value;
130  os << " data_size=" << self.data_size;
131  os << " children_count=" << self.children_count;
132  os << " ephemeral=" << (self.is_ephemeral() ? "true" : "false");
133  return os << '}';
134 }
135 
136 std::string to_string(const stat& self)
137 {
138  std::ostringstream os;
139  os << self;
140  return os.str();
141 }
142 
144 // state //
146 
147 std::ostream& operator<<(std::ostream& os, const state& self)
148 {
149  switch (self)
150  {
151  case state::closed: return os << "closed";
152  case state::connecting: return os << "connecting";
153  case state::connected: return os << "connected";
154  case state::read_only: return os << "read_only";
155  case state::expired_session: return os << "expired_session";
156  case state::authentication_failed: return os << "authentication_failed";
157  default: return os << "state(" << static_cast<int>(self) << ')';
158  }
159 }
160 
161 std::string to_string(const state& self)
162 {
163  std::ostringstream os;
164  os << self;
165  return os.str();
166 }
167 
169 // create_mode //
171 
172 std::ostream& operator<<(std::ostream& os, const create_mode& mode)
173 {
174  if (mode == create_mode::normal)
175  return os << "normal";
176 
177  bool first = true;
178  auto tick = [&] { return std::exchange(first, false) ? "" : "|"; };
179  if (is_set(mode, create_mode::ephemeral)) os << tick() << "ephemeral";
180  if (is_set(mode, create_mode::sequential)) os << tick() << "sequential";
181  if (is_set(mode, create_mode::container)) os << tick() << "container";
182 
183  return os;
184 }
185 
186 std::string to_string(const create_mode& self)
187 {
188  std::ostringstream os;
189  os << self;
190  return os.str();
191 }
192 
193 }
This value is issued as part of an event when the state changes.
The client is connected to a read-only server, that is the server which is not currently connected to...
Issued when an entry at a given path is erased.
constexpr bool is_set(create_mode self, create_mode flags)
Check that self has flags set.
Definition: types.hpp:321
The client is not connected to any server in the ensemble.
state
Enumeration of states the client may be at when a watch triggers.
Definition: types.hpp:385
The client is connecting.
create_mode
When used in client::set, this value determines how the entry is created on the server.
Definition: types.hpp:283
Authentication has failed – connection requires a new connection instance with different credentials...
Standard behavior of an entry – the opposite of doing any of the options.
The client is in the connected state – it is connected to a server in the ensemble (one of the serve...
The entry will be deleted when the client session expires.
Invalid event (this should never be issued).
Issued when an entry for a given path is created.
Issued when the data of a watched entry is altered.
The serving cluster has expired this session.
Watch has been forcefully removed.
event_type
Enumeration of types of events that may occur.
Definition: types.hpp:331
The name of the entry will be appended with a monotonically increasing number.
static constexpr version any()
When specified in an operation, this version specifier will always pass.
Definition: types.hpp:150
static constexpr version invalid()
An invalid version specifier.
Definition: types.hpp:145
Container entries are special purpose entries useful for recipes such as leader, lock, etc.
Issued when the children of a watched entry are created or deleted.