Hazelcast C++ Client
ReadResultSet.h
1 /*
2  * Copyright (c) 2008-2019, 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_CLIENT_RINGBUFFER_READRESULTSET_H_
17 #define HAZELCAST_CLIENT_RINGBUFFER_READRESULTSET_H_
18 
19 #include <stdint.h>
20 
21 #include "hazelcast/client/impl/DataArrayImpl.h"
22 
23 namespace hazelcast {
24  namespace client {
25  namespace ringbuffer {
26  template<typename E>
27  class ReadResultSet {
28  public:
34  static const int64_t SEQUENCE_UNAVAILABLE = -1;
35 
36  ReadResultSet() {}
37 
38  ReadResultSet(int32_t readCount, const std::vector<serialization::pimpl::Data> &dataItems,
39  serialization::pimpl::SerializationService &serializationService,
40  std::auto_ptr<std::vector<int64_t> > &itemSeqs, bool itemSeqsExist,
41  int64_t nextSeq) : itemsReadCount(readCount),
42  items(new client::impl::DataArrayImpl<E>(dataItems,
43  serializationService)),
44  itemSeqs(itemSeqs),
45  itemSeqsExist(itemSeqsExist),
46  nextSeq(nextSeq) {}
47 
48  virtual ~ReadResultSet() {}
49 
63  virtual int32_t readCount() const {
64  return itemsReadCount;
65  }
66 
67  virtual DataArray<E> &getItems() {
68  return *items;
69  }
70 
79  virtual int64_t getSequence(int32_t index) const {
80  if (!itemSeqsExist) {
81  throw exception::IllegalArgumentException("ReadResultSet::getSequence",
82  "No item sequences exist");
83  }
84  if (index >= (int32_t) itemSeqs->size() || index < 0) {
86  "ReadResultSet::getSequence") << "Index " << index
87  << " is out of bounds. Sequences size is:"
88  << itemSeqs->size()).build();
89  }
90 
91  return (*itemSeqs)[index];
92  }
93 
115  virtual int64_t getNextSequenceToReadFrom() const {
116  return nextSeq;
117  }
118 
119  private:
120  int32_t itemsReadCount;
121  std::auto_ptr<client::impl::DataArrayImpl<E> > items;
122  std::auto_ptr<std::vector<int64_t> > itemSeqs;
123  bool itemSeqsExist;
124  int64_t nextSeq;
125  };
126  }
127  }
128 }
129 
130 #endif /* HAZELCAST_CLIENT_RINGBUFFER_READRESULTSET_H_ */
virtual int64_t getSequence(int32_t index) const
Return the sequence number for the item at the given index.
Definition: ReadResultSet.h:79
Definition: DataArray.h:28
static const int64_t SEQUENCE_UNAVAILABLE
Value returned from methods returning a sequence number when the information is not available (e...
Definition: ReadResultSet.h:34
Definition: ReadResultSet.h:27
virtual int64_t getNextSequenceToReadFrom() const
Returns the sequence of the item following the last read item.
Definition: ReadResultSet.h:115
virtual int32_t readCount() const
Returns the number of items that have been read before filtering.
Definition: ReadResultSet.h:63
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32