VMware GemFire Native Client Cache Reference  9.0.6
HashMapT.hpp
Go to the documentation of this file.
1 #ifndef _GEMFIRE_HASHMAPT_HPP_
2 #define _GEMFIRE_HASHMAPT_HPP_
3 
4 /*=========================================================================
5  * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
6  * This product is protected by U.S. and international copyright
7  * and intellectual property laws. Pivotal products are covered by
8  * more patents listed at http://www.pivotal.io/patents.
9  *========================================================================
10  */
11 
12 #include "gfcpp_globals.hpp"
13 #include "HashMapOfSharedBase.hpp"
14 #include "Cacheable.hpp"
15 #include "CacheableKey.hpp"
16 #include "Exception.hpp"
17 
18 
22 namespace gemfire
23 {
24 
26  template< typename TKEY, typename TVAL > class HashMapT
27  {
28  private:
29 
30  HashMapOfSharedBase m_map;
31 
32 
33  public:
34 
35  class Iterator
36  {
37  private:
38 
40 
41 
42  inline Iterator( const HashMapOfSharedBase::Iterator& iter )
43  : m_iter( iter ) { }
44 
45  // Never defined.
46  Iterator( );
47 
48 
49  public:
50 
51  inline const TKEY first( ) const
52  {
53  return staticCast<TKEY>( m_iter.first( ) );
54  }
55 
56  inline const TVAL second( ) const
57  {
58  return staticCast<TVAL>( m_iter.second( ) );
59  }
60 
61  inline Iterator& operator ++ ( )
62  {
63  ++m_iter;
64  return *this;
65  }
66 
67  inline void operator ++ ( int )
68  {
69  m_iter++;
70  }
71 
72  inline bool operator == ( const Iterator& other ) const
73  {
74  return ( m_iter == other.m_iter );
75  }
76 
77  inline bool operator != ( const Iterator& other ) const
78  {
79  return ( m_iter != other.m_iter );
80  }
81 
82 
83  friend class HashMapT;
84  };
85 
86 
87  static int32_t hasher( const SharedBasePtr& p )
88  {
89  return gemfire::hashFunction< TKEY >( staticCast<TKEY>( p ) );
90  }
91 
92  static bool equal_to( const SharedBasePtr& x, const SharedBasePtr& y )
93  {
94  return gemfire::equalToFunction< TKEY >( staticCast<TKEY>( x ),
95  staticCast<TKEY>( y ) );
96  }
97 
99  inline int32_t size() const
100  {
101  return static_cast<int32_t> (m_map.size());
102  }
103 
105  inline int32_t max_size() const
106  {
107  return static_cast<int32_t>(m_map.max_size());
108  }
109 
111  inline bool empty( ) const
112  {
113  return m_map.empty( );
114  }
115 
117  inline int32_t bucket_count( ) const
118  {
119  return static_cast<int32_t> (m_map.bucket_count( ));
120  }
121 
123  inline void resize( int32_t n )
124  {
125  m_map.resize( n );
126  }
127 
129  inline void swap( HashMapT& other )
130  {
131  m_map.swap( other.m_map );
132  }
133 
137  inline bool insert( const TKEY& k, const TVAL& v )
138  {
139  return m_map.insert( k, v );
140  }
141 
143  inline void update( const TKEY& k, const TVAL& v )
144  {
145  m_map[k] = v;
146  }
147 
149  inline int32_t erase( const TKEY& k )
150  {
151  return m_map.erase( k );
152  }
153 
155  inline void clear( )
156  {
157  m_map.clear( );
158  }
159 
161  inline bool contains( const TKEY& k ) const
162  {
163  return m_map.contains( k );
164  }
165 
167  inline Iterator find( const TKEY& k ) const
168  {
169  return Iterator( m_map.find( k ) );
170  }
171 
173  int32_t count( const SharedBasePtr& k ) const
174  {
175  return m_map.count( k );
176  }
177 
181  inline TVAL operator [] ( const TKEY& k )
182  {
183  return staticCast<TVAL>( m_map[ k ] );
184  }
185 
187  inline Iterator begin( ) const
188  {
189  return Iterator( m_map.begin( ) );
190  }
191 
193  inline Iterator end( ) const
194  {
195  return Iterator( m_map.end( ) );
196  }
197 
199  inline HashMapT& operator = ( const HashMapT& other )
200  {
201  m_map = other.m_map;
202  return *this;
203  }
204 
208  inline HashMapT( )
209  : m_map( hasher, equal_to )
210  {
211  }
212 
216  inline HashMapT( int32_t n )
217  : m_map( n, hasher, equal_to )
218  {
219  }
220 
222  inline HashMapT( const HashMapT& other )
223  : m_map( other.m_map )
224  {
225  }
226 
228  inline ~HashMapT( )
229  {
230  }
231  };
232 
235 
241  public _HashMapOfCacheable, public SharedBase
242  {
243  public:
245  typedef _HashMapOfCacheable::Iterator Iterator;
246 
249  _HashMapOfCacheable() { }
250 
252  inline HashMapOfCacheable(int32_t n) :
253  _HashMapOfCacheable(n) { }
254 
256  inline HashMapOfCacheable(const HashMapOfCacheable& other) :
257  _HashMapOfCacheable(other) { }
258  private:
260 
261  };
262 
268  public _HashMapOfException, public SharedBase
269  {
270  public:
272  typedef _HashMapOfException::Iterator Iterator;
273 
276  _HashMapOfException() { }
277 
279  inline HashMapOfException(int32_t n) :
280  _HashMapOfException(n) { }
281 
283  inline HashMapOfException(const HashMapOfException& other) :
284  _HashMapOfException(other) { }
285 
286  private:
288 
289  };
290 
293 
294 }
295 
296 
297 #endif
Interface of an iterator for HashMapOfSharedBase.
Definition: HashMapOfSharedBase.hpp:52
bool empty() const
true if the hash_map&#39;s size is 0.
void clear()
Erases all of the elements.
Definition: HashMapT.hpp:155
Iterator find(const SharedBasePtr &k) const
Finds an element whose key is k.
void update(const TKEY &k, const TVAL &v)
Updates a value whose key must exist.
Definition: HashMapT.hpp:143
int32_t count(const SharedBasePtr &k) const
Counts the number of elements whose key is k.
Definition: HashMapT.hpp:173
Iterator end() const
Get an iterator pointing to the end of hash_map.
Represents a HashMap of SharedBase
Definition: HashMapOfSharedBase.hpp:39
void swap(HashMapOfSharedBase &other)
Swaps the contents of two hash_maps.
bool contains(const SharedBasePtr &k) const
Check if a given key k exists in the hash_map.
int32_t max_size() const
Returns the largest possible size of the hash_map.
HashMapOfCacheable(int32_t n)
Creates an empty hash map with at least n buckets.
Definition: HashMapT.hpp:252
bool contains(const TKEY &k) const
Check if a given key k exists in the hash map.
Definition: HashMapT.hpp:161
Iterator end() const
Get an iterator pointing to the end of hash_map.
Definition: HashMapT.hpp:193
HashMapT()
Creates an empty hash map with hash function hasher<TKEY> and equal to function equal_to<TKEY>.
Definition: HashMapT.hpp:208
bool empty() const
true if the hash map&#39;s size is 0.
Definition: HashMapT.hpp:111
HashMapT & operator=(const HashMapT &other)
Assignment operator.
Definition: HashMapT.hpp:199
A map of CacheableKey objects to Exception that also extends SharedBase for smart pointers...
Definition: HashMapT.hpp:267
~HashMapT()
Destructor: the destructor of m_map would do required stuff.
Definition: HashMapT.hpp:228
int32_t erase(const TKEY &k)
Erases the element whose key is k.
Definition: HashMapT.hpp:149
HashMapOfCacheable()
Creates an empty hash map.
Definition: HashMapT.hpp:248
TVAL operator[](const TKEY &k)
Returns a copy of the object that is associated with a particular key.
Definition: HashMapT.hpp:181
HashMapOfCacheable(const HashMapOfCacheable &other)
Copy constructor.
Definition: HashMapT.hpp:256
void swap(HashMapT &other)
Swaps the contents of two hash maps.
Definition: HashMapT.hpp:129
HashMapT(const HashMapT &other)
Copy constructor.
Definition: HashMapT.hpp:222
This namespace contains all the GemFire C++ API classes, enumerations and globals.
Definition: Assert.hpp:19
HashMap of TKEY to TVAL.
Definition: HashMapT.hpp:26
HashMapOfException(const HashMapOfException &other)
Copy constructor.
Definition: HashMapT.hpp:283
bool insert(const TKEY &k, const TVAL &v)
Inserts the <k, v> pair into the hash map, when k does not exist in the hash map. ...
Definition: HashMapT.hpp:137
Iterator find(const TKEY &k) const
Finds an element whose key is k.
Definition: HashMapT.hpp:167
A map of CacheableKey objects to Cacheable that also extends SharedBase for smart pointers...
Definition: HashMapT.hpp:240
int32_t max_size() const
Returns the largest possible size of the hash map.
Definition: HashMapT.hpp:105
int32_t erase(const SharedBasePtr &k)
Erases the element whose key is k.
void clear()
Erases all of the elements.
Iterator begin() const
Get an iterator pointing to the start of hash_map.
void resize(int32_t n)
Increases the bucket count to at least n.
int32_t size() const
Returns the size of the hash map.
Definition: HashMapT.hpp:99
HashMapT(int32_t n)
Creates an empty hash map with at least n buckets and hash function hasher<TKEY> and equal to functio...
Definition: HashMapT.hpp:216
_HashMapOfException::Iterator Iterator
Iterator class for the hash map.
Definition: HashMapT.hpp:272
#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
HashMapOfException()
Creates an empty hash map.
Definition: HashMapT.hpp:275
int32_t bucket_count() const
Returns the number of buckets used by the hash_map.
bool insert(const SharedBasePtr &k, const SharedBasePtr &v)
Inserts the <k, v> pair into the hash_map, when k does not exist in the hash_map. ...
HashMapOfException(int32_t n)
Creates an empty hash map with at least n buckets.
Definition: HashMapT.hpp:279
int32_t bucket_count() const
Returns the number of buckets used by the hash map.
Definition: HashMapT.hpp:117
void resize(int32_t n)
Increases the bucket count to at least n.
Definition: HashMapT.hpp:123
int32_t count(const SharedBasePtr &k) const
Counts the number of elements whose key is k.
_HashMapOfCacheable::Iterator Iterator
Iterator class for the hash map.
Definition: HashMapT.hpp:245
Defines a reference counted shared pointer.
Definition: SharedPtr.hpp:35
int32_t size() const
Returns the size of the hash_map.
Iterator begin() const
Get an iterator pointing to the start of hash_map.
Definition: HashMapT.hpp:187

GemFire C++ Cache API Documentation