zookeeper-cpp
ZooKeeper Client for C++
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 
61  const children_list_type& children() const & { return _children; }
62  children_list_type& children() & { return _children; }
63  children_list_type children() && { return std::move(_children); }
64 
66  const stat& parent_stat() const { return _parent_stat; }
67  stat& parent_stat() { return _parent_stat; }
68 
69 private:
70  children_list_type _children;
71  stat _parent_stat;
72 };
73 
74 std::ostream& operator<<(std::ostream&, const get_children_result&);
75 
76 std::string to_string(const get_children_result&);
77 
79 class exists_result final
80 {
81 public:
82  explicit exists_result(const optional<zk::stat>& stat) noexcept;
83 
84  ~exists_result() noexcept;
85 
86  explicit operator bool() const { return bool(_stat); }
87  bool operator!() const { return !_stat; }
88 
89  const optional<zk::stat>& stat() const { return _stat; }
90  optional<zk::stat>& stat() { return _stat; }
91 
92 private:
93  optional<zk::stat> _stat;
94 };
95 
96 std::ostream& operator<<(std::ostream&, const exists_result&);
97 
98 std::string to_string(const exists_result&);
99 
101 class create_result final
102 {
103 public:
104  explicit create_result(std::string name) noexcept;
105 
106  ~create_result() noexcept;
107 
110  const std::string& name() const & { return _name; }
111  std::string& name() & { return _name; }
112  std::string name() && { return std::move(_name); }
113 
114 private:
115  std::string _name;
116 };
117 
118 std::ostream& operator<<(std::ostream&, const create_result&);
119 
120 std::string to_string(const create_result&);
121 
123 class set_result final
124 {
125 public:
126  explicit set_result(const zk::stat& stat) noexcept;
127 
128  ~set_result() noexcept;
129 
130  const zk::stat& stat() const { return _stat; }
131  zk::stat& stat() { return _stat; }
132 
133 private:
134  zk::stat _stat;
135 };
136 
137 std::ostream& operator<<(std::ostream&, const set_result&);
138 
139 std::string to_string(const set_result&);
140 
142 class get_acl_result final
143 {
144 public:
145  explicit get_acl_result(zk::acl acl, const zk::stat& stat) noexcept;
146 
147  virtual ~get_acl_result() noexcept;
148 
149  const zk::acl& acl() const & { return _acl; }
150  zk::acl& acl() & { return _acl; }
151  zk::acl acl() && { return std::move(_acl); }
152 
153  const zk::stat& stat() const { return _stat; }
154  zk::stat& stat() { return _stat; }
155 
156 private:
157  zk::acl _acl;
158  zk::stat _stat;
159 };
160 
161 std::ostream& operator<<(std::ostream&, const get_acl_result&);
162 
163 std::string to_string(const get_acl_result&);
164 
175 class event final
176 {
177 public:
178  explicit event(event_type type, zk::state state) noexcept;
179 
181  const event_type& type() const { return _type; }
182 
186  const zk::state& state() const { return _state; }
187 
188 private:
189  event_type _type;
190  zk::state _state;
191 };
192 
193 std::ostream& operator<<(std::ostream&, const event&);
194 
195 std::string to_string(const event&);
196 
198 class watch_result final
199 {
200 public:
201  explicit watch_result(get_result initial, future<event> next) noexcept;
202 
203  watch_result(watch_result&&) = default;
204 
205  ~watch_result() noexcept;
206 
208  const get_result& initial() const & { return _initial; }
209  get_result& initial() & { return _initial; }
210  get_result initial() && { return std::move(_initial); }
211 
213  const future<event>& next() const & { return _next; }
214  future<event>& next() & { return _next; }
215  future<event> next() && { return std::move(_next); }
216 
217 private:
218  get_result _initial;
219  future<event> _next;
220 };
221 
222 std::ostream& operator<<(std::ostream&, const watch_result&);
223 
224 std::string to_string(const watch_result&);
225 
228 {
229 public:
230  explicit watch_children_result(get_children_result initial, future<event> next) noexcept;
231 
233 
234  ~watch_children_result() noexcept;
235 
237  const get_children_result& initial() const & { return _initial; }
238  get_children_result& initial() & { return _initial; }
239  get_children_result initial() && { return std::move(_initial); }
240 
242  const future<event>& next() const & { return _next; }
243  future<event>& next() & { return _next; }
244  future<event> next() && { return std::move(_next); }
245 
246 private:
247  get_children_result _initial;
248  future<event> _next;
249 };
250 
251 std::ostream& operator<<(std::ostream&, const watch_children_result&);
252 
253 std::string to_string(const watch_children_result&);
254 
257 {
258 public:
259  explicit watch_exists_result(exists_result initial, future<event> next) noexcept;
260 
262 
263  ~watch_exists_result() noexcept;
264 
266  const exists_result& initial() const & { return _initial; }
267  exists_result& initial() & { return _initial; }
268  exists_result initial() && { return std::move(_initial); }
269 
271  const future<event>& next() const & { return _next; }
272  future<event>& next() & { return _next; }
273  future<event> next() && { return std::move(_next); }
274 
275 private:
276  exists_result _initial;
277  future<event> _next;
278 };
279 
280 std::ostream& operator<<(std::ostream&, const watch_exists_result&);
281 
282 std::string to_string(const watch_exists_result&);
283 
286 }
Data delivered when a watched event triggers.
Definition: results.hpp:175
state
Enumeration of states the client may be at when a watch triggers.
Definition: types.hpp:320
Definition: acl.cpp:8
const future< event > & next() const &
Future to be delivered when the watch is triggered.
Definition: results.hpp:242
The result type of client::get_acl.
Definition: results.hpp:142
The result type of client::watch_exists.
Definition: results.hpp:256
const get_result & initial() const &
The initial result of the fetch.
Definition: results.hpp:208
The result type of client::create.
Definition: results.hpp:101
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:79
The result type of client::watch.
Definition: results.hpp:198
The result type of client::watch_children.
Definition: results.hpp:227
Statistics about a znode, similar to the UNIX stat structure.
Definition: types.hpp:191
const children_list_type & children() const &
The list of children of the parent znode.
Definition: results.hpp:61
const get_children_result & initial() const &
The initial result of the fetch.
Definition: results.hpp:237
const exists_result & initial() const &
The initial result of the fetch.
Definition: results.hpp:266
const future< event > & next() const &
Future to be delivered when the watch is triggered.
Definition: results.hpp:271
Controls the import of future and promise types.
The result type of client::set.
Definition: results.hpp:123
const zk::state & state() const
The state of the connection when the event occurred.
Definition: results.hpp:186
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:213
const stat & parent_stat() const
The stat of the znode client::get_children was called on.
Definition: results.hpp:66
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:181