Hazelcast C++ Client
 All Classes Functions Variables Enumerations Enumerator Pages
IList.h
1 /*
2  * Copyright (c) 2008-2017, 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_ILIST
17 #define HAZELCAST_ILIST
18 
19 #include "hazelcast/client/serialization/pimpl/Data.h"
20 #include "hazelcast/client/DistributedObject.h"
21 #include "hazelcast/client/ItemListener.h"
22 #include "hazelcast/client/impl/ItemEventHandler.h"
23 #include "hazelcast/client/proxy/IListImpl.h"
24 #include "hazelcast/client/protocol/codec/ListAddListenerCodec.h"
25 
26 #include <stdexcept>
27 
28 
29 namespace hazelcast {
30  namespace client {
31  namespace adaptor {
32  template <typename E>
33  class RawPointerList;
34  }
35 
41  template<typename E>
42  class IList : public proxy::IListImpl {
43  friend class HazelcastClient;
44  friend class adaptor::RawPointerList<E>;
45 
46  public:
58  std::string addItemListener(ItemListener<E> &listener, bool includeValue) {
59  impl::ItemEventHandler<E, protocol::codec::ListAddListenerCodec::AbstractEventHandler> *entryEventHandler =
60  new impl::ItemEventHandler<E, protocol::codec::ListAddListenerCodec::AbstractEventHandler>(
61  getName(), context->getClusterService(), context->getSerializationService(), listener,
62  includeValue);
63  return proxy::IListImpl::addItemListener(entryEventHandler, includeValue);
64  }
65 
74  bool removeItemListener(const std::string &registrationId) {
75  return proxy::IListImpl::removeItemListener(registrationId);
76  }
77 
82  int size() {
83  return proxy::IListImpl::size();
84  }
85 
90  bool isEmpty() {
91  return size() == 0;
92  }
93 
100  bool contains(const E &element) {
101  return proxy::IListImpl::contains(toData(element));
102  }
103 
108  std::vector<E> toArray() {
109  return toObjectCollection<E>(proxy::IListImpl::toArrayData());
110  }
111 
118  bool add(const E &element) {
119  return proxy::IListImpl::add(toData(element));
120  }
121 
128  bool remove(const E &element) {
129  return proxy::IListImpl::remove(toData(element));
130  }
131 
138  bool containsAll(const std::vector<E> &elements) {
139  return proxy::IListImpl::containsAll(toDataCollection(elements));
140  }
141 
148  bool addAll(const std::vector<E> &elements) {
149  return proxy::IListImpl::addAll(toDataCollection(elements));
150  }
151 
163  bool addAll(int index, const std::vector<E> &elements) {
164  return proxy::IListImpl::addAll(index, toDataCollection(elements));
165  }
166 
173  bool removeAll(const std::vector<E> &elements) {
174  return proxy::IListImpl::removeAll(toDataCollection(elements));
175  }
176 
184  bool retainAll(const std::vector<E> &elements) {
185  return proxy::IListImpl::retainAll(toDataCollection(elements));
186  }
187 
191  void clear() {
192  proxy::IListImpl::clear();
193  }
194 
207  boost::shared_ptr<E> get(int index) {
208  return boost::shared_ptr<E>(toObject<E>(proxy::IListImpl::getData(index)));
209  }
210 
220  boost::shared_ptr<E> set(int index, const E &element) {
221  return boost::shared_ptr<E>(toObject<E>(proxy::IListImpl::setData(index, toData(element))));
222  }
223 
232  void add(int index, const E &element) {
233  proxy::IListImpl::add(index, toData(element));
234  }
235 
243  boost::shared_ptr<E> remove(int index) {
244  return boost::shared_ptr<E>(toObject<E>(proxy::IListImpl::removeData(index)));
245  }
246 
254  int indexOf(const E &element) {
255  return proxy::IListImpl::indexOf(toData(element));
256  }
257 
264  int lastIndexOf(const E &element) {
265  return proxy::IListImpl::lastIndexOf(toData(element));
266  }
267 
273  std::vector<E> subList(int fromIndex, int toIndex) {
274  return toObjectCollection<E>(proxy::IListImpl::subListData(fromIndex, toIndex));
275  }
276 
277  private:
278  IList(const std::string &instanceName, spi::ClientContext *context)
279  : proxy::IListImpl(instanceName, context) {
280  }
281  };
282  }
283 }
284 
285 #endif /* HAZELCAST_ILIST */
286 
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: IList.h:58
int indexOf(const E &element)
Definition: IList.h:254
int lastIndexOf(const E &element)
Definition: IList.h:264
bool retainAll(const std::vector< E > &elements)
Removes the elements from this list that are not available in given "elements" vector.
Definition: IList.h:184
int size()
Definition: IList.h:82
bool removeAll(const std::vector< E > &elements)
Definition: IList.h:173
bool removeItemListener(const std::string &registrationId)
Removes the specified item listener.
Definition: IList.h:74
bool containsAll(const std::vector< E > &elements)
Definition: IList.h:138
std::vector< E > subList(int fromIndex, int toIndex)
Definition: IList.h:273
Concurrent, distributed , client implementation of std::list.
Definition: IList.h:42
bool add(const E &element)
Definition: IList.h:118
Concurrent, distributed , client implementation of std::list.
Definition: RawPointerList.h:38
void clear()
Removes all elements from list.
Definition: IList.h:191
bool addAll(int index, const std::vector< E > &elements)
Adds elements in vector to the list with given order.
Definition: IList.h:163
bool isEmpty()
Definition: IList.h:90
bool addAll(const std::vector< E > &elements)
Definition: IList.h:148
boost::shared_ptr< E > set(int index, const E &element)
Replaced the element in the given index.
Definition: IList.h:220
Item listener for IQueue, ISet and IList.
Definition: ItemListener.h:40
std::vector< E > toArray()
Definition: IList.h:108
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:459
void add(int index, const E &element)
Adds the element to the given index.
Definition: IList.h:232
bool contains(const E &element)
Definition: IList.h:100