Hazelcast C++ Client
Hazelcast C++ Client Library
ilist.h
1 /*
2  * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include "hazelcast/client/impl/ItemEventHandler.h"
19 #include "hazelcast/client/proxy/IListImpl.h"
20 #include "hazelcast/client/protocol/codec/codecs.h"
21 
22 namespace hazelcast {
23 namespace client {
28 class ilist : public proxy::IListImpl
29 {
30  friend class spi::ProxyManager;
31 
32 public:
33  static constexpr const char* SERVICE_NAME = "hz:impl:listService";
34 
47  boost::future<boost::uuids::uuid> add_item_listener(
48  item_listener&& listener,
49  bool include_value)
50  {
51  std::unique_ptr<
52  impl::item_event_handler<protocol::codec::list_addlistener_handler>>
53  itemEventHandler(new impl::item_event_handler<
54  protocol::codec::list_addlistener_handler>(
55  get_name(),
56  get_context().get_client_cluster_service(),
57  get_context().get_serialization_service(),
58  std::move(listener),
59  include_value));
60 
61  return proxy::IListImpl::add_item_listener(std::move(itemEventHandler),
62  include_value);
63  }
64 
70  template<typename E>
71  boost::future<bool> contains(const E& element)
72  {
73  return proxy::IListImpl::contains(to_data(element));
74  }
75 
80  template<typename E>
81  boost::future<std::vector<E>> to_array()
82  {
83  return to_object_vector<E>(proxy::IListImpl::to_array_data());
84  }
85 
91  template<typename E>
92  boost::future<bool> add(const E& element)
93  {
94  return proxy::IListImpl::add(to_data(element));
95  }
96 
102  template<typename E>
103  boost::future<bool> remove(const E& element)
104  {
105  return proxy::IListImpl::remove(to_data(element));
106  }
107 
113  template<typename E>
114  boost::future<bool> contains_all(const std::vector<E>& elements)
115  {
116  return proxy::IListImpl::contains_all_data(
117  to_data_collection(elements));
118  }
119 
125  template<typename E>
126  boost::future<bool> add_all(const std::vector<E>& elements)
127  {
128  return proxy::IListImpl::add_all_data(to_data_collection(elements));
129  }
130 
141  template<typename E>
142  boost::future<bool> add_all(int32_t index, const std::vector<E>& elements)
143  {
144  return proxy::IListImpl::add_all_data(index,
145  to_data_collection(elements));
146  }
147 
153  template<typename E>
154  boost::future<bool> remove_all(const std::vector<E>& elements)
155  {
156  return proxy::IListImpl::remove_all_data(to_data_collection(elements));
157  }
158 
166  template<typename E>
167  boost::future<bool> retain_all(const std::vector<E>& elements)
168  {
169  return proxy::IListImpl::retain_all_data(to_data_collection(elements));
170  }
171 
185  template<typename E>
186  boost::future<boost::optional<E>> get(int32_t index)
187  {
188  return to_object<E>(proxy::IListImpl::get_data(index));
189  }
190 
202  template<typename E, typename R = E>
203  boost::future<boost::optional<R>> set(int32_t index, const E& element)
204  {
205  return to_object<R>(
206  proxy::IListImpl::set_data(index, to_data(element)));
207  }
208 
218  template<typename E>
219  boost::future<void> add(int32_t index, const E& element)
220  {
221  return proxy::IListImpl::add(index, to_data(element));
222  }
223 
232  template<typename E>
233  boost::future<boost::optional<E>> remove(int32_t index)
234  {
235  return to_object<E>(proxy::IListImpl::remove_data(index));
236  }
237 
244  template<typename E>
245  boost::future<int> index_of(const E& element)
246  {
247  return proxy::IListImpl::index_of(to_data(element));
248  }
249 
255  template<typename E>
256  boost::future<int32_t> last_index_of(const E& element)
257  {
258  return proxy::IListImpl::last_index_of(to_data(element));
259  }
260 
266  template<typename E>
267  boost::future<std::vector<E>> sub_list(int32_t from_index, int32_t to_index)
268  {
269  return to_object_vector<E>(
270  proxy::IListImpl::sub_list_data(from_index, to_index));
271  }
272 
273 private:
274  ilist(const std::string& instance_name, spi::ClientContext* context)
275  : proxy::IListImpl(instance_name, context)
276  {}
277 };
278 } // namespace client
279 } // namespace hazelcast
Concurrent, distributed, client implementation of list.
Definition: ilist.h:29
boost::future< std::vector< E > > to_array()
Definition: ilist.h:81
boost::future< boost::optional< R > > set(int32_t index, const E &element)
Replaced the element in the given index.
Definition: ilist.h:203
boost::future< bool > retain_all(const std::vector< E > &elements)
Removes the elements from this list that are not available in given "elements" vector.
Definition: ilist.h:167
boost::future< int > index_of(const E &element)
Definition: ilist.h:245
boost::future< std::vector< E > > sub_list(int32_t from_index, int32_t to_index)
Definition: ilist.h:267
boost::future< bool > contains_all(const std::vector< E > &elements)
Definition: ilist.h:114
boost::future< bool > remove(const E &element)
Definition: ilist.h:103
boost::future< bool > add_all(const std::vector< E > &elements)
Definition: ilist.h:126
boost::future< bool > remove_all(const std::vector< E > &elements)
Definition: ilist.h:154
boost::future< boost::uuids::uuid > add_item_listener(item_listener &&listener, bool include_value)
Warning 1: If listener should do a time consuming operation, off-load the operation to another thread...
Definition: ilist.h:47
boost::future< int32_t > last_index_of(const E &element)
Definition: ilist.h:256
boost::future< boost::optional< E > > get(int32_t index)
You can check if element is available by.
Definition: ilist.h:186
boost::future< bool > add(const E &element)
Definition: ilist.h:92
boost::future< bool > contains(const E &element)
Definition: ilist.h:71
boost::future< boost::optional< E > > remove(int32_t index)
Definition: ilist.h:233
boost::future< void > add(int32_t index, const E &element)
Adds the element to the given index.
Definition: ilist.h:219
boost::future< bool > add_all(int32_t index, const std::vector< E > &elements)
Adds elements in vector to the list with given order.
Definition: ilist.h:142
Item listener for IQueue, ISet and IList.
Definition: item_listener.h:52