Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Hash_Cache_Map_Manager_T.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Hash_Cache_Map_Manager_T.h
00006  *
00007  *  $Id: Hash_Cache_Map_Manager_T.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef HASH_CACHE_MAP_MANAGER_T_H
00015 #define HASH_CACHE_MAP_MANAGER_T_H
00016 #include "ace/pre.h"
00017 
00018 #include "ace/Hash_Map_Manager_T.h"
00019 #include "ace/Cache_Map_Manager_T.h"
00020 #include "ace/Synch.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 #define  ACE_LACKS_PRAGMA_ONCE
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 // Forward declaration.
00027 class ACE_Allocator;
00028 
00029 #if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES)
00030 #define ACE_CACHE_MAP_MANAGER \
00031         ACE_Cache_Map_Manager<KEY, \
00032                               VALUE, \
00033                               ACE_Hash_Map_Manager_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \
00034                               ACE_Hash_Map_Iterator_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \
00035                               ACE_Hash_Map_Reverse_Iterator_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \
00036                               CACHING_STRATEGY, \
00037                               ATTRIBUTES>
00038 #else
00039 #define ACE_CACHE_MAP_MANAGER \
00040         ACE_Cache_Map_Manager<KEY, \
00041                               VALUE, \
00042                               ACE_Hash_Map_Manager_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \
00043                               CACHING_STRATEGY, \
00044                               ATTRIBUTES>
00045 #endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */
00046 
00047 // For linkers that cant grok long names.
00048 #define ACE_Hash_Cache_Map_Manager AHCMM
00049 
00050  /**
00051   * @class ACE_Hash_Cache_Map_Manager
00052   *
00053   * @brief Defines a abstraction which will purge entries from a map.
00054   * The map considered is the ACE_Hash_Map_Manager_Ex.
00055   *
00056   * The Hash_Cache_Map_Manager will manage the map it contains
00057   * and provide purging on demand from the map. The strategy for
00058   * caching is decided by the user and provided to the Cache
00059   * Manager.  The Cache Manager acts as a agent and communicates
00060   * between the Map and the Strategy for purging entries from the
00061   * map.  To tap the optimal methods like find(key,value,entry)
00062   * present in the ACE_Hash_Map_Manager,
00063   * Hash_Cache_Map_Manager provides extra functionality on top
00064   * of the Cache_Map_Manager.
00065   * No locking mechanism provided since locking at this level
00066   * isnt efficient.  Locking has to be provided by the
00067   * application.
00068   */
00069 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES>
00070 class ACE_Hash_Cache_Map_Manager : public ACE_CACHE_MAP_MANAGER
00071 {
00072  public:
00073 
00074   /**
00075    * The actual value mapped to the key in the map. The <attributes>
00076    * are used by the strategy and is transparent to the user of this
00077    * class.
00078    */
00079   typedef ACE_Pair<VALUE, ATTRIBUTES> CACHE_VALUE;
00080   typedef ACE_Hash_Map_Manager_Ex<KEY, CACHE_VALUE, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex> HASH_MAP;
00081   typedef ACE_Hash_Map_Entry<KEY, CACHE_VALUE> CACHE_ENTRY;
00082   typedef KEY key_type;
00083   typedef VALUE mapped_type;
00084 
00085   // = Initialization and termination methods.
00086   /// Initialize a <Hash_Cache_Map_Manager> with <size> entries.
00087   ACE_Hash_Cache_Map_Manager (CACHING_STRATEGY &caching_s,
00088                               size_t size = ACE_DEFAULT_MAP_SIZE,
00089                               ACE_Allocator *alloc = 0);
00090 
00091   /// Close down a <Cache_Map_Manager> and release dynamically allocated
00092   /// resources.
00093   ~ACE_Hash_Cache_Map_Manager (void);
00094 
00095   /**
00096    * Associate <key> with <value>.  If <key> is already in the
00097    * MAP then the ENTRY is not changed.  Returns 0 if a new entry is
00098    * bound successfully, returns 1 if an attempt is made to bind an
00099    * existing entry, and returns -1 if failures occur.
00100    */
00101   int bind (const KEY &key,
00102             const VALUE &value);
00103 
00104   /**
00105    * Same as a normal bind, except the cache entry is also passed back
00106    * to the caller.  The entry in this case will either be the newly
00107    * created entry, or the existing one.
00108    */
00109   int bind (const KEY &key,
00110             const VALUE &value,
00111             CACHE_ENTRY *&entry);
00112 
00113   /// Loopkup entry<key,value> in the cache.
00114   int find (const KEY &key,
00115             VALUE &value);
00116 
00117   /// Is <key> in the cache?
00118   int find (const KEY &key);
00119 
00120   /// Obtain the entry when the find succeeds.
00121   int find (const KEY &key,
00122             CACHE_ENTRY *&entry);
00123 
00124   /**
00125    * Reassociate the <key> with <value>. If the <key> already exists
00126    * in the cache then returns 1, on a new bind returns 0 and returns
00127    * -1 in case of any failures.
00128    */
00129   int rebind (const KEY &key,
00130               const VALUE &value);
00131 
00132   /**
00133    * Reassociate <key> with <value>, storing the old value into the
00134    * "out" parameter <old_value>.  The function fails if <key> is not
00135    * in the cache for caches that do not allow user specified keys.
00136    * However, for caches that allow user specified keys, if the key is
00137    * not in the cache, a new <key>/<value> association is created.
00138    */
00139   int rebind (const KEY &key,
00140               const VALUE &value,
00141               VALUE &old_value);
00142 
00143   /**
00144    * Reassociate <key> with <value>, storing the old key and value
00145    * into the "out" parameters <old_key> and <old_value>.  The
00146    * function fails if <key> is not in the cache for caches that do not
00147    * allow user specified keys.  However, for caches that allow user
00148    * specified keys, if the key is not in the cache, a new <key>/<value>
00149    * association is created.
00150    */
00151   int rebind (const KEY &key,
00152               const VALUE &value,
00153               KEY &old_key,
00154               VALUE &old_value);
00155 
00156   /**
00157    * Same as a normal rebind, except the cache entry is also passed back
00158    * to the caller.  The entry in this case will either be the newly
00159    * created entry, or the existing one.
00160    */
00161   int rebind (const KEY &key,
00162               const VALUE &value,
00163               CACHE_ENTRY *&entry);
00164 
00165   /**
00166    * Associate <key> with <value> if and only if <key> is not in the
00167    * cache.  If <key> is already in the cache, then the <value> parameter
00168    * is overwritten with the existing value in the cache. Returns 0 if a
00169    * new <key>/<value> association is created.  Returns 1 if an
00170    * attempt is made to bind an existing entry.  This function fails
00171    * for maps that do not allow user specified keys.
00172    */
00173   int trybind (const KEY &key,
00174                VALUE &value);
00175 
00176   /**
00177    * Same as a normal trybind, except the cache entry is also passed
00178    * back to the caller.  The entry in this case will either be the
00179    * newly created entry, or the existing one.
00180    */
00181   int trybind (const KEY &key,
00182                VALUE &value,
00183                CACHE_ENTRY *&entry);
00184 
00185   /// Remove <key> from the cache.
00186   int unbind (const KEY &key);
00187 
00188   /// Remove <key> from the cache, and return the <value> associated with
00189   /// <key>.
00190   int unbind (const KEY &key,
00191               VALUE &value);
00192 
00193   /// Remove entry from map.
00194   int unbind (CACHE_ENTRY *entry);
00195 
00196 protected:
00197 
00198   /// Base class.
00199   typedef ACE_CACHE_MAP_MANAGER ACE_HCMM_BASE;
00200 };
00201 
00202 
00203 #if defined (__ACE_INLINE__)
00204 #include "ace/Hash_Cache_Map_Manager_T.i"
00205 #endif /* __ACE_INLINE__ */
00206 
00207 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00208 #include "ace/Hash_Cache_Map_Manager_T.cpp"
00209 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00210 
00211 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00212 #pragma implementation ("Hash_Cache_Map_Manager_T.cpp")
00213 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00214 
00215 #include "ace/post.h"
00216 #endif /* HASH_CACHE_MAP_MANAGER_T_H */

Generated on Mon Jun 16 11:19:46 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002