00001 #ifndef _GEMFIRE_HASHMAPT_HPP_
00002 #define _GEMFIRE_HASHMAPT_HPP_
00003
00004
00005
00006
00007
00008
00009
00010 #include "gfcpp_globals.hpp"
00011 #include "HashMapOfSharedBase.hpp"
00012 #include "Cacheable.hpp"
00013 #include "CacheableKey.hpp"
00014 #include "Exception.hpp"
00015
00016
00020 namespace gemfire
00021 {
00022
00024 template< typename TKEY, typename TVAL > class HashMapT
00025 {
00026 private:
00027
00028 HashMapOfSharedBase m_map;
00029
00030
00031 public:
00032
00033 class Iterator
00034 {
00035 private:
00036
00037 HashMapOfSharedBase::Iterator m_iter;
00038
00039
00040 inline Iterator( const HashMapOfSharedBase::Iterator& iter )
00041 : m_iter( iter ) { }
00042
00043
00044 Iterator( );
00045
00046
00047 public:
00048
00049 inline const TKEY first( ) const
00050 {
00051 return staticCast<TKEY>( m_iter.first( ) );
00052 }
00053
00054 inline const TVAL second( ) const
00055 {
00056 return staticCast<TVAL>( m_iter.second( ) );
00057 }
00058
00059 inline Iterator& operator ++ ( )
00060 {
00061 ++m_iter;
00062 return *this;
00063 }
00064
00065 inline void operator ++ ( int )
00066 {
00067 m_iter++;
00068 }
00069
00070 inline bool operator == ( const Iterator& other ) const
00071 {
00072 return ( m_iter == other.m_iter );
00073 }
00074
00075 inline bool operator != ( const Iterator& other ) const
00076 {
00077 return ( m_iter != other.m_iter );
00078 }
00079
00080
00081 friend class HashMapT;
00082 };
00083
00084
00085 static size_t hasher( const SharedBasePtr& p )
00086 {
00087 return gemfire::hashFunction< TKEY >( staticCast<TKEY>( p ) );
00088 }
00089
00090 static bool equal_to( const SharedBasePtr& x, const SharedBasePtr& y )
00091 {
00092 return gemfire::equalToFunction< TKEY >( staticCast<TKEY>( x ),
00093 staticCast<TKEY>( y ) );
00094 }
00095
00097 inline size_t size() const
00098 {
00099 return m_map.size();
00100 }
00101
00103 inline size_t max_size() const
00104 {
00105 return m_map.max_size();
00106 }
00107
00109 inline bool empty( ) const
00110 {
00111 return m_map.empty( );
00112 }
00113
00115 inline size_t bucket_count( ) const
00116 {
00117 return m_map.bucket_count( );
00118 }
00119
00121 inline void resize( size_t n )
00122 {
00123 m_map.resize( n );
00124 }
00125
00127 inline void swap( HashMapT& other )
00128 {
00129 m_map.swap( other.m_map );
00130 }
00131
00135 inline bool insert( const TKEY& k, const TVAL& v )
00136 {
00137 return m_map.insert( k, v );
00138 }
00139
00141 inline void update( const TKEY& k, const TVAL& v )
00142 {
00143 m_map[k] = v;
00144 }
00145
00147 inline size_t erase( const TKEY& k )
00148 {
00149 return m_map.erase( k );
00150 }
00151
00153 inline void clear( )
00154 {
00155 m_map.clear( );
00156 }
00157
00159 inline bool contains( const TKEY& k ) const
00160 {
00161 return m_map.contains( k );
00162 }
00163
00165 inline Iterator find( const TKEY& k ) const
00166 {
00167 return Iterator( m_map.find( k ) );
00168 }
00169
00171 size_t count( const SharedBasePtr& k ) const
00172 {
00173 return m_map.count( k );
00174 }
00175
00179 inline TVAL operator [] ( const TKEY& k )
00180 {
00181 return staticCast<TVAL>( m_map[ k ] );
00182 }
00183
00185 inline Iterator begin( ) const
00186 {
00187 return Iterator( m_map.begin( ) );
00188 }
00189
00191 inline Iterator end( ) const
00192 {
00193 return Iterator( m_map.end( ) );
00194 }
00195
00197 inline HashMapT& operator = ( const HashMapT& other )
00198 {
00199 m_map = other.m_map;
00200 return *this;
00201 }
00202
00206 inline HashMapT( )
00207 : m_map( hasher, equal_to )
00208 {
00209 }
00210
00214 inline HashMapT( size_t n )
00215 : m_map( n, hasher, equal_to )
00216 {
00217 }
00218
00220 inline HashMapT( const HashMapT& other )
00221 : m_map( other.m_map )
00222 {
00223 }
00224
00226 inline ~HashMapT( )
00227 {
00228 }
00229 };
00230
00231 typedef HashMapT<CacheableKeyPtr, CacheablePtr> _HashMapOfCacheable;
00232 typedef HashMapT<CacheableKeyPtr, ExceptionPtr> _HashMapOfException;
00233
00238 class CPPCACHE_EXPORT HashMapOfCacheable :
00239 public _HashMapOfCacheable, public SharedBase
00240 {
00241 public:
00243 typedef _HashMapOfCacheable::Iterator Iterator;
00244
00246 inline HashMapOfCacheable() :
00247 _HashMapOfCacheable() { }
00248
00250 inline HashMapOfCacheable(size_t n) :
00251 _HashMapOfCacheable(n) { }
00252
00254 inline HashMapOfCacheable(const HashMapOfCacheable& other) :
00255 _HashMapOfCacheable(other) { }
00256 };
00257
00262 class CPPCACHE_EXPORT HashMapOfException :
00263 public _HashMapOfException, public SharedBase
00264 {
00265 public:
00267 typedef _HashMapOfException::Iterator Iterator;
00268
00270 inline HashMapOfException() :
00271 _HashMapOfException() { }
00272
00274 inline HashMapOfException(size_t n) :
00275 _HashMapOfException(n) { }
00276
00278 inline HashMapOfException(const HashMapOfException& other) :
00279 _HashMapOfException(other) { }
00280 };
00281
00282 typedef SharedPtr<HashMapOfCacheable> HashMapOfCacheablePtr;
00283 typedef SharedPtr<HashMapOfException> HashMapOfExceptionPtr;
00284
00285 }
00286
00287
00288 #endif