3 //=============================================================================
5 * @file Active_Map_Manager_T.h
7 * $Id: Active_Map_Manager_T.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Irfan Pyarali
11 //=============================================================================
14 #ifndef ACE_ACTIVE_MAP_MANAGER_T_H
15 #define ACE_ACTIVE_MAP_MANAGER_T_H
16 #include /**/ "ace/pre.h"
18 #include "ace/Map_Manager.h"
19 #include "ace/Active_Map_Manager.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #include "ace/Null_Mutex.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 * @class ACE_Active_Map_Manager
32 * @brief Define a map abstraction that associates system generated
33 * keys with user specified values.
35 * Since the key is system generated, searches are very fast and
36 * take a constant amount of time.
39 class ACE_Active_Map_Manager
: public ACE_Map_Manager
<ACE_Active_Map_Manager_Key
, T
, ACE_Null_Mutex
>
44 typedef ACE_Active_Map_Manager_Key key_type
;
45 typedef T mapped_type
;
47 typedef ACE_Map_Entry
<ACE_Active_Map_Manager_Key
, T
> ENTRY
;
48 typedef ACE_Map_Iterator
<ACE_Active_Map_Manager_Key
, T
, ACE_Null_Mutex
> ITERATOR
;
49 typedef ACE_Map_Reverse_Iterator
<ACE_Active_Map_Manager_Key
, T
, ACE_Null_Mutex
> REVERSE_ITERATOR
;
52 typedef ITERATOR iterator
;
53 typedef REVERSE_ITERATOR reverse_iterator
;
55 // = Initialization and termination methods.
56 /// Initialize a <Active_Map_Manager> with the ACE_DEFAULT_MAP_SIZE.
57 ACE_Active_Map_Manager (ACE_Allocator
*alloc
= 0);
59 /// Initialize a <Active_Map_Manager> with @a size entries.
60 ACE_Active_Map_Manager (size_t size
,
61 ACE_Allocator
*alloc
= 0);
63 /// Close down a <Active_Map_Manager> and release dynamically
64 /// allocated resources.
65 ~ACE_Active_Map_Manager (void);
67 /// Initialize a <Active_Map_Manager> with size @a length.
68 int open (size_t length
= ACE_DEFAULT_MAP_SIZE
,
69 ACE_Allocator
*alloc
= 0);
71 /// Close down a <Active_Map_Manager> and release dynamically
72 /// allocated resources.
75 /// Add @a value to the map, and the corresponding key produced by the
76 /// Active_Map_Manager is returned through @a key.
77 int bind (const T
&value
,
78 ACE_Active_Map_Manager_Key
&key
);
80 /// Add @a value to the map. The user does not care about the
81 /// corresponding key produced by the Active_Map_Manager.
82 int bind (const T
&value
);
85 * Reserves a slot in the internal structure and returns the key and
86 * a pointer to the value. User should place their @a value into
87 * <*internal_value>. This method is useful in reducing the number
88 * of copies required in some cases. Note that <internal_value> is
89 * only a temporary pointer and will change when the map resizes.
90 * Therefore, the user should use the pointer immediately and not
93 int bind (ACE_Active_Map_Manager_Key
&key
,
96 /// Reassociate @a key with @a value. The function fails if @a key is
98 int rebind (const ACE_Active_Map_Manager_Key
&key
,
102 * Reassociate @a key with @a value, storing the old value into the
103 * "out" parameter @a old_value. The function fails if @a key is not
106 int rebind (const ACE_Active_Map_Manager_Key
&key
,
111 * Reassociate @a key with @a value, storing the old key and value
112 * into the "out" parameter @a old_key and @a old_value. The function
113 * fails if @a key is not in the map.
115 int rebind (const ACE_Active_Map_Manager_Key
&key
,
117 ACE_Active_Map_Manager_Key
&old_key
,
120 /// Locate @a value associated with @a key.
121 int find (const ACE_Active_Map_Manager_Key
&key
,
124 /// Is @a key in the map?
125 int find (const ACE_Active_Map_Manager_Key
&key
) const;
128 * Locate @a value associated with @a key. The value is returned via
129 * <internal_value> and hence a copy is saved. Note that
130 * <internal_value> is only a temporary pointer and will change when
131 * the map resizes. Therefore, the user should use the pointer
132 * immediately and not hold on to it.
134 int find (const ACE_Active_Map_Manager_Key
&key
,
135 T
*&internal_value
) const;
137 // Creates a key. User should place their @a value into
138 // <*internal_value>. This method is useful in reducing the number
139 // of copies required in some cases.
141 /// Remove @a key from the map.
142 int unbind (const ACE_Active_Map_Manager_Key
&key
);
144 /// Remove @a key from the map, and return the @a value associated with
146 int unbind (const ACE_Active_Map_Manager_Key
&key
,
150 * Locate @a value associated with @a key. The value is returned via
151 * <internal_value> and hence a copy is saved. Note that
152 * <internal_value> is only a temporary pointer and will change when
153 * the map resizes or when this slot is reused. Therefore, the user
154 * should use the pointer immediately and not hold on to it.
156 int unbind (const ACE_Active_Map_Manager_Key
&key
,
159 /// Return the current size of the map.
160 size_t current_size (void) const;
162 /// Return the total size of the map.
163 size_t total_size (void) const;
165 /// Returns a key that cannot be found in the map.
166 static const ACE_Active_Map_Manager_Key
npos (void);
168 /// Dump the state of an object.
169 void dump (void) const;
171 // = STL styled iterator factory functions.
173 /// Return forward iterator.
174 ACE_Map_Iterator
<ACE_Active_Map_Manager_Key
, T
, ACE_Null_Mutex
> begin (void);
175 ACE_Map_Iterator
<ACE_Active_Map_Manager_Key
, T
, ACE_Null_Mutex
> end (void);
177 /// Return reverse iterator.
178 ACE_Map_Reverse_Iterator
<ACE_Active_Map_Manager_Key
, T
, ACE_Null_Mutex
> rbegin (void);
179 ACE_Map_Reverse_Iterator
<ACE_Active_Map_Manager_Key
, T
, ACE_Null_Mutex
> rend (void);
181 /// Declare the dynamic allocation hooks.
182 ACE_ALLOC_HOOK_DECLARE
;
186 /// Private base class
187 typedef ACE_Map_Manager
<ACE_Active_Map_Manager_Key
, T
, ACE_Null_Mutex
> ACE_AMM_BASE
;
191 // = Disallow these operations.
192 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Active_Map_Manager
<T
> &))
193 ACE_UNIMPLEMENTED_FUNC (ACE_Active_Map_Manager (const ACE_Active_Map_Manager
<T
> &))
196 ACE_END_VERSIONED_NAMESPACE_DECL
198 #if defined (__ACE_INLINE__)
199 #include "ace/Active_Map_Manager_T.inl"
200 #endif /* __ACE_INLINE__ */
202 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
203 #include "ace/Active_Map_Manager_T.cpp"
204 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
206 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
207 #pragma implementation ("Active_Map_Manager_T.cpp")
208 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
210 #include /**/ "ace/post.h"
211 #endif /* ACE_ACTIVE_MAP_MANAGER_T_H */