Active_Map_Manager_T.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Active_Map_Manager_T.h
00006  *
00007  *  Active_Map_Manager_T.h,v 4.14 2005/10/28 16:14:51 ossama Exp
00008  *
00009  *  @author Irfan Pyarali
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef ACE_ACTIVE_MAP_MANAGER_T_H
00015 #define ACE_ACTIVE_MAP_MANAGER_T_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/Map_Manager.h"
00019 #include "ace/Active_Map_Manager.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #include "ace/Null_Mutex.h"
00026 
00027 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00028 
00029 /**
00030  * @class ACE_Active_Map_Manager
00031  *
00032  * @brief Define a map abstraction that associates system generated
00033  * keys with user specified values.
00034  *
00035  * Since the key is system generated, searches are very fast and
00036  * take a constant amount of time.
00037  */
00038 template <class T>
00039 class ACE_Active_Map_Manager : public ACE_Map_Manager<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex>
00040 {
00041 public:
00042 
00043   // = Traits.
00044   typedef ACE_Active_Map_Manager_Key key_type;
00045   typedef T mapped_type;
00046 
00047   typedef ACE_Map_Entry<ACE_Active_Map_Manager_Key, T> ENTRY;
00048   typedef ACE_Map_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> ITERATOR;
00049   typedef ACE_Map_Reverse_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> REVERSE_ITERATOR;
00050 
00051   typedef ENTRY entry;
00052   typedef ITERATOR iterator;
00053   typedef REVERSE_ITERATOR reverse_iterator;
00054 
00055   // = Initialization and termination methods.
00056   /// Initialize a <Active_Map_Manager> with the <ACE_DEFAULT_MAP_SIZE>.
00057   ACE_Active_Map_Manager (ACE_Allocator *alloc = 0);
00058 
00059   /// Initialize a <Active_Map_Manager> with <size> entries.
00060   ACE_Active_Map_Manager (size_t size,
00061                           ACE_Allocator *alloc = 0);
00062 
00063   /// Close down a <Active_Map_Manager> and release dynamically
00064   /// allocated resources.
00065   ~ACE_Active_Map_Manager (void);
00066 
00067   /// Initialize a <Active_Map_Manager> with size <length>.
00068   int open (size_t length = ACE_DEFAULT_MAP_SIZE,
00069             ACE_Allocator *alloc = 0);
00070 
00071   /// Close down a <Active_Map_Manager> and release dynamically
00072   /// allocated resources.
00073   int close (void);
00074 
00075   /// Add <value> to the map, and the corresponding key produced by the
00076   /// Active_Map_Manager is returned through <key>.
00077   int bind (const T &value,
00078             ACE_Active_Map_Manager_Key &key);
00079 
00080   /// Add <value> to the map.  The user does not care about the
00081   /// corresponding key produced by the Active_Map_Manager.
00082   int bind (const T &value);
00083 
00084   /**
00085    * Reserves a slot in the internal structure and returns the key and
00086    * a pointer to the value.  User should place their <value> into
00087    * <*internal_value>.  This method is useful in reducing the number
00088    * of copies required in some cases.  Note that <internal_value> is
00089    * only a temporary pointer and will change when the map resizes.
00090    * Therefore, the user should use the pointer immediately and not
00091    * hold on to it.
00092    */
00093   int bind (ACE_Active_Map_Manager_Key &key,
00094             T *&internal_value);
00095 
00096   /// Reassociate <key> with <value>. The function fails if <key> is
00097   /// not in the map.
00098   int rebind (const ACE_Active_Map_Manager_Key &key,
00099               const T &value);
00100 
00101   /**
00102    * Reassociate <key> with <value>, storing the old value into the
00103    * "out" parameter <old_value>.  The function fails if <key> is not
00104    * in the map.
00105    */
00106   int rebind (const ACE_Active_Map_Manager_Key &key,
00107               const T &value,
00108               T &old_value);
00109 
00110   /**
00111    * Reassociate <key> with <value>, storing the old key and value
00112    * into the "out" parameter <old_key> and <old_value>.  The function
00113    * fails if <key> is not in the map.
00114    */
00115   int rebind (const ACE_Active_Map_Manager_Key &key,
00116               const T &value,
00117               ACE_Active_Map_Manager_Key &old_key,
00118               T &old_value);
00119 
00120   /// Locate <value> associated with <key>.
00121   int find (const ACE_Active_Map_Manager_Key &key,
00122             T &value) const;
00123 
00124   /// Is <key> in the map?
00125   int find (const ACE_Active_Map_Manager_Key &key) const;
00126 
00127   /**
00128    * Locate <value> associated with <key>.  The value is returned via
00129    * <internal_value> and hence a copy is saved.  Note that
00130    * <internal_value> is only a temporary pointer and will change when
00131    * the map resizes.  Therefore, the user should use the pointer
00132    * immediately and not hold on to it.
00133    */
00134   int find (const ACE_Active_Map_Manager_Key &key,
00135             T *&internal_value) const;
00136 
00137   // Creates a key.  User should place their <value> into
00138   // <*internal_value>.  This method is useful in reducing the number
00139   // of copies required in some cases.
00140 
00141   /// Remove <key> from the map.
00142   int unbind (const ACE_Active_Map_Manager_Key &key);
00143 
00144   /// Remove <key> from the map, and return the <value> associated with
00145   /// <key>.
00146   int unbind (const ACE_Active_Map_Manager_Key &key,
00147               T &value);
00148 
00149   /**
00150    * Locate <value> associated with <key>.  The value is returned via
00151    * <internal_value> and hence a copy is saved.  Note that
00152    * <internal_value> is only a temporary pointer and will change when
00153    * the map resizes or when this slot is reused.  Therefore, the user
00154    * should use the pointer immediately and not hold on to it.
00155    */
00156   int unbind (const ACE_Active_Map_Manager_Key &key,
00157               T *&internal_value);
00158 
00159   /// Return the current size of the map.
00160   size_t current_size (void) const;
00161 
00162   /// Return the total size of the map.
00163   size_t total_size (void) const;
00164 
00165   /// Returns a key that cannot be found in the map.
00166   static const ACE_Active_Map_Manager_Key npos (void);
00167 
00168   /// Dump the state of an object.
00169   void dump (void) const;
00170 
00171   // = STL styled iterator factory functions.
00172 
00173   /// Return forward iterator.
00174   ACE_Map_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> begin (void);
00175   ACE_Map_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> end (void);
00176 
00177   /// Return reverse iterator.
00178   ACE_Map_Reverse_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> rbegin (void);
00179   ACE_Map_Reverse_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> rend (void);
00180 
00181   /// Declare the dynamic allocation hooks.
00182   ACE_ALLOC_HOOK_DECLARE;
00183 
00184 protected:
00185 
00186   /// Private base class
00187   typedef ACE_Map_Manager<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> ACE_AMM_BASE;
00188 
00189 private:
00190 
00191   // = Disallow these operations.
00192   ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Active_Map_Manager<T> &))
00193   ACE_UNIMPLEMENTED_FUNC (ACE_Active_Map_Manager (const ACE_Active_Map_Manager<T> &))
00194 };
00195 
00196 ACE_END_VERSIONED_NAMESPACE_DECL
00197 
00198 #if defined (__ACE_INLINE__)
00199 #include "ace/Active_Map_Manager_T.inl"
00200 #endif /* __ACE_INLINE__ */
00201 
00202 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00203 #include "ace/Active_Map_Manager_T.cpp"
00204 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00205 
00206 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00207 #pragma implementation ("Active_Map_Manager_T.cpp")
00208 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00209 
00210 #include /**/ "ace/post.h"
00211 #endif /* ACE_ACTIVE_MAP_MANAGER_T_H */

Generated on Thu Nov 9 09:41:45 2006 for ACE by doxygen 1.3.6