Hazelcast C++ Client
Hazelcast C++ Client Library
hazelcast::cp::atomic_long Class Reference

Client-side Raft-based proxy implementation of atomic long. More...

#include <cp.h>

+ Inheritance diagram for hazelcast::cp::atomic_long:

Public Member Functions

 atomic_long (const std::string &name, client::spi::ClientContext &context, const raft_group_id &group_id, const std::string &object_name)
 
boost::future< int64_t > add_and_get (int64_t delta)
 Atomically adds the given value to the current value. More...
 
boost::future< bool > compare_and_set (int64_t expect, int64_t update)
 Atomically sets the value to the given updated value only if the current value. More...
 
boost::future< int64_t > get_and_decrement ()
 Atomically decrements the current value by one. More...
 
boost::future< int64_t > decrement_and_get ()
 Atomically decrements the current value by one. More...
 
boost::future< int64_t > get ()
 Gets the current value. More...
 
boost::future< int64_t > get_and_add (int64_t delta)
 Atomically adds the given value to the current value. More...
 
boost::future< int64_t > get_and_set (int64_t new_value)
 Atomically sets the given value and returns the old value. More...
 
boost::future< int64_t > increment_and_get ()
 Atomically increments the current value by one. More...
 
boost::future< int64_t > get_and_increment ()
 Atomically increments the current value by one. More...
 
boost::future< void > set (int64_t new_value)
 Atomically sets the given value. More...
 
template<typename F >
boost::future< void > alter (const F &function)
 Alters the currently stored value by applying a function on it. More...
 
template<typename F >
boost::future< int64_t > alter_and_get (const F &function)
 Alters the currently stored value by applying a function on it and gets the result. More...
 
template<typename F >
boost::future< int64_t > get_and_alter (const F &function)
 Alters the currently stored value by applying a function on it on and gets the old value. More...
 
template<typename F , typename R >
boost::future< boost::optional< R > > apply (const F &function)
 Applies a function on the value, the actual stored value will not change. More...
 
- Public Member Functions inherited from hazelcast::cp::cp_proxy
 cp_proxy (const std::string &service_name, const std::string &proxy_name, client::spi::ClientContext *context, const raft_group_id &group_id, const std::string &object_name)
 
const raft_group_idget_group_id () const
 

Additional Inherited Members

- Protected Member Functions inherited from hazelcast::cp::cp_proxy
void on_destroy ()
 
- Protected Attributes inherited from hazelcast::cp::cp_proxy
raft_group_id group_id_
 
std::string object_name_
 

Detailed Description

Client-side Raft-based proxy implementation of atomic long.

Definition at line 90 of file cp.h.

Member Function Documentation

◆ add_and_get()

boost::future< int64_t > hazelcast::cp::atomic_long::add_and_get ( int64_t  delta)

Atomically adds the given value to the current value.

Parameters
deltathe value to add to the current value
Returns
the updated value, the given value added to the current value

Definition at line 166 of file cp.cpp.

166  {
167  auto request = atomiclong_addandget_encode(group_id_, object_name_, delta);
168  return invoke_and_get_future<int64_t>(request);
169  }

◆ alter()

template<typename F >
boost::future<void> hazelcast::cp::atomic_long::alter ( const F &  function)
inline

Alters the currently stored value by applying a function on it.

Parameters
functionthe function applied to the currently stored value

Definition at line 178 of file cp.h.

178  {
179  return to_void_future(alter_and_get(function));
180  }
boost::future< int64_t > alter_and_get(const F &function)
Alters the currently stored value by applying a function on it and gets the result.
Definition: cp.h:190

◆ alter_and_get()

template<typename F >
boost::future<int64_t> hazelcast::cp::atomic_long::alter_and_get ( const F &  function)
inline

Alters the currently stored value by applying a function on it and gets the result.

Parameters
functionthe function applied to the currently stored value
Returns
the new value

Definition at line 190 of file cp.h.

190  {
191  auto f = to_data(function);
192  return alter_data(f, alter_result_type::NEW_VALUE);
193  }

◆ apply()

template<typename F , typename R >
boost::future<boost::optional<R> > hazelcast::cp::atomic_long::apply ( const F &  function)
inline

Applies a function on the value, the actual stored value will not change.

