zookeeper-cpp
ZooKeeper Client for C++
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
results.hpp
Go to the documentation of this file.
1 #pragma once
4 
5 #include <zk/config.hpp>
6 
7 #include <iosfwd>
8 #include <string>
9 #include <vector>
10 
11 #include "acl.hpp"
12 #include "buffer.hpp"
13 #include "future.hpp"
14 #include "optional.hpp"
15 #include "types.hpp"
16 
17 namespace zk
18 {
19 
22 
24 class get_result final
25 {
26 public:
27  explicit get_result(buffer data, const zk::stat& stat) noexcept;
28 
29  ~get_result() noexcept;
30 
33  const buffer& data() const & { return _data; }
34  buffer& data() & { return _data; }
35  buffer data() && { return std::move(_data); }
37 
41  const zk::stat& stat() const { return _stat; }
42  zk::stat& stat() { return _stat; }
44 
45 private:
46  buffer _data;
47  zk::stat _stat;
48 };
49 
50 std::ostream& operator<<(std::ostream&, const get_result&);
51 
52 std::string to_string(const get_result&);
53 
56 {
57 public:
58  using children_list_type = std::vector<std::string>;
59 
60 public:
61  explicit get_children_result(children_list_type children, const stat& parent_stat) noexcept;
62 
63  ~get_children_result() noexcept;
64 
67  const children_list_type& children() const & { return _children; }
68  children_list_type& children() & { return _children; }
69  children_list_type children() && { return std::move(_children); }
71 
74  const stat& parent_stat() const { return _parent_stat; }
75  stat& parent_stat() { return _parent_stat; }
77 
78 private:
79  children_list_type _children;
80  stat _parent_stat;
81 };
82 
83 std::ostream& operator<<(std::ostream&, const get_children_result&);
84 
85 std::string to_string(const get_children_result&);
86 
88 class exists_result final
89 {
90 public:
91  explicit exists_result(const optional<zk::stat>& stat) noexcept;
92 
93  ~exists_result() noexcept;
94 
97  explicit operator bool() const { return bool(_stat); }
98  bool operator!() const { return !_stat; }
100 
103  const optional<zk::stat>& stat() const { return _stat; }
104  optional<zk::stat>& stat() { return _stat; }
106 
107 private:
108  optional<zk::stat> _stat;
109 };
110 
111 std::ostream& operator<<(std::ostream&, const exists_result&);
112 
113 std::string to_string(const exists_result&);
114 
116 class create_result final
117 {
118 public:
119  explicit create_result(std::string name) noexcept;
120 
121  ~create_result() noexcept;
122 
127  const std::string& name() const & { return _name; }
128  std::string& name() & { return _name; }
129  std::string name() && { return std::move(_name); }
131 
132 private:
133  std::string _name;
134 };
135 
136 std::ostream& operator<<(std::ostream&, const create_result&);
137 
138 std::string to_string(const create_result&);
139 
141 class set_result final
142 {
143 public:
144  explicit set_result(const zk::stat& stat) noexcept;
145 
146  ~set_result() noexcept;
147 
150  const zk::stat& stat() const { return _stat; }
151  zk::stat& stat() { return _stat; }
153 
154 private:
155  zk::stat _stat;
156 };
157 
158 std::ostream& operator<<(std::ostream&, const set_result&);
159 
160 std::string to_string(const set_result&);
161 
163 class get_acl_result final
164 {
165 public:
166  explicit get_acl_result(zk::acl acl, const zk::stat& stat) noexcept;
167 
168  virtual ~get_acl_result() noexcept;
169 
172  const zk::acl& acl() const & { return _acl; }
173  zk::acl& acl() & { return _acl; }
174  zk::acl acl() && { return std::move(_acl); }
176 
180  const zk::stat& stat() const { return _stat; }
181  zk::stat& stat() { return _stat; }
183 
184 private:
185  zk::acl _acl;
186  zk::stat _stat;
187 };
188 
189 std::ostream& operator<<(std::ostream&, const get_acl_result&);
190 
191 std::string to_string(const get_acl_result&);
192 
202 class event final
203 {
204 public:
205  explicit event(event_type type, zk::state state) noexcept;
206 
208  const event_type& type() const { return _type; }
209 
212  const zk::state& state() const { return _state; }
213 
214 private:
215  event_type _type;
216  zk::state _state;
217 };
218 
219 std::ostream& operator<<(std::ostream&, const event&);
220 
221 std::string to_string(const event&);
222 
224 class watch_result final
225 {
226 public:
227  explicit watch_result(get_result initial, future<event> next) noexcept;
228 
229  watch_result(watch_result&&) = default;
230 
231  ~watch_result() noexcept;
232 
235  const get_result& initial() const & { return _initial; }
236  get_result& initial() & { return _initial; }
237  get_result initial() && { return std::move(_initial); }
239 
242  const future<event>& next() const & { return _next; }
243  future<event>& next() & { return _next; }
244  future<event> next() && { return std::move(_next); }
246 
247 private:
248  get_result _initial;
249  future<event> _next;
250 };
251 
252 std::ostream& operator<<(std::ostream&, const watch_result&);
253 
254 std::string to_string(const watch_result&);
255 
258 {
259 public:
260  explicit watch_children_result(get_children_result initial, future<event> next) noexcept;
261 
263 
264  ~watch_children_result() noexcept;
265 
268  const get_children_result& initial() const & { return _initial; }
269  get_children_result& initial() & { return _initial; }
270  get_children_result initial() && { return std::move(_initial); }
272 
275  const future<event>& next() const & { return _next; }
276  future<event>& next() & { return _next; }
277  future<event> next() && { return std::move(_next); }
279 
280 private:
281  get_children_result _initial;
282  future<event> _next;
283 };
284 
285 std::ostream& operator<<(std::ostream&, const watch_children_result&);
286 
287 std::string to_string(const watch_children_result&);
288 
291 {
292 public:
293  explicit watch_exists_result(exists_result initial, future<event> next) noexcept;
294 
296 
297  ~watch_exists_result() noexcept;
298 
301  const exists_result& initial() const & { return _initial; }
302  exists_result& initial() & { return _initial; }
303  exists_result initial() && { return std::move(_initial); }
305 
308  const future<event>& next() const & { return _next; }
309  future<event>& next() & { return _next; }
310  future<event> next() && { return std::move(_next); }
312 
313 private:
314  exists_result _initial;
315  future<event> _next;
316 };
317 
318 std::ostream& operator<<(std::ostream&, const watch_exists_result&);
319 
320 std::string to_string(const watch_exists_result&);
321 
323 
324 }
Data delivered when a watched event triggers.
Definition: results.hpp:202
state
Enumeration of states the client may be at when a watch triggers.
Definition: types.hpp:385
const zk::stat & stat() const
Definition: results.hpp:150
const future< event > & next() const &
Definition: results.hpp:275
The result type of client::get_acl.
Definition: results.hpp:163
The result type of client::watch_exists.
Definition: results.hpp:290
const get_result & initial() const &
Definition: results.hpp:235
The result type of client::create.
Definition: results.hpp:116
const zk::stat & stat() const
Definition: results.hpp:180
Imports of optional and nullopt_t types, as well as the nullopt constexpr.
The result type of client::exists.
Definition: results.hpp:88
const buffer & data() const &
Definition: results.hpp:33
The result type of client::watch.
Definition: results.hpp:224
const zk::acl & acl() const &
Definition: results.hpp:172
The result type of client::watch_children.
Definition: results.hpp:257
const zk::stat & stat() const
Definition: results.hpp:41
Statistics about a ZooKeeper entry, similar to the UNIX stat structure.
Definition: types.hpp:220
const children_list_type & children() const &
Definition: results.hpp:67
const optional< zk::stat > & stat() const
Definition: results.hpp:103
const get_children_result & initial() const &
Definition: results.hpp:268
const exists_result & initial() const &
Definition: results.hpp:301
const future< event > & next() const &
Definition: results.hpp:308
Controls the import of future and promise types.
The result type of client::set.
Definition: results.hpp:141
const zk::state & state() const
The state of the connection when the event occurred.
Definition: results.hpp:212
const std::string & name() const &
Definition: results.hpp:127
event_type
Enumeration of types of events that may occur.
Definition: types.hpp:331
An access control list is a wrapper around acl_rule instances.
Definition: acl.hpp:139
Controls the buffer type.
The result type of client::get_children.
Definition: results.hpp:55
const future< event > & next() const &
Definition: results.hpp:242
const stat & parent_stat() const
Definition: results.hpp:74
ZKPP_BUFFER_TYPE buffer
The buffer type.
Definition: buffer.hpp:79
The result type of client::get.
Definition: results.hpp:24
const event_type & type() const
The type of event that occurred.
Definition: results.hpp:208