Hazelcast C++ Client
Hazelcast C++ Client Library
iset.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/proxy/ISetImpl.h"
19 #include "hazelcast/client/impl/ItemEventHandler.h"
20 #include "hazelcast/client/protocol/codec/codecs.h"
21 
22 namespace hazelcast {
23 namespace client {
28 class HAZELCAST_API iset : public proxy::ISetImpl
29 {
30  friend class spi::ProxyManager;
31 
32 public:
33  static constexpr const char* SERVICE_NAME = "hz:impl:setService";
34 
46  boost::future<boost::uuids::uuid> add_item_listener(
47  item_listener&& listener,
48  bool include_value)
49  {
50  std::unique_ptr<
51  impl::item_event_handler<protocol::codec::set_addlistener_handler>>
52  itemEventHandler(new impl::item_event_handler<
53  protocol::codec::set_addlistener_handler>(
54  get_name(),
55  get_context().get_client_cluster_service(),
56  get_context().get_serialization_service(),
57  std::move(listener),
58  include_value));
59 
60  return proxy::ISetImpl::add_item_listener(std::move(itemEventHandler),
61  include_value);
62  }
63 
69  template<typename E>
70  boost::future<bool> contains(const E& element)
71  {
72  return proxy::ISetImpl::contains(to_data(element));
73  }
74 
79  template<typename E>
80  boost::future<std::vector<E>> to_array()
81  {
82  return to_object_vector<E>(proxy::ISetImpl::to_array_data());
83  }
84 
91  template<typename E>
92  boost::future<bool> add(const E& element)
93  {
94  return proxy::ISetImpl::add(to_data(element));
95  }
96 
102  template<typename E>
103  boost::future<bool> remove(const E& element)
104  {
105  return proxy::ISetImpl::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::ISetImpl::contains_all(to_data_collection(elements));
117  }
118 
124  template<typename E>
125  boost::future<bool> add_all(const std::vector<E>& elements)
126  {
127  std::vector<serialization::pimpl::data> dataCollection =
128  to_data_collection(elements);
129  return proxy::ISetImpl::add_all(to_data_collection(elements));
130  }
131 
137  template<typename E>
138  boost::future<bool> remove_all(const std::vector<E>& elements)
139  {
140  return proxy::ISetImpl::remove_all(to_data_collection(elements));
141  }
142 
150  template<typename E>
151  boost::future<bool> retain_all(const std::vector<E>& elements)
152  {
153  return proxy::ISetImpl::retain_all(to_data_collection(elements));
154  }
155 
156 private:
157  iset(const std::string& instance_name, spi::ClientContext* context)
158  : proxy::ISetImpl(instance_name, context)
159  {}
160 };
161 } // namespace client
162 } // namespace hazelcast
Concurrent, distributed client implementation of std::unordered_set.
Definition: iset.h:29
boost::future< std::vector< E > > to_array()
Definition: iset.h:80
boost::future< bool > retain_all(const std::vector< E > &elements)
Removes the elements from this set that are not available in given "elements" vector.
Definition: iset.h:151
boost::future< bool > add(const E &element)
Definition: iset.h:92
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: iset.h:46
boost::future< bool > contains_all(const std::vector< E > &elements)
Definition: iset.h:114
boost::future< bool > remove(const E &element)
Definition: iset.h:103
boost::future< bool > contains(const E &element)
Definition: iset.h:70
boost::future< bool > remove_all(const std::vector< E > &elements)
Definition: iset.h:138
boost::future< bool > add_all(const std::vector< E > &elements)
Definition: iset.h:125
Item listener for IQueue, ISet and IList.
Definition: item_listener.h:52