Pivotal GemFire Native Client Cache Reference  9.0.6
VectorT.hpp
Go to the documentation of this file.
1 
2 #ifndef _GEMFIRE_VECTORT_HPP_
3 #define _GEMFIRE_VECTORT_HPP_
4 
5 /*=========================================================================
6  * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
7  * This product is protected by U.S. and international copyright
8  * and intellectual property laws. Pivotal products are covered by
9  * more patents listed at http://www.pivotal.io/patents.
10  *========================================================================
11  */
12 
13 #include "gfcpp_globals.hpp"
14 #include "VectorOfSharedBase.hpp"
15 #include "Cacheable.hpp"
16 #include "CacheableKey.hpp"
17 
21 namespace gemfire {
22 
24 template < class PTR_TYPE > class VectorT
25 {
26  private:
27  VectorOfSharedBase m_vector;
28 
29  public:
30 
32  class Iterator
33  {
34  private:
35 
37 
38 
39  inline Iterator( const VectorOfSharedBase::Iterator& iter )
40  : m_iter( iter ) { }
41 
42  // Never defined.
43  Iterator( );
44 
45 
46  public:
47 
48  inline const PTR_TYPE operator * ( ) const
49  {
50  return staticCast<PTR_TYPE>( *m_iter );
51  }
52 
53  inline Iterator& operator ++ ( )
54  {
55  ++m_iter;
56  return *this;
57  }
58 
59  inline void operator ++ ( int )
60  {
61  m_iter++;
62  }
63 
64  inline bool operator == ( const Iterator& other ) const
65  {
66  return ( m_iter == other.m_iter );
67  }
68 
69  inline bool operator != ( const Iterator& other ) const
70  {
71  return ( m_iter != other.m_iter );
72  }
73 
74 
75  friend class VectorT;
76  };
77 
79  inline int32_t size( ) const
80  {
81  return static_cast<int32_t> (m_vector.size());
82  }
83 
85  inline int32_t length( ) const
86  {
87  return static_cast<int32_t> (m_vector.size());
88  }
89 
91  inline int32_t max_size( ) const
92  {
93  return static_cast<int32_t> (m_vector.max_size());
94  }
95 
97  inline int32_t capacity( ) const
98  {
99  return static_cast<int32_t> (m_vector.capacity());
100  }
101 
103  inline bool empty( ) const
104  {
105  return m_vector.empty();
106  }
107 
109  inline PTR_TYPE operator [] ( int32_t n )
110  {
111  return staticCast<PTR_TYPE>( m_vector[n] );
112  }
113 
115  inline const PTR_TYPE operator [] ( int32_t n ) const
116  {
117  return staticCast<PTR_TYPE>( m_vector[n] );
118  }
119 
121  inline PTR_TYPE at( int32_t n )
122  {
123  return staticCast<PTR_TYPE>( m_vector.at( n ) );
124  }
125 
127  inline const PTR_TYPE at( int32_t n ) const
128  {
129  return staticCast<PTR_TYPE>( m_vector.at( n ) );
130  }
131 
133  inline Iterator begin( ) const
134  {
135  return Iterator( m_vector.begin( ) );
136  }
137 
139  inline Iterator end( ) const
140  {
141  return Iterator( m_vector.end( ) );
142  }
143 
145  inline VectorT( )
146  : m_vector( )
147  {
148  }
149 
151  inline VectorT( int32_t n )
152  : m_vector( n )
153  {
154  }
155 
157  inline VectorT( int32_t n, const PTR_TYPE& t )
158  : m_vector( n, t )
159  {
160  }
161 
163  inline VectorT( const VectorT& other )
164  : m_vector( other.m_vector )
165  {
166  }
167 
169  inline ~VectorT( )
170  {
171  // destructor of m_vector field does all the work.
172  }
173 
175  inline VectorT& operator = ( const VectorT& other )
176  {
177  m_vector = other.m_vector;
178  return *this;
179  }
180 
182  inline void reserve( int32_t n )
183  {
184  m_vector.reserve( n );
185  }
186 
188  inline PTR_TYPE front( )
189  {
190  return staticCast<PTR_TYPE>( m_vector.front( ) );
191  }
192 
194  inline const PTR_TYPE front( ) const
195  {
196  return staticCast<PTR_TYPE>( m_vector.front( ) );
197  }
198 
200  inline PTR_TYPE back( )
201  {
202  return staticCast<PTR_TYPE>( m_vector.back( ) );
203  }
204 
206  inline const PTR_TYPE back( ) const
207  {
208  return staticCast<PTR_TYPE>( m_vector.back( ) );
209  }
210 
212  inline void push_back( const PTR_TYPE& e )
213  {
214  m_vector.push_back( e );
215  }
216 
218  inline void pop_back( )
219  {
220  m_vector.pop_back();
221  }
222 
224  inline void swap( VectorT& other )
225  {
226  m_vector.swap( other.m_vector );
227  }
228 
230  inline void clear( )
231  {
232  m_vector.clear();
233  }
234 
238  inline void resize(int32_t n, const PTR_TYPE& t = NULLPTR)
239  {
240  m_vector.resize( n, t );
241  }
242 
244  inline void insert( int32_t index, const PTR_TYPE& t )
245  {
246  m_vector.insert( index, t );
247  }
248 
250  inline void erase( int32_t index )
251  {
252  m_vector.erase( index );
253  }
254 
255 };
256 
264 
270  public _VectorOfCacheable, public SharedBase
271 {
272 public:
275 
277  inline VectorOfCacheable() :
278  _VectorOfCacheable() { }
279 
281  inline VectorOfCacheable(int32_t n) :
282  _VectorOfCacheable(n) { }
283 
285  inline VectorOfCacheable(int32_t n, const CacheablePtr& t ) :
286  _VectorOfCacheable(n, t) { }
287 
289  inline VectorOfCacheable(const VectorOfCacheable& other) :
290  _VectorOfCacheable(other) { }
291 
292 private:
294 };
295 
301  public _VectorOfCacheableKey, public SharedBase
302 {
303 public:
306 
309  _VectorOfCacheableKey() { }
310 
312  inline VectorOfCacheableKey(int32_t n) :
313  _VectorOfCacheableKey(n) { }
314 
316  inline VectorOfCacheableKey(int32_t n, const CacheableKeyPtr& t ) :
317  _VectorOfCacheableKey(n, t) { }
318 
321  _VectorOfCacheableKey(other) { }
322 
323 private:
325 
326 };
327 
330 
331 }
332 
333 #endif
Iterator begin() const
Get an iterator pointing to the start of vector.
Definition: VectorT.hpp:133
void pop_back()
removes the last element.
Definition: VectorT.hpp:218
bool empty() const
return true if the vector&#39;s size is 0.
Definition: VectorT.hpp:103
Vector template type class.
Definition: VectorT.hpp:24
void swap(VectorOfSharedBase &other)
swaps the contents of two vectors.
Represents a vector of gemfire::SharedBasePtr
Definition: VectorOfSharedBase.hpp:35
int32_t max_size() const
return the largest possible size of the vector.
Definition: VectorT.hpp:91
void pop_back()
removes the last element.
VectorT & operator=(const VectorT &other)
assignment operator
Definition: VectorT.hpp:175
int32_t capacity() const
return the number of elements allocated for this vector.
Definition: VectorT.hpp:97
SharedBasePtr & front()
returns the first element.
A vector of CacheableKey objects that also extends SharedBase for smart pointers. ...
Definition: VectorT.hpp:300
PTR_TYPE front()
returns the first element.
Definition: VectorT.hpp:188
VectorOfCacheable(const VectorOfCacheable &other)
Copy constructor.
Definition: VectorT.hpp:289
VectorOfCacheableKey(int32_t n, const CacheableKeyPtr &t)
Create a vector with n copies of t.
Definition: VectorT.hpp:316
PTR_TYPE back()
returns the last element.
Definition: VectorT.hpp:200
VectorOfCacheable(int32_t n)
Create a vector with n elements allocated.
Definition: VectorT.hpp:281
VectorOfCacheable()
Create an empty vector.
Definition: VectorT.hpp:277
void clear()
erases all elements.
VectorT(int32_t n, const PTR_TYPE &t)
Create a vector with n copies of t.
Definition: VectorT.hpp:157
int32_t capacity() const
return the number of elements allocated for this vector.
void erase(int32_t index)
Removes the object at the specified index from a vector.
Definition: VectorT.hpp:250
VectorOfCacheable(int32_t n, const CacheablePtr &t)
Create a vector with n copies of t.
Definition: VectorT.hpp:285
A vector of Cacheable objects that also extends SharedBase for smart pointers.
Definition: VectorT.hpp:269
_VectorOfCacheable::Iterator Iterator
Iterator class for the vector.
Definition: VectorT.hpp:274
void insert(int32_t index, const SharedBasePtr &t)
insert object at the given index.
This namespace contains all the GemFire C++ API classes, enumerations and globals.
Definition: Assert.hpp:19
VectorT()
Create an empty vector.
Definition: VectorT.hpp:145
void reserve(int32_t n)
reallocate a vector to hold n elements.
Definition: VectorT.hpp:182
~VectorT()
destructor, sets all SharedPtr elements to NULLPTR
Definition: VectorT.hpp:169
int32_t length() const
synonym for size.
Definition: VectorT.hpp:85
VectorOfCacheableKey()
Create an empty vector.
Definition: VectorT.hpp:308
const PTR_TYPE back() const
returns the last element.
Definition: VectorT.hpp:206
Interface of an iterator for VectorOfSharedBase.
Definition: VectorOfSharedBase.hpp:43
const PTR_TYPE front() const
returns the first element.
Definition: VectorT.hpp:194
const PTR_TYPE at(int32_t n) const
Return the n&#39;th element with bounds checking.
Definition: VectorT.hpp:127
bool empty() const
return true if the vector&#39;s size is 0.
void push_back(const SharedBasePtr &e)
insert a new element at the end.
void swap(VectorT &other)
swaps the contents of two vectors.
Definition: VectorT.hpp:224
void resize(int32_t n, const PTR_TYPE &t=gemfire::NullSharedBase::s_instancePtr)
inserts or erases elements at the end such that size becomes n.
Definition: VectorT.hpp:238
void erase(int32_t index)
removes the object at the specified index from a vector
Iterator begin() const
Get an iterator pointing to the start of vector.
VectorOfCacheableKey(const VectorOfCacheableKey &other)
Copy constructor.
Definition: VectorT.hpp:320
#define CPPCACHE_EXPORT
Defines a GemFire CPPCACHE export.
Definition: gf_base.hpp:51
This abstract base class is the base class of all user objects that have the shared capability of ref...
Definition: SharedBase.hpp:31
VectorT(const VectorT &other)
copy constructor
Definition: VectorT.hpp:163
Interface of an iterator for VectorT.
Definition: VectorT.hpp:32
PTR_TYPE operator[](int32_t n)
Return the n&#39;th element.
Definition: VectorT.hpp:109
Iterator end() const
Get an iterator pointing to the end of vector.
Definition: VectorT.hpp:139
PTR_TYPE at(int32_t n)
Return the n&#39;th element with bounds checking.
Definition: VectorT.hpp:121
int32_t max_size() const
return the largest possible size of the vector.
int32_t size() const
return the size of the vector.
void resize(int32_t n, const SharedBasePtr &t=gemfire::NullSharedBase::s_instancePtr)
inserts or erases elements at the end such that size becomes n.
void reserve(int32_t n)
reallocate a vector to hold n elements.
int32_t size() const
return the size of the vector.
Definition: VectorT.hpp:79
SharedBasePtr & back()
returns the last element.
Iterator end() const
Get an iterator pointing to the end of vector.
void push_back(const PTR_TYPE &e)
insert a new element at the end.
Definition: VectorT.hpp:212
_VectorOfCacheableKey::Iterator Iterator
Iterator class for the vector.
Definition: VectorT.hpp:305
SharedBasePtr & at(int32_t n)
Return the n&#39;th element with bounds checking.
void clear()
erases all elements.
Definition: VectorT.hpp:230
VectorOfCacheableKey(int32_t n)
Create a vector with n elements allocated.
Definition: VectorT.hpp:312
void insert(int32_t index, const PTR_TYPE &t)
insert object at the given position.
Definition: VectorT.hpp:244
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:35
VectorT(int32_t n)
Create a vector with n elements allocated.
Definition: VectorT.hpp:151

GemFire C++ Cache API Documentation