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 
31  template<typename E>
32  class ISet : public proxy::ISetImpl {
33  friend class HazelcastClient;
34 
35  public:
46  std::string addItemListener(ItemListener<E> &listener, bool includeValue) {
47  impl::ItemEventHandler<E, protocol::codec::SetAddListenerCodec::AbstractEventHandler> *itemEventHandler =
48  new impl::ItemEventHandler<E, protocol::codec::SetAddListenerCodec::AbstractEventHandler>(
49  getName(), context->getClusterService(), context->getSerializationService(), listener,
50  includeValue);
51  return proxy::ISetImpl::addItemListener(itemEventHandler, includeValue);
52  }
53 
62  bool removeItemListener(const std::string &registrationId) {
63  return proxy::ISetImpl::removeItemListener(registrationId);
64  }
65 
70  int size() {
71  return proxy::ISetImpl::size();
72  }
73 
78  bool isEmpty() {
79  return size() == 0;
80  }
81 
88  bool contains(const E &element) {
89  return proxy::ISetImpl::contains(toData(element));
90  }
91 
96  std::vector<E> toArray() {
97  return toObjectCollection<E>(proxy::ISetImpl::toArray());
98  }
99 
106  bool add(const E &element) {
107  return proxy::ISetImpl::add(toData(element));
108  }
109 
116  bool remove(const E &element) {
117  return proxy::ISetImpl::remove(toData(element));
118  }
119 
126  bool containsAll(const std::vector<E> &elements) {
127  return proxy::ISetImpl::containsAll(toDataCollection(elements));
128  }
129 
136  bool addAll(const std::vector<E> &elements) {
137  std::vector<serialization::pimpl::Data> dataCollection = toDataCollection(elements);
138  return proxy::ISetImpl::addAll(toDataCollection(elements));
139  }
140 
147  bool removeAll(const std::vector<E> &elements) {
148  std::vector<serialization::pimpl::Data> dataCollection = toDataCollection(elements);
149  return proxy::ISetImpl::removeAll(dataCollection);
150  }
151 
159  bool retainAll(const std::vector<E> &elements) {
160  return proxy::ISetImpl::retainAll(toDataCollection(elements));
161  }
162 
167  void clear() {
168  proxy::ISetImpl::clear();
169  }
170 
171  private:
172  ISet(const std::string &instanceName, spi::ClientContext *context)
173  : proxy::ISetImpl(instanceName, context) {
174  }
175  };
176  }
177 }
178 
179 #endif /* HAZELCAST_ISET */
180 
bool removeAll(const std::vector< E > &elements)
Definition: ISet.h:147
std::vector< E > toArray()
Definition: ISet.h:96
bool containsAll(const std::vector< E > &elements)
Definition: ISet.h:126
int size()
Definition: ISet.h:70
void clear()
Removes all elements from set.
Definition: ISet.h:167
bool add(const E &element)
Definition: ISet.h:106
Concurrent, distributed client implementation of std::unordered_set.
Definition: ISet.h:32
bool addAll(const std::vector< E > &elements)
Definition: ISet.h:136
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:46
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:62
bool contains(const E &element)
Definition: ISet.h:88
bool retainAll(const std::vector< E > &elements)
Removes the elements from this set that are not available in given "elements" vector.
Definition: ISet.h:159
bool isEmpty()
Definition: ISet.h:78
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:410