zookeeper-cpp
ZooKeeper Client for C++
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups
results.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <zk/config.hpp>
7 
8 #include <iosfwd>
9 #include <string>
10 #include <vector>
11 
12 #include "acl.hpp"
13 #include "buffer.hpp"
14 #include "future.hpp"
15 #include "optional.hpp"
16 #include "types.hpp"
17 
18 namespace zk
19 {
20 
26 class get_result final
27 {
28 public:
29  explicit get_result(buffer data, const zk::stat& stat) noexcept;
30 
31  virtual ~get_result() noexcept;
32 
33  const buffer& data() const & { return _data; }
34  buffer& data() & { return _data; }
35  buffer data() && { return std::move(_data); }
36 
37  const zk::stat& stat() const { return _stat; }
38  zk::stat& stat() { return _stat; }
39 
40 private:
41  buffer _data;
42  zk::stat _stat;
43 };
44 
45 std::ostream& operator<<(std::ostream&, const get_result&);
46 
47 std::string to_string(const get_result&);
48 
51 {
52 public:
53  using children_list_type = std::vector<std::string>;
54 
55 public:
56  explicit get_children_result(children_list_type children, const stat& parent_stat) noexcept;
57 
58  ~get_children_result() noexcept;
59 
60  const children_list_type& children() const & { return _children; }
61  children_list_type& children() & { return _children; }
62  children_list_type children() && { return std::move(_children); }
63 
64  const stat& parent_stat() const { return _parent_stat; }
65  stat& parent_stat() { return _parent_stat; }
66 
67 private:
68  children_list_type _children;
69  stat _parent_stat;
70 };
71 
72 std::ostream& operator<<(std::ostream&, const get_children_result&);
73 
74 std::string to_string(const get_children_result&);
75 
77 class exists_result final
78 {
79 public:
80  explicit exists_result(const optional<zk::stat>& stat) noexcept;
81 
82  ~exists_result() noexcept;
83 
84  explicit operator bool() const { return bool(_stat); }
85  bool operator!() const { return !_stat; }
86 
87  const optional<zk::stat>& stat() const { return _stat; }
88  optional<zk::stat>& stat() { return _stat; }
89 
90 private:
91  optional<zk::stat> _stat;
92 };
93 
94 std::ostream& operator<<(std::ostream&, const exists_result&);
95 
96 std::string to_string(const exists_result&);
97 
99 class create_result final
100 {
101 public:
102  explicit create_result(std::string name) noexcept;
103 
104  ~create_result() noexcept;
105 
106  const std::string& name() const & { return _name; }
107  std::string& name() & { return _name; }
108  std::string name() && { return std::move(_name); }
109 
110 private:
111  std::string _name;
112 };
113 
114 std::ostream& operator<<(std::ostream&, const create_result&);
115 
116 std::string to_string(const create_result&);
117 
119 class set_result final
120 {
121 public:
122  explicit set_result(const zk::stat& stat) noexcept;
123 
124  ~set_result() noexcept;
125 
126  const zk::stat& stat() const { return _stat; }
127  zk::stat& stat() { return _stat; }
128 
129 private:
130  zk::stat _stat;
131 };
132 
133 std::ostream& operator<<(std::ostream&, const set_result&);
134 
135 std::string to_string(const set_result&);
136 
138 class get_acl_result final
139 {
140 public:
141  explicit get_acl_result(zk::acl acl, const zk::stat& stat) noexcept;
142 
143  virtual ~get_acl_result() noexcept;
144 
145  const zk::acl& acl() const & { return _acl; }
146  zk::acl& acl() & { return _acl; }
147  zk::acl acl() && { return std::move(_acl); }
148 
149  const zk::stat& stat() const { return _stat; }
150  zk::stat& stat() { return _stat; }
151 
152 private:
153  zk::acl _acl;
154  zk::stat _stat;
155 };
156 
157 std::ostream& operator<<(std::ostream&, const get_acl_result&);
158 
159 std::string to_string(const get_acl_result&);
160 
171 class event final
172 {
173 public:
174  explicit event(event_type type, zk::state state) noexcept;
175 
177  const event_type& type() const { return _type; }
178 
182  const zk::state& state() const { return _state; }
183 
184 private:
185  event_type _type;
186  zk::state _state;
187 };
188 
189 std::ostream& operator<<(std::ostream&, const event&);
190 
191 std::string to_string(const event&);
192 
194 class watch_result final
195 {
196 public:
197  explicit watch_result(get_result initial, future<event> next) noexcept;
198 
199  watch_result(watch_result&&) = default;
200 
201  ~watch_result() noexcept;
202 
204  const get_result& initial() const & { return _initial; }
205  get_result& initial() & { return _initial; }
206  get_result initial() && { return std::move(_initial); }
207 
209  const future<event>& next() const & { return _next; }
210  future<event>& next() & { return _next; }
211  future<event> next() && { return std::move(_next); }
212 
213 private:
214  get_result _initial;
215  future<event> _next;
216 };
217 
218 std::ostream& operator<<(std::ostream&, const watch_result&);
219 
220 std::string to_string(const watch_result&);
221 
224 {
225 public:
226  explicit watch_children_result(get_children_result initial, future<event> next) noexcept;
227 
229 
230  ~watch_children_result() noexcept;
231 
233  const get_children_result& initial() const & { return _initial; }
234  get_children_result& initial() & { return _initial; }
235  get_children_result initial() && { return std::move(_initial); }
236 
238  const future<event>& next() const & { return _next; }
239  future<event>& next() & { return _next; }
240  future<event> next() && { return std::move(_next); }
241 
242 private:
243  get_children_result _initial;
244  future<event> _next;
245 };
246 
247 std::ostream& operator<<(std::ostream&, const watch_children_result&);
248 
249 std::string to_string(const watch_children_result&);
250 
253 {
254 public:
255  explicit watch_exists_result(exists_result initial, future<event> next) noexcept;
256 
258 
259  ~watch_exists_result() noexcept;
260 
262  const exists_result& initial() const & { return _initial; }
263  exists_result& initial() & { return _initial; }
264  exists_result initial() && { return std::move(_initial); }
265 
267  const future<event>& next() const & { return _next; }
268  future<event>& next() & { return _next; }
269  future<event> next() && { return std::move(_next); }
270 
271 private:
272  exists_result _initial;
273  future<event> _next;
274 };
275 
276 std::ostream& operator<<(std::ostream&, const watch_exists_result&);
277 
278 std::string to_string(const watch_exists_result&);
279 
282 }
Data delivered when a watched event triggers.
Definition: results.hpp:171
state
Enumeration of states the client may be at when a watch triggers.
Definition: types.hpp:320
const future< event > & next() const &
Future to be delivered when the watch is triggered.
Definition: results.hpp:238
The result type of client::get_acl.
Definition: results.hpp:138
The result type of client::watch_exists.
Definition: results.hpp:252
const get_result & initial() const &
The initial result of the fetch.
Definition: results.hpp:204
The result type of client::create.
Definition: results.hpp:99
Controls the import of the optional and nullopt_t types, as well as the nullopt constexpr.
The result type of client::exists.
Definition: results.hpp:77
The result type of client::watch.
Definition: results.hpp:194
The result type of client::watch_children.
Definition: results.hpp:223
Statistics about a znode, similar to the UNIX stat structure.
Definition: types.hpp:191
const get_children_result & initial() const &
The initial result of the fetch.
Definition: results.hpp:233
const exists_result & initial() const &
The initial result of the fetch.
Definition: results.hpp:262
const future< event > & next() const &
Future to be delivered when the watch is triggered.
Definition: results.hpp:267
Controls the import of future and promise types.
The result type of client::set.
Definition: results.hpp:119
const zk::state & state() const
The state of the connection when the event occurred.
Definition: results.hpp:182
event_type
Enumeration of types of events that may occur.
Definition: types.hpp:298
An access control list is a wrapper around acl_rule instances.
Definition: acl.hpp:124
Controls the buffer type.
The result type of client::get_children.
Definition: results.hpp:50
const future< event > & next() const &
Future to be delivered when the watch is triggered.
Definition: results.hpp:209
ZKPP_BUFFER_TYPE buffer
The buffer type.
Definition: buffer.hpp:67
The result type of client::get.
Definition: results.hpp:26
const event_type & type() const
The type of event that occurred.
Definition: results.hpp:177