00001 #ifndef _GEMFIRE_HASHMAPT_HPP_
00002 #define _GEMFIRE_HASHMAPT_HPP_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "gfcpp_globals.hpp"
00013 #include "HashMapOfSharedBase.hpp"
00014 #include "Cacheable.hpp"
00015 #include "CacheableKey.hpp"
00016 #include "Exception.hpp"
00017
00018
00022 namespace gemfire
00023 {
00024
00026 template< typename TKEY, typename TVAL > class HashMapT
00027 {
00028 private:
00029
00030 HashMapOfSharedBase m_map;
00031
00032
00033 public:
00034
00035 class Iterator
00036 {
00037 private:
00038
00039 HashMapOfSharedBase::Iterator m_iter;
00040
00041
00042 inline Iterator( const HashMapOfSharedBase::Iterator& iter )
00043 : m_iter( iter ) { }
00044
00045
00046 Iterator( );
00047
00048
00049 public:
00050
00051 inline const TKEY first( ) const
00052 {
00053 return staticCast<TKEY>( m_iter.first( ) );
00054 }
00055
00056 inline const TVAL second( ) const
00057 {
00058 return staticCast<TVAL>( m_iter.second( ) );
00059 }
00060
00061 inline Iterator& operator ++ ( )
00062 {
00063 ++m_iter;
00064 return *this;
00065 }
00066
00067 inline void operator ++ ( int )
00068 {
00069 m_iter++;
00070 }
00071
00072 inline bool operator == ( const Iterator& other ) const
00073 {
00074 return ( m_iter == other.m_iter );
00075 }
00076
00077 inline bool operator != ( const Iterator& other ) const
00078 {
00079 return ( m_iter != other.m_iter );
00080 }
00081
00082
00083 friend class HashMapT;
00084 };
00085
00086
00087 static int32_t hasher( const SharedBasePtr& p )
00088 {
00089 return gemfire::hashFunction< TKEY >( staticCast<TKEY>( p ) );
00090 }
00091
00092 static bool equal_to( const SharedBasePtr& x, const SharedBasePtr& y )
00093 {
00094 return gemfire::equalToFunction< TKEY >( staticCast<TKEY>( x ),
00095 staticCast<TKEY>( y ) );
00096 }
00097
00099 inline int32_t size() const
00100 {
00101 return static_cast<int32_t> (m_map.size());
00102 }
00103
00105 inline int32_t max_size() const
00106 {
00107 return static_cast<int32_t>(m_map.max_size());
00108 }
00109
00111 inline bool empty( ) const
00112 {
00113 return m_map.empty( );
00114 }
00115
00117 inline int32_t bucket_count( ) const
00118 {
00119 return static_cast<int32_t> (m_map.bucket_count( ));
00120 }
00121
00123 inline void resize( int32_t n )
00124 {
00125 m_map.resize( n );
00126 }
00127
00129 inline void swap( HashMapT& other )
00130 {
00131 m_map.swap( other.m_map );
00132 }
00133
00137 inline bool insert( const TKEY& k, const TVAL& v )
00138 {
00139 return m_map.insert( k, v );
00140 }
00141
00143 inline void update( const TKEY& k, const TVAL& v )
00144 {
00145 m_map[k] = v;
00146 }
00147
00149 inline int32_t erase( const TKEY& k )
00150 {
00151 return m_map.erase( k );
00152 }
00153
00155 inline void clear( )
00156 {
00157 m_map.clear( );
00158 }
00159
00161 inline bool contains( const TKEY& k ) const
00162 {
00163 return m_map.contains( k );
00164 }
00165
00167 inline Iterator find( const TKEY& k ) const
00168 {
00169 return Iterator( m_map.find( k ) );
00170 }
00171
00173 int32_t count( const SharedBasePtr& k ) const
00174 {
00175 return m_map.count( k );
00176 }
00177
00181 inline TVAL operator [] ( const TKEY& k )
00182 {
00183 return staticCast<TVAL>( m_map[ k ] );
00184 }
00185
00187 inline Iterator begin( ) const
00188 {
00189 return Iterator( m_map.begin( ) );
00190 }
00191
00193 inline Iterator end( ) const
00194 {
00195 return Iterator( m_map.end( ) );
00196 }
00197
00199 inline HashMapT& operator = ( const HashMapT& other )
00200 {
00201 m_map = other.m_map;
00202 return *this;
00203 }
00204
00208 inline HashMapT( )
00209 : m_map( hasher, equal_to )
00210 {
00211 }
00212
00216 inline HashMapT( int32_t n )
00217 : m_map( n, hasher, equal_to )
00218 {
00219 }
00220
00222 inline HashMapT( const HashMapT& other )
00223 : m_map( other.m_map )
00224 {
00225 }
00226
00228 inline ~HashMapT( )
00229 {
00230 }
00231 };
00232
00233 typedef HashMapT<CacheableKeyPtr, CacheablePtr> _HashMapOfCacheable;
00234 typedef HashMapT<CacheableKeyPtr, ExceptionPtr> _HashMapOfException;
00235
00240 class CPPCACHE_EXPORT HashMapOfCacheable :
00241 public _HashMapOfCacheable, public SharedBase
00242 {
00243 public:
00245 typedef _HashMapOfCacheable::Iterator Iterator;
00246
00248 inline HashMapOfCacheable() :
00249 _HashMapOfCacheable() { }
00250
00252 inline HashMapOfCacheable(int32_t n) :
00253 _HashMapOfCacheable(n) { }
00254
00256 inline HashMapOfCacheable(const HashMapOfCacheable& other) :
00257 _HashMapOfCacheable(other) { }
00258 private:
00259 const HashMapOfCacheable& operator=( const HashMapOfCacheable& );
00260
00261 };
00262
00267 class CPPCACHE_EXPORT HashMapOfException :
00268 public _HashMapOfException, public SharedBase
00269 {
00270 public:
00272 typedef _HashMapOfException::Iterator Iterator;
00273
00275 inline HashMapOfException() :
00276 _HashMapOfException() { }
00277
00279 inline HashMapOfException(int32_t n) :
00280 _HashMapOfException(n) { }
00281
00283 inline HashMapOfException(const HashMapOfException& other) :
00284 _HashMapOfException(other) { }
00285
00286 private:
00287 const HashMapOfException& operator=( const HashMapOfException& );
00288
00289 };
00290
00291 typedef SharedPtr<HashMapOfCacheable> HashMapOfCacheablePtr;
00292 typedef SharedPtr<HashMapOfException> HashMapOfExceptionPtr;
00293
00294 }
00295
00296
00297 #endif