Parameters
functionthe function applied to the value, the value is not changed
<R>the result type of the function
Returns
the result of the function application

Definition at line 217 of file cp.h.

217  {
218  auto f = to_data(function);
219  return to_object<R>(apply_data(f));
220  }

◆ compare_and_set()

boost::future< bool > hazelcast::cp::atomic_long::compare_and_set ( int64_t  expect,
int64_t  update 
)

Atomically sets the value to the given updated value only if the current value.

==

the expected value.

Parameters
expectthe expected value
updatethe new value
Returns
true
if successful; or
false
if the actual value was not equal to the expected value.

Definition at line 171 of file cp.cpp.

171  {
172  auto request = atomiclong_compareandset_encode(group_id_, object_name_, expect, update);
173  return invoke_and_get_future<bool>(request);
174  }

◆ decrement_and_get()

boost::future< int64_t > hazelcast::cp::atomic_long::decrement_and_get ( )

Atomically decrements the current value by one.

Returns
the updated value, the current value decremented by one

Definition at line 180 of file cp.cpp.

180  {
181  return add_and_get(-1);
182  }
boost::future< int64_t > add_and_get(int64_t delta)
Atomically adds the given value to the current value.
Definition: cp.cpp:166

◆ get()

boost::future< int64_t > hazelcast::cp::atomic_long::get ( )

Gets the current value.

Returns
the current value

Definition at line 184 of file cp.cpp.

184  {
185  auto request = atomiclong_get_encode(group_id_, object_name_);
186  return invoke_and_get_future<int64_t>(request);
187  }

◆ get_and_add()

boost::future< int64_t > hazelcast::cp::atomic_long::get_and_add ( int64_t  delta)

Atomically adds the given value to the current value.

Parameters
deltathe value to add to the current value
Returns
the old value before the add

Definition at line 189 of file cp.cpp.

189  {
190  auto request = atomiclong_getandadd_encode(group_id_, object_name_, delta);
191  return invoke_and_get_future<int64_t>(request);
192  }

◆ get_and_alter()

template<typename F >
boost::future<int64_t> hazelcast::cp::atomic_long::get_and_alter ( const F &  function)
inline

Alters the currently stored value by applying a function on it on and gets the old value.

Parameters
functionthe function applied to the currently stored value
Returns
the old value
Since
3.2

Definition at line 204 of file cp.h.

204  {
205  auto f = to_data(function);
206  return alter_data(f, alter_result_type::OLD_VALUE);
207  }

◆ get_and_decrement()

boost::future< int64_t > hazelcast::cp::atomic_long::get_and_decrement ( )

Atomically decrements the current value by one.

Returns
the old value.

Definition at line 176 of file cp.cpp.

176  {
177  return get_and_add(-1);
178  }
boost::future< int64_t > get_and_add(int64_t delta)
Atomically adds the given value to the current value.
Definition: cp.cpp:189

◆ get_and_increment()

boost::future< int64_t > hazelcast::cp::atomic_long::get_and_increment ( )

Atomically increments the current value by one.

Returns
the old value

Definition at line 203 of file cp.cpp.

203  {
204  return get_and_add(1);
205  }

◆ get_and_set()

boost::future< int64_t > hazelcast::cp::atomic_long::get_and_set ( int64_t  new_value)

Atomically sets the given value and returns the old value.

Parameters
newValuethe new value
Returns
the old value

Definition at line 194 of file cp.cpp.

194  {
195  auto request = atomiclong_getandset_encode(group_id_, object_name_, new_value);
196  return invoke_and_get_future<int64_t>(request);
197  }

◆ increment_and_get()

boost::future< int64_t > hazelcast::cp::atomic_long::increment_and_get ( )

Atomically increments the current value by one.

Returns
the updated value, the current value incremented by one

Definition at line 199 of file cp.cpp.

199  {
200  return add_and_get(1);
201  }

◆ set()

boost::future< void > hazelcast::cp::atomic_long::set ( int64_t  new_value)

Atomically sets the given value.

Parameters
newValuethe new value

Definition at line 207 of file cp.cpp.

207  {
208  return to_void_future(get_and_set(new_value));
209  }
boost::future< int64_t > get_and_set(int64_t new_value)
Atomically sets the given value and returns the old value.
Definition: cp.cpp:194

The documentation for this class was generated from the following files: