E:/gfcppsancout/product/include/gfcpp/VectorT.hpp

Go to the documentation of this file.
00001 
00002 #ifndef _GEMFIRE_VECTORT_HPP_
00003 #define _GEMFIRE_VECTORT_HPP_
00004 
00005 /*=========================================================================
00006  * (c) Copyright 2002-2007, GemStone Systems, Inc. All Rights Reserved.
00007  * 1260 NW Waterhouse Ave., Suite 200,  Beaverton, OR 97006
00008  *========================================================================
00009  */
00010 
00011 #include "gfcpp_globals.hpp"
00012 #include "VectorOfSharedBase.hpp"
00013 #include "Cacheable.hpp"
00014 #include "CacheableKey.hpp"
00015 
00019 namespace gemfire {
00020 
00022 template < class PTR_TYPE > class VectorT
00023 {
00024   private:
00025     VectorOfSharedBase m_vector;
00026 
00027   public:
00028 
00030     class Iterator
00031     {
00032       private:
00033 
00034         VectorOfSharedBase::Iterator m_iter;
00035 
00036 
00037         inline Iterator( const VectorOfSharedBase::Iterator& iter )
00038           : m_iter( iter ) { }
00039 
00040         // Never defined.
00041         Iterator( );
00042 
00043 
00044       public:
00045 
00046         inline const PTR_TYPE operator * ( ) const
00047         {
00048           return staticCast<PTR_TYPE>( *m_iter );
00049         }
00050 
00051         inline Iterator& operator ++ ( )
00052         {
00053           ++m_iter;
00054           return *this;
00055         }
00056 
00057         inline void operator ++ ( int )
00058         {
00059           m_iter++;
00060         }
00061 
00062         inline bool operator == ( const Iterator& other ) const
00063         {
00064           return ( m_iter == other.m_iter );
00065         }
00066 
00067         inline bool operator != ( const Iterator& other ) const
00068         {
00069           return ( m_iter != other.m_iter );
00070         }
00071 
00072 
00073         friend class VectorT;
00074     };
00075 
00077     inline int32_t size( ) const
00078     {
00079       return static_cast<int32_t> (m_vector.size());
00080     }
00081 
00083     inline int32_t length( ) const
00084     {
00085       return static_cast<int32_t> (m_vector.size());
00086     }
00087 
00089     inline int32_t max_size( ) const
00090     {
00091       return static_cast<int32_t> (m_vector.max_size());
00092     }
00093 
00095     inline int32_t capacity( ) const
00096     {
00097       return static_cast<int32_t> (m_vector.capacity());
00098     }
00099 
00101     inline bool empty( ) const
00102     {
00103       return m_vector.empty();
00104     }
00105 
00107     inline PTR_TYPE operator [] ( int32_t n )
00108     {
00109       return staticCast<PTR_TYPE>( m_vector[n] );
00110     }
00111 
00113     inline const PTR_TYPE operator [] ( int32_t n ) const
00114     {
00115       return staticCast<PTR_TYPE>( m_vector[n] );
00116     }
00117 
00119     inline PTR_TYPE at( int32_t n )
00120     {
00121       return staticCast<PTR_TYPE>( m_vector.at( n ) );
00122     }
00123 
00125     inline const PTR_TYPE at( int32_t n ) const
00126     {
00127       return staticCast<PTR_TYPE>( m_vector.at( n ) );
00128     }
00129 
00131     inline Iterator begin( ) const
00132     {
00133       return Iterator( m_vector.begin( ) );
00134     }
00135 
00137     inline Iterator end( ) const
00138     {
00139       return Iterator( m_vector.end( ) );
00140     }
00141 
00143     inline VectorT( )
00144     : m_vector( )
00145     {
00146     }
00147 
00149     inline VectorT( int32_t n )
00150     : m_vector( n )
00151     {
00152     }
00153 
00155     inline VectorT( int32_t n, const PTR_TYPE& t )
00156     : m_vector( n, t )
00157     {
00158     }
00159 
00161     inline VectorT( const VectorT& other )
00162     : m_vector( other.m_vector )
00163     {
00164     }
00165 
00167     inline ~VectorT( )
00168     {
00169       // destructor of m_vector field does all the work.
00170     }
00171 
00173     inline VectorT& operator = ( const VectorT& other )
00174     {
00175       m_vector = other.m_vector;
00176       return *this;
00177     }
00178 
00180     inline void reserve( int32_t n )
00181     {
00182       m_vector.reserve( n );
00183     }
00184 
00186     inline PTR_TYPE front( )
00187     {
00188       return staticCast<PTR_TYPE>( m_vector.front( ) );
00189     }
00190 
00192     inline const PTR_TYPE front( ) const
00193     {
00194       return staticCast<PTR_TYPE>( m_vector.front( ) );
00195     }
00196 
00198     inline PTR_TYPE back( )
00199     {
00200       return staticCast<PTR_TYPE>( m_vector.back( ) );
00201     }
00202 
00204     inline const PTR_TYPE back( ) const
00205     {
00206       return staticCast<PTR_TYPE>( m_vector.back( ) );
00207     }
00208 
00210     inline void push_back( const PTR_TYPE& e )
00211     {
00212       m_vector.push_back( e );
00213     }
00214 
00216     inline void pop_back( )
00217     {
00218       m_vector.pop_back();
00219     }
00220 
00222     inline void swap( VectorT& other )
00223     {
00224       m_vector.swap( other.m_vector );
00225     }
00226 
00228     inline void clear( )
00229     {
00230       m_vector.clear();
00231     }
00232 
00236     inline void resize(int32_t n, const PTR_TYPE& t = NULLPTR)
00237     {
00238       m_vector.resize( n, t );
00239     }
00240 
00242     inline void insert( int32_t index, const PTR_TYPE& t )
00243     {
00244       m_vector.insert( index, t );
00245     }
00246 
00248     inline void erase( int32_t index )
00249     {
00250       m_vector.erase( index );
00251     }
00252 
00253 };
00254 
00255 typedef VectorT<CacheablePtr> _VectorOfCacheable;
00256 typedef VectorT<CacheableKeyPtr> _VectorOfCacheableKey;
00257 typedef VectorT<RegionEntryPtr> VectorOfRegionEntry;
00258 typedef VectorT<RegionPtr> VectorOfRegion;
00259 typedef VectorT<CacheableStringPtr> VectorOfCacheableString;
00260 typedef VectorT< CqListenerPtr > VectorOfCqListener;
00261 typedef VectorT< CqQueryPtr > VectorOfCqQuery;
00262 
00267 class CPPCACHE_EXPORT VectorOfCacheable :
00268   public _VectorOfCacheable, public SharedBase
00269 {
00270 public:
00272   typedef _VectorOfCacheable::Iterator Iterator;
00273 
00275   inline VectorOfCacheable() :
00276     _VectorOfCacheable() { }
00277 
00279   inline VectorOfCacheable(int32_t n) :
00280     _VectorOfCacheable(n) { }
00281 
00283   inline VectorOfCacheable(int32_t n, const CacheablePtr& t ) :
00284     _VectorOfCacheable(n, t) { }
00285 
00287   inline VectorOfCacheable(const VectorOfCacheable& other) :
00288     _VectorOfCacheable(other) { }
00289 
00290 private:
00291   const VectorOfCacheable& operator=( const VectorOfCacheable& );
00292 };
00293 
00298 class CPPCACHE_EXPORT VectorOfCacheableKey :
00299   public _VectorOfCacheableKey, public SharedBase
00300 {
00301 public:
00303   typedef _VectorOfCacheableKey::Iterator Iterator;
00304 
00306   inline VectorOfCacheableKey() :
00307     _VectorOfCacheableKey() { }
00308 
00310   inline VectorOfCacheableKey(int32_t n) :
00311     _VectorOfCacheableKey(n) { }
00312 
00314   inline VectorOfCacheableKey(int32_t n, const CacheableKeyPtr& t ) :
00315     _VectorOfCacheableKey(n, t) { }
00316 
00318   inline VectorOfCacheableKey(const VectorOfCacheableKey& other) :
00319     _VectorOfCacheableKey(other) { }
00320 
00321 private:
00322   const VectorOfCacheableKey& operator=( const VectorOfCacheableKey& );
00323 
00324 };
00325 
00326 typedef SharedPtr<VectorOfCacheable> VectorOfCacheablePtr;
00327 typedef SharedPtr<VectorOfCacheableKey> VectorOfCacheableKeyPtr;
00328 
00329 }
00330 
00331 #endif

GemFire C++ Cache API Documentation