12 static std::string to_string_generic(
const T&
self)
14 std::ostringstream os;
23 std::ostream& operator<<(std::ostream& os,
const op_type&
self)
31 default:
return os <<
"op_type(" <<
static_cast<int>(
self) <<
')';
35 std::string to_string(
const op_type&
self)
37 return to_string_generic(
self);
44 op::op(any_data&& src) noexcept :
45 _storage(std::move(src))
48 op::op(
const op& src) =
default;
50 op::op(op&& src) noexcept :
51 _storage(std::move(src._storage))
54 op::~op() noexcept = default;
58 return std::visit([] (
const auto& x) {
return x.type(); }, _storage);
66 return std::get<T>(_storage);
68 catch (
const std::bad_variant_access&)
70 throw std::logic_error( std::string(
"Invalid op type for op::")
71 + std::string(operation)
80 op::check_data::check_data(std::string path, version check_) :
81 path(std::move(path)),
85 std::ostream& operator<<(std::ostream& os,
const op::check_data&
self)
87 os <<
'{' <<
self.path;
88 os <<
' ' <<
self.check;
99 return as<check_data>(
"as_check");
105 path(std::move(path)),
106 data(std::move(data)),
107 rules(std::move(rules)),
111 std::ostream& operator<<(std::ostream& os,
const op::create_data&
self)
113 os <<
'{' <<
self.path;
114 os <<
' ' <<
self.mode;
115 os <<
' ' <<
self.rules;
121 return op(
create_data(std::move(path), std::move(data), std::move(rules), mode));
131 return as<create_data>(
"as_create");
136 op::erase_data::erase_data(std::string path,
version check) :
137 path(std::move(path)),
141 std::ostream& operator<<(std::ostream& os,
const op::erase_data&
self)
143 os <<
'{' <<
self.path;
144 os <<
' ' <<
self.check;
155 return as<erase_data>(
"as_erase");
161 path(std::move(path)),
162 data(std::move(data)),
166 std::ostream& operator<<(std::ostream& os,
const op::set_data&
self)
168 os <<
'{' <<
self.path;
169 os <<
' ' <<
self.check;
175 return op(
set_data(std::move(path), std::move(data), check));
180 return as<set_data>(
"as_set");
185 std::ostream& operator<<(std::ostream& os,
const op&
self)
188 std::visit([&] (
const auto& x) { os << x; },
self._storage);
192 std::string to_string(
const op&
self)
194 std::ostringstream os;
207 multi_op::~multi_op() noexcept
210 std::ostream& operator<<(std::ostream& os,
const multi_op&
self)
214 for (
const auto& x :
self)
229 multi_result::part::part(
op_type type, std::nullptr_t) noexcept :
231 _storage(std::monostate())
234 multi_result::part::part(create_result res) noexcept :
236 _storage(std::move(res))
239 multi_result::part::part(set_result res) noexcept :
241 _storage(std::move(res))
244 multi_result::part::part(
const part& src) =
default;
246 multi_result::part::part(part&& src) noexcept :
248 _storage(std::move(src._storage))
251 multi_result::part::~part() noexcept = default;
253 template <typename T>
254 const T& multi_result::part::as(
ptr<const
char> operation)
const
258 return std::get<T>(_storage);
260 catch (
const std::bad_variant_access&)
262 throw std::logic_error( std::string(
"Invalid op type for multi_result::")
263 + std::string(operation)
272 return as<create_result>(
"as_create");
277 return as<set_result>(
"as_set");
280 multi_result::multi_result(std::vector<part> parts) noexcept :
281 _parts(std::move(parts))
284 multi_result::~multi_result() noexcept
287 std::ostream& operator<<(std::ostream& os,
const multi_result::part&
self)
293 default:
return os <<
self.type() <<
"_result{}";
297 std::ostream& operator<<(std::ostream& os,
const multi_result&
self)
301 for (
const auto& x :
self)
312 std::string to_string(
const multi_result::part&
self)
314 return to_string_generic(
self);
317 std::string to_string(
const multi_result&
self)
319 return to_string_generic(
self);
T * ptr
A simple, unowned pointer.
Data for a op::set operation.
const set_data & as_set() const
Get the set-specific data.
const set_result & as_set() const
Get the set-specific result data.
const create_result & as_create() const
Get the create-specific result data.
Represents a single operation of a multi_op.
The result type of client::create.
op_type
Describes the type of an op.
const create_data & as_create() const
Get the create-specific data.
create_mode
When used in client::set, this value determines how the entry is created on the server.
Data for a op::check operation.
static const acl & open_unsafe()
This is a completely open ACL.
op_type type() const
Get the underlying type of this operation.
The result type of client::set.
An access control list is a wrapper around acl_rule instances.
multi_op() noexcept
Create an empty operation set.
const erase_data & as_erase() const
Get the erase-specific data.
static op check(std::string path, version check=version::any())
Check that the given path exists with the provided version check (which can be version::any).
static op create(std::string path, buffer data, acl rules, create_mode mode=create_mode::normal)
Represents a version of the data.
ZKPP_BUFFER_TYPE buffer
The buffer type.
Data for a op::erase operation.
const check_data & as_check() const
Get the check-specific data.
Data for a op::create operation.
static op erase(std::string path, version check=version::any())
Delete the entry at the given path if it matches the version check.
static op set(std::string path, buffer data, version check=version::any())
Set the data for the entry at path if it matches the version check.