Hazelcast C++ Client
 All Classes Functions Variables Enumerations Pages
IList.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_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 
37  template<typename E>
38  class IList : public proxy::IListImpl {
39  friend class HazelcastClient;
40 
41  public:
53  std::string addItemListener(ItemListener<E> &listener, bool includeValue) {
54  impl::ItemEventHandler<E, protocol::codec::ListAddListenerCodec::AbstractEventHandler> *entryEventHandler =
55  new impl::ItemEventHandler<E, protocol::codec::ListAddListenerCodec::AbstractEventHandler>(
56  getName(), context->getClusterService(), context->getSerializationService(), listener,
57  includeValue);
58  return proxy::IListImpl::addItemListener(entryEventHandler, includeValue);
59  }
60 
69  bool removeItemListener(const std::string &registrationId) {
70  return proxy::IListImpl::removeItemListener(registrationId);
71  }
72 
77  int size() {
78  return proxy::IListImpl::size();
79  }
80 
85  bool isEmpty() {
86  return size() == 0;
87  }
88 
95  bool contains(const E &element) {
96  return proxy::IListImpl::contains(toData(element));
97  }
98 
103  std::vector<E> toArray() {
104  return toObjectCollection<E>(proxy::IListImpl::toArray());
105  }
106 
113  bool add(const E &element) {
114  return proxy::IListImpl::add(toData(element));
115  }
116 
123  bool remove(const E &element) {
124  return proxy::IListImpl::remove(toData(element));
125  }
126 
133  bool containsAll(const std::vector<E> &elements) {
134  return proxy::IListImpl::containsAll(toDataCollection(elements));
135  }
136 
143  bool addAll(const std::vector<E> &elements) {
144  return proxy::IListImpl::addAll(toDataCollection(elements));
145  }
146 
158  bool addAll(int index, const std::vector<E> &elements) {
159  return proxy::IListImpl::addAll(index, toDataCollection(elements));
160  }
161 
168  bool removeAll(const std::vector<E> &elements) {
169  return proxy::IListImpl::removeAll(toDataCollection(elements));
170  }
171 
179  bool retainAll(const std::vector<E> &elements) {
180  return proxy::IListImpl::retainAll(toDataCollection(elements));
181  }
182 
186  void clear() {
187  proxy::IListImpl::clear();
188  }
189 
202  boost::shared_ptr<E> get(int index) {
203  return toObject<E>(proxy::IListImpl::get(index));
204  }
205 
215  boost::shared_ptr<E> set(int index, const E &element) {
216  return toObject<E>(proxy::IListImpl::set(index, toData(element)));
217  }
218 
227  void add(int index, const E &element) {
228  proxy::IListImpl::add(index, toData(element));
229  }
230 
238  boost::shared_ptr<E> remove(int index) {
239  return toObject<E>(proxy::IListImpl::remove(index));
240  }
241 
249  int indexOf(const E &element) {
250  return proxy::IListImpl::indexOf(toData(element));
251  }
252 
259  int lastIndexOf(const E &element) {
260  return proxy::IListImpl::lastIndexOf(toData(element));
261  }
262 
268  std::vector<E> subList(int fromIndex, int toIndex) {
269  return toObjectCollection<E>(proxy::IListImpl::subList(fromIndex, toIndex));
270  }
271 
272  private:
273  IList(const std::string &instanceName, spi::ClientContext *context)
274  : proxy::IListImpl(instanceName, context) {
275  }
276  };
277  }
278 }
279 
280 #endif /* HAZELCAST_ILIST */
281 
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:53
int indexOf(const E &element)
Definition: IList.h:249
int lastIndexOf(const E &element)
Definition: IList.h:259
bool retainAll(const std::vector< E > &elements)
Removes the elements from this list that are not available in given "elements" vector.
Definition: IList.h:179
int size()
Definition: IList.h:77
bool removeAll(const std::vector< E > &elements)
Definition: IList.h:168
bool removeItemListener(const std::string &registrationId)
Removes the specified item listener.
Definition: IList.h:69
bool containsAll(const std::vector< E > &elements)
Definition: IList.h:133
std::vector< E > subList(int fromIndex, int toIndex)
Definition: IList.h:268
Concurrent, distributed , client implementation of std::list.
Definition: IList.h:38
bool add(const E &element)
Definition: IList.h:113
void clear()
Removes all elements from list.
Definition: IList.h:186
bool addAll(int index, const std::vector< E > &elements)
Adds elements in vector to the list with given order.
Definition: IList.h:158
bool isEmpty()
Definition: IList.h:85
bool addAll(const std::vector< E > &elements)
Definition: IList.h:143
boost::shared_ptr< E > set(int index, const E &element)
Replaced the element in the given index.
Definition: IList.h:215
Item listener for IQueue, ISet and IList.
Definition: ItemListener.h:40
std::vector< E > toArray()
Definition: IList.h:103
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:410
void add(int index, const E &element)
Adds the element to the given index.
Definition: IList.h:227
bool contains(const E &element)
Definition: IList.h:95