Hazelcast C++ Client
Hazelcast C++ Client Library
ilist.h
1 /*
2  * Copyright (c) 2008-2021, 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  friend class spi::ProxyManager;
30  public:
31  static constexpr const char *SERVICE_NAME = "hz:impl:listService";
32 
44  boost::future<boost::uuids::uuid> add_item_listener(item_listener &&listener, bool include_value) {
45  std::unique_ptr<impl::item_event_handler<protocol::codec::list_addlistener_handler>> itemEventHandler(
46  new impl::item_event_handler<protocol::codec::list_addlistener_handler>(
47  get_name(), get_context().get_client_cluster_service(),
48  get_context().get_serialization_service(),
49  std::move(listener),
50  include_value));
51 
52  return proxy::IListImpl::add_item_listener(std::move(itemEventHandler), include_value);
53  }
54 
60  template<typename E>
61  boost::future<bool> contains(const E &element) {
62  return proxy::IListImpl::contains(to_data(element));
63  }
64 
69  template<typename E>
70  boost::future<std::vector<E>> to_array() {
71  return to_object_vector<E>(proxy::IListImpl::to_array_data());
72  }
73 
79  template<typename E>
80  boost::future<bool> add(const E &element) {
81  return proxy::IListImpl::add(to_data(element));
82  }
83 
89  template<typename E>
90  boost::future<bool> remove(const E &element) {
91  return proxy::IListImpl::remove(to_data(element));
92  }
93 
99  template<typename E>
100  boost::future<bool> contains_all(const std::vector<E> &elements) {
101  return proxy::IListImpl::contains_all_data(to_data_collection(elements));
102  }
103 
109  template<typename E>
110  boost::future<bool> add_all(const std::vector<E> &elements) {
111  return proxy::IListImpl::add_all_data(to_data_collection(elements));
112  }
113 
124  template<typename E>
125  boost::future<bool> add_all(int32_t index, const std::vector<E> &elements) {
126  return proxy::IListImpl::add_all_data(index, to_data_collection(elements));
127  }
128 
134  template<typename E>
135  boost::future<bool> remove_all(const std::vector<E> &elements) {
136  return proxy::IListImpl::remove_all_data(to_data_collection(elements));
137  }
138 
145  template<typename E>
146  boost::future<bool> retain_all(const std::vector<E> &elements) {
147  return proxy::IListImpl::retain_all_data(to_data_collection(elements));
148  }
149 
162  template<typename E>
163  boost::future<boost::optional<E>> get(int32_t index) {
164  return to_object<E>(proxy::IListImpl::get_data(index));
165  }
166 
176  template<typename E, typename R = E>
177  boost::future<boost::optional<R>> set(int32_t index, const E &element) {
178  return to_object<R>(proxy::IListImpl::set_data(index, to_data(element)));
179  }
180 
189  template<typename E>
190  boost::future<void> add(int32_t index, const E &element) {
191  return proxy::IListImpl::add(index, to_data(element));
192  }
193 
201  template<typename E>
202  boost::future<boost::optional<E>> remove(int32_t index) {
203  return to_object<E>(proxy::IListImpl::remove_data(index));
204  }
205 
212  template<typename E>
213  boost::future<int> index_of(const E &element) {
214  return proxy::IListImpl::index_of(to_data(element));
215  }
216 
222  template<typename E>
223  boost::future<int32_t> last_index_of(const E &element) {
224  return proxy::IListImpl::last_index_of(to_data(element));
225  }
226 
232  template<typename E>
233  boost::future<std::vector<E>> sub_list(int32_t from_index, int32_t to_index) {
234  return to_object_vector<E>(proxy::IListImpl::sub_list_data(from_index, to_index));
235  }
236 
237  private:
238  ilist(const std::string &instance_name, spi::ClientContext *context) : proxy::IListImpl(instance_name,
239  context) {}
240  };
241  }
242 }
243 
Concurrent, distributed, client implementation of list.
Definition: ilist.h:28
boost::future< std::vector< E > > to_array()
Definition: ilist.h:70
boost::future< boost::optional< R > > set(int32_t index, const E &element)
Replaced the element in the given index.
Definition: ilist.h:177
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:146
boost::future< int > index_of(const E &element)
Definition: ilist.h:213
boost::future< std::vector< E > > sub_list(int32_t from_index, int32_t to_index)
Definition: ilist.h:233
boost::future< bool > contains_all(const std::vector< E > &elements)
Definition: ilist.h:100
boost::future< bool > remove(const E &element)
Definition: ilist.h:90
boost::future< bool > add_all(const std::vector< E > &elements)
Definition: ilist.h:110
boost::future< bool > remove_all(const std::vector< E > &elements)
Definition: ilist.h:135
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:44
boost::future< int32_t > last_index_of(const E &element)
Definition: ilist.h:223
boost::future< boost::optional< E > > get(int32_t index)
You can check if element is available by.
Definition: ilist.h:163
boost::future< bool > add(const E &element)
Definition: ilist.h:80
boost::future< bool > contains(const E &element)
Definition: ilist.h:61
boost::future< boost::optional< E > > remove(int32_t index)
Definition: ilist.h:202
boost::future< void > add(int32_t index, const E &element)
Adds the element to the given index.
Definition: ilist.h:190
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:125
Item listener for IQueue, ISet and IList.
Definition: item_listener.h:51