VMware GemFire Native C++ Reference  9.1
VectorT.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef GEODE_VECTORT_H_
4 #define GEODE_VECTORT_H_
5 
6 /*
7  * Licensed to the Apache Software Foundation (ASF) under one or more
8  * contributor license agreements. See the NOTICE file distributed with
9  * this work for additional information regarding copyright ownership.
10  * The ASF licenses this file to You under the Apache License, Version 2.0
11  * (the "License"); you may not use this file except in compliance with
12  * the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include "geode_globals.hpp"
24 #include "VectorOfSharedBase.hpp"
25 #include "Cacheable.hpp"
26 #include "CacheableKey.hpp"
27 
31 namespace apache {
32 namespace geode {
33 namespace client {
34 
36 template <class PTR_TYPE>
37 class VectorT {
38  private:
39  VectorOfSharedBase m_vector;
40 
41  public:
43  class Iterator {
44  private:
46 
47  inline Iterator(const VectorOfSharedBase::Iterator& iter) : m_iter(iter) {}
48 
49  // Never defined.
50  Iterator();
51 
52  public:
53  inline const PTR_TYPE operator*() const {
54  return staticCast<PTR_TYPE>(*m_iter);
55  }
56 
57  inline Iterator& operator++() {
58  ++m_iter;
59  return *this;
60  }
61 
62  inline void operator++(int) { m_iter++; }
63 
64  inline bool operator==(const Iterator& other) const {
65  return (m_iter == other.m_iter);
66  }
67 
68  inline bool operator!=(const Iterator& other) const {
69  return (m_iter != other.m_iter);
70  }
71 
72  friend class VectorT;
73  };
74 
76  inline int32_t size() const { return static_cast<int32_t>(m_vector.size()); }
77 
79  inline int32_t length() const {
80  return static_cast<int32_t>(m_vector.size());
81  }
82 
84  inline int32_t max_size() const {
85  return static_cast<int32_t>(m_vector.max_size());
86  }
87 
89  inline int32_t capacity() const {
90  return static_cast<int32_t>(m_vector.capacity());
91  }
92 
94  inline bool empty() const { return m_vector.empty(); }
95 
97  inline PTR_TYPE operator[](int32_t n) {
98  return staticCast<PTR_TYPE>(m_vector[n]);
99  }
100 
102  inline const PTR_TYPE operator[](int32_t n) const {
103  return staticCast<PTR_TYPE>(m_vector[n]);
104  }
105 
107  inline PTR_TYPE at(int32_t n) { return staticCast<PTR_TYPE>(m_vector.at(n)); }
108 
110  inline const PTR_TYPE at(int32_t n) const {
111  return staticCast<PTR_TYPE>(m_vector.at(n));
112  }
113 
115  inline Iterator begin() const { return Iterator(m_vector.begin()); }
116 
118  inline Iterator end() const { return Iterator(m_vector.end()); }
119 
121  inline VectorT() : m_vector() {}
122 
124  inline VectorT(int32_t n) : m_vector(n) {}
125 
127  inline VectorT(int32_t n, const PTR_TYPE& t) : m_vector(n, t) {}
128 
130  inline VectorT(const VectorT& other) : m_vector(other.m_vector) {}
131 
133  inline ~VectorT() {
134  // destructor of m_vector field does all the work.
135  }
136 
138  inline VectorT& operator=(const VectorT& other) {
139  m_vector = other.m_vector;
140  return *this;
141  }
142 
144  inline void reserve(int32_t n) { m_vector.reserve(n); }
145 
147  inline PTR_TYPE front() { return staticCast<PTR_TYPE>(m_vector.front()); }
148 
150  inline const PTR_TYPE front() const {
151  return staticCast<PTR_TYPE>(m_vector.front());
152  }
153 
155  inline PTR_TYPE back() { return staticCast<PTR_TYPE>(m_vector.back()); }
156 
158  inline const PTR_TYPE back() const {
159  return staticCast<PTR_TYPE>(m_vector.back());
160  }
161 
163  inline void push_back(const PTR_TYPE& e) { m_vector.push_back(e); }
164 
166  inline void pop_back() { m_vector.pop_back(); }
167 
169  inline void swap(VectorT& other) { m_vector.swap(other.m_vector); }
170 
172  inline void clear() { m_vector.clear(); }
173 
177  inline void resize(int32_t n, const PTR_TYPE& t = NULLPTR) {
178  m_vector.resize(n, t);
179  }
180 
182  inline void insert(int32_t index, const PTR_TYPE& t) {
183  m_vector.insert(index, t);
184  }
185 
187  inline void erase(int32_t index) { m_vector.erase(index); }
188 };
189 
197 
202 class CPPCACHE_EXPORT VectorOfCacheable : public _VectorOfCacheable,
203  public SharedBase {
204  public:
207 
209  inline VectorOfCacheable() : _VectorOfCacheable() {}
210 
212  inline VectorOfCacheable(int32_t n) : _VectorOfCacheable(n) {}
213 
215  inline VectorOfCacheable(int32_t n, const CacheablePtr& t)
216  : _VectorOfCacheable(n, t) {}
217 
220  : _VectorOfCacheable(other) {}
221 
222  private:
224 };
225 
230 class CPPCACHE_EXPORT VectorOfCacheableKey : public _VectorOfCacheableKey,
231  public SharedBase {
232  public:
235 
237  inline VectorOfCacheableKey() : _VectorOfCacheableKey() {}
238 
240  inline VectorOfCacheableKey(int32_t n) : _VectorOfCacheableKey(n) {}
241 
243  inline VectorOfCacheableKey(int32_t n, const CacheableKeyPtr& t)
244  : _VectorOfCacheableKey(n, t) {}
245 
248  : _VectorOfCacheableKey(other) {}
249 
250  private:
252 };
253 
256 } // namespace client
257 } // namespace geode
258 } // namespace apache
259 
260 #endif // GEODE_VECTORT_H_
void swap(VectorOfSharedBase &other)
swaps the contents of two vectors.
bool empty() const
return true if the vector&#39;s size is 0.
Definition: VectorT.hpp:94
const PTR_TYPE back() const
returns the last element.
Definition: VectorT.hpp:158
int32_t max_size() const
return the largest possible size of the vector.
int32_t max_size() const
return the largest possible size of the vector.
Definition: VectorT.hpp:84
_VectorOfCacheableKey::Iterator Iterator
Iterator class for the vector.
Definition: VectorT.hpp:234
Iterator begin() const
Get an iterator pointing to the start of vector.
Definition: VectorT.hpp:115
int32_t size() const
return the size of the vector.
Each enum represents a predefined RegionAttributes in a Cache.
Definition: Assert.hpp:31
VectorOfCacheableKey(const VectorOfCacheableKey &other)
Copy constructor.
Definition: VectorT.hpp:247
VectorOfCacheable(const VectorOfCacheable &other)
Copy constructor.
Definition: VectorT.hpp:219
A vector of Cacheable objects that also extends SharedBase for smart pointers.
Definition: VectorT.hpp:202
VectorT(int32_t n, const PTR_TYPE &t)
Create a vector with n copies of t.
Definition: VectorT.hpp:127
int32_t length() const
synonym for size.
Definition: VectorT.hpp:79
const PTR_TYPE front() const
returns the first element.
Definition: VectorT.hpp:150
int32_t size() const
return the size of the vector.
Definition: VectorT.hpp:76
const PTR_TYPE at(int32_t n) const
Return the n&#39;th element with bounds checking.
Definition: VectorT.hpp:110
#define CPPCACHE_EXPORT
Defines a Geode CPPCACHE export.
Definition: geode_base.hpp:58
Interface of an iterator for VectorT.
Definition: VectorT.hpp:43
Iterator begin() const
Get an iterator pointing to the start of vector.
VectorOfCacheable(int32_t n, const CacheablePtr &t)
Create a vector with n copies of t.
Definition: VectorT.hpp:215
PTR_TYPE back()
returns the last element.
Definition: VectorT.hpp:155
void erase(int32_t index)
removes the object at the specified index from a vector
void resize(int32_t n, const PTR_TYPE &t=::apache::geode::client::NullSharedBase::s_instancePtr)
inserts or erases elements at the end such that size becomes n.
Definition: VectorT.hpp:177
void insert(int32_t index, const SharedBasePtr &t)
insert object at the given index.
bool empty() const
return true if the vector&#39;s size is 0.
~VectorT()
destructor, sets all SharedPtr elements to NULLPTR
Definition: VectorT.hpp:133
SharedBasePtr & front()
returns the first element.
VectorT(int32_t n)
Create a vector with n elements allocated.
Definition: VectorT.hpp:124
_VectorOfCacheable::Iterator Iterator
Iterator class for the vector.
Definition: VectorT.hpp:206
void push_back(const PTR_TYPE &e)
insert a new element at the end.
Definition: VectorT.hpp:163
void pop_back()
removes the last element.
Definition: VectorT.hpp:166
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:52
PTR_TYPE at(int32_t n)
Return the n&#39;th element with bounds checking.
Definition: VectorT.hpp:107
void insert(int32_t index, const PTR_TYPE &t)
insert object at the given position.
Definition: VectorT.hpp:182
VectorOfCacheableKey(int32_t n)
Create a vector with n elements allocated.
Definition: VectorT.hpp:240
VectorOfCacheableKey(int32_t n, const CacheableKeyPtr &t)
Create a vector with n copies of t.
Definition: VectorT.hpp:243
void swap(VectorT &other)
swaps the contents of two vectors.
Definition: VectorT.hpp:169
VectorT()
Create an empty vector.
Definition: VectorT.hpp:121
void resize(int32_t n, const SharedBasePtr &t=::apache::geode::client::NullSharedBase::s_instancePtr)
inserts or erases elements at the end such that size becomes n.
Interface of an iterator for VectorOfSharedBase.
Definition: VectorOfSharedBase.hpp:53
void push_back(const SharedBasePtr &e)
insert a new element at the end.
VectorOfCacheableKey()
Create an empty vector.
Definition: VectorT.hpp:237
Represents a vector of apache::geode::client::SharedBasePtr
Definition: VectorOfSharedBase.hpp:47
SharedBasePtr & at(int32_t n)
Return the n&#39;th element with bounds checking.
void reserve(int32_t n)
reallocate a vector to hold n elements.
Definition: VectorT.hpp:144
PTR_TYPE operator[](int32_t n)
Return the n&#39;th element.
Definition: VectorT.hpp:97
PTR_TYPE front()
returns the first element.
Definition: VectorT.hpp:147
Iterator end() const
Get an iterator pointing to the end of vector.
SharedBasePtr & back()
returns the last element.
This abstract base class is the base class of all user objects that have the shared capability of ref...
Definition: SharedBase.hpp:40
void reserve(int32_t n)
reallocate a vector to hold n elements.
void clear()
erases all elements.
void pop_back()
removes the last element.
Vector template type class.
Definition: VectorT.hpp:37
const PTR_TYPE operator[](int32_t n) const
Return the n&#39;th element.
Definition: VectorT.hpp:102
Iterator end() const
Get an iterator pointing to the end of vector.
Definition: VectorT.hpp:118
A vector of CacheableKey objects that also extends SharedBase for smart pointers. ...
Definition: VectorT.hpp:230
int32_t capacity() const
return the number of elements allocated for this vector.
VectorOfCacheable()
Create an empty vector.
Definition: VectorT.hpp:209
void erase(int32_t index)
Removes the object at the specified index from a vector.
Definition: VectorT.hpp:187
VectorT & operator=(const VectorT &other)
assignment operator
Definition: VectorT.hpp:138
VectorT(const VectorT &other)
copy constructor
Definition: VectorT.hpp:130
VectorOfCacheable(int32_t n)
Create a vector with n elements allocated.
Definition: VectorT.hpp:212
void clear()
erases all elements.
Definition: VectorT.hpp:172
This namespace contains all the Geode C++ API classes, enumerations and globals.
int32_t capacity() const
return the number of elements allocated for this vector.
Definition: VectorT.hpp:89

Pivotal GemFire C++ Cache API Documentation