Hazelcast C++ Client
 All Classes Functions Variables Enumerations Pages
ISet.h
1 /*
2  * Copyright (c) 2008-2015, 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 #ifndef HAZELCAST_ISET
17 #define HAZELCAST_ISET
18 
19 #include "hazelcast/client/proxy/ISetImpl.h"
20 #include "hazelcast/client/impl/ItemEventHandler.h"
21 #include "hazelcast/client/protocol/codec/SetAddListenerCodec.h"
22 
23 namespace hazelcast {
24  namespace client {
25  namespace adaptor {
26  template <typename E>
27  class RawPointerSet;
28  }
29 
35  template<typename E>
36  class ISet : public proxy::ISetImpl {
37  friend class HazelcastClient;
38  friend class adaptor::RawPointerSet<E>;
39 
40  public:
51  std::string addItemListener(ItemListener<E> &listener, bool includeValue) {
52  impl::ItemEventHandler<E, protocol::codec::SetAddListenerCodec::AbstractEventHandler> *itemEventHandler =
53  new impl::ItemEventHandler<E, protocol::codec::SetAddListenerCodec::AbstractEventHandler>(
54  getName(), context->getClusterService(), context->getSerializationService(), listener,
55  includeValue);
56  return proxy::ISetImpl::addItemListener(itemEventHandler, includeValue);
57  }
58 
67  bool removeItemListener(const std::string &registrationId) {
68  return proxy::ISetImpl::removeItemListener(registrationId);
69  }
70 
75  int size() {
76  return proxy::ISetImpl::size();
77  }
78 
83  bool isEmpty() {
84  return size() == 0;
85  }
86 
93  bool contains(const E &element) {
94  return proxy::ISetImpl::contains(toData(element));
95  }
96 
101  std::vector<E> toArray() {
102  return toObjectCollection<E>(proxy::ISetImpl::toArrayData());
103  }
104 
111  bool add(const E &element) {
112  return proxy::ISetImpl::add(toData(element));
113  }
114 
121  bool remove(const E &element) {
122  return proxy::ISetImpl::remove(toData(element));
123  }
124 
131  bool containsAll(const std::vector<E> &elements) {
132  return proxy::ISetImpl::containsAll(toDataCollection(elements));
133  }
134 
141  bool addAll(const std::vector<E> &elements) {
142  std::vector<serialization::pimpl::Data> dataCollection = toDataCollection(elements);
143  return proxy::ISetImpl::addAll(toDataCollection(elements));
144  }
145 
152  bool removeAll(const std::vector<E> &elements) {
153  std::vector<serialization::pimpl::Data> dataCollection = toDataCollection(elements);
154  return proxy::ISetImpl::removeAll(dataCollection);
155  }
156 
164  bool retainAll(const std::vector<E> &elements) {
165  return proxy::ISetImpl::retainAll(toDataCollection(elements));
166  }
167 
172  void clear() {
173  proxy::ISetImpl::clear();
174  }
175 
176  private:
177  ISet(const std::string &instanceName, spi::ClientContext *context)
178  : proxy::ISetImpl(instanceName, context) {
179  }
180  };
181  }
182 }
183 
184 #endif /* HAZELCAST_ISET */
185 
bool removeAll(const std::vector< E > &elements)
Definition: ISet.h:152
std::vector< E > toArray()
Definition: ISet.h:101
bool containsAll(const std::vector< E > &elements)
Definition: ISet.h:131
int size()
Definition: ISet.h:75
Concurrent, distributed client implementation of std::unordered_set.
Definition: RawPointerSet.h:31
void clear()
Removes all elements from set.
Definition: ISet.h:172
bool add(const E &element)
Definition: ISet.h:111
Concurrent, distributed client implementation of std::unordered_set.
Definition: ISet.h:36
bool addAll(const std::vector< E > &elements)
Definition: ISet.h:141
std::string addItemListener(ItemListener< E > &listener, bool includeValue)
Warning 1: If listener should do a time consuming operation, off-load the operation to another thread...
Definition: ISet.h:51
Item listener for IQueue, ISet and IList.
Definition: ItemListener.h:40
bool removeItemListener(const std::string &registrationId)
Removes the specified item listener.
Definition: ISet.h:67
bool contains(const E &element)
Definition: ISet.h:93
bool retainAll(const std::vector< E > &elements)
Removes the elements from this set that are not available in given "elements" vector.
Definition: ISet.h:164
bool isEmpty()
Definition: ISet.h:83
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:450