1 #ifndef ACE_CACHE_MAP_MANAGER_T_CPP
2 #define ACE_CACHE_MAP_MANAGER_T_CPP
4 #include "ace/Cache_Map_Manager_T.h"
6 #if !defined (ACE_LACKS_PRAGMA_ONCE)
8 #endif /* ACE_LACKS_PRAGMA_ONCE */
10 #include "ace/Log_Category.h"
11 #include "ace/Malloc_Base.h"
13 #if !defined (__ACE_INLINE__)
14 #include "ace/Cache_Map_Manager_T.inl"
15 #endif /* __ACE_INLINE__ */
17 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
19 ACE_ALLOC_HOOK_DEFINE_Tc7(ACE_Cache_Map_Manager
)
20 ACE_ALLOC_HOOK_DEFINE_Tc5(ACE_Cache_Map_Iterator
)
21 ACE_ALLOC_HOOK_DEFINE_Tc5(ACE_Cache_Map_Reverse_Iterator
)
23 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
>
24 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::ACE_Cache_Map_Manager (CACHING_STRATEGY
&caching_s
,
27 : caching_strategy_ (caching_s
)
29 if (this->open (size
, alloc
) == -1)
30 ACELIB_ERROR ((LM_ERROR
,
32 ACE_TEXT ("ACE_Cache_Map_Manager::ACE_Cache_Map_Manager")));
35 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
>
36 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::~ACE_Cache_Map_Manager ()
41 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
42 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::open (size_t length
,
45 return this->map_
.open (length
,
49 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
50 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::close ()
52 return this->map_
.close ();
55 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
56 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::bind (const KEY
&key
,
59 // Insert an entry which has the <key> and the <cache_value> which
60 // is the combination of the <value> and the attributes of the
62 CACHE_VALUE
cache_value (value
,
63 this->caching_strategy_
.attributes ());
65 int bind_result
= this->map_
.bind (key
,
68 if (bind_result
!= -1)
70 int result
= this->caching_strategy_
.notify_bind (bind_result
,
75 this->map_
.unbind (key
);
77 // Unless the notification goes thru the bind operation is
88 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
89 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::rebind (const KEY
&key
,
92 CACHE_VALUE
cache_value (value
,
93 this->caching_strategy_
.attributes ());
95 int rebind_result
= this->map_
.rebind (key
,
98 if (rebind_result
!= -1)
100 int result
= this->caching_strategy_
.notify_rebind (rebind_result
,
101 cache_value
.second ());
105 // Make sure the unbind operation is done only when the
106 // notification fails after a bind which is denoted by
108 if (rebind_result
== 0)
109 this->map_
.unbind (key
);
111 // Unless the notification goes thru the rebind operation is
118 return rebind_result
;
122 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
123 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::rebind (const KEY
&key
,
127 CACHE_VALUE
cache_value (value
,
128 this->caching_strategy_
.attributes ());
130 CACHE_VALUE
old_cache_value (old_value
,
131 this->caching_strategy_
.attributes ());
133 int rebind_result
= this->map_
.rebind (key
,
137 if (rebind_result
!= -1)
139 int result
= this->caching_strategy_
.notify_rebind (rebind_result
,
140 cache_value
.second ());
144 // Make sure the unbind operation is done only when the
145 // notification fails after a bind which is denoted by
147 if (rebind_result
== 0)
148 this->map_
.unbind (key
);
150 // Unless the notification goes thru the rebind operation is
156 old_value
= old_cache_value
.first ();
161 return rebind_result
;
164 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
165 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::rebind (const KEY
&key
,
170 CACHE_VALUE
cache_value (value
,
171 this->caching_strategy_
.attributes ());
173 CACHE_VALUE
old_cache_value (old_value
,
174 this->caching_strategy_
.attributes ());
176 int rebind_result
= this->map_
.rebind (key
,
181 if (rebind_result
!= -1)
183 int result
= this->caching_strategy_
.notify_rebind (rebind_result
,
184 cache_value
.second ());
188 // Make sure the unbind operation is done only when the
189 // notification fails after a bind which is denoted by
191 if (rebind_result
== 0)
192 this->map_
.unbind (key
);
194 // Unless the notification goes thru the rebind operation is
200 old_value
= old_cache_value
.first ();
205 return rebind_result
;
208 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
209 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::trybind (const KEY
&key
,
212 CACHE_VALUE
cache_value (value
,
213 this->caching_strategy_
.attributes ());
215 int trybind_result
= this->map_
.trybind (key
,
218 if (trybind_result
!= -1)
220 int result
= this->caching_strategy_
.notify_trybind (trybind_result
,
221 cache_value
.second ());
225 // If the entry has got inserted into the map, it is removed
227 if (trybind_result
== 0)
228 this->map_
.unbind (key
);
234 // If an attempt is made to bind an existing entry the value
235 // is overwritten with the value from the map.
236 if (trybind_result
== 1)
237 value
= cache_value
.first ();
242 return trybind_result
;
245 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
246 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::find (const KEY
&key
,
249 // Lookup the key and populate the <value>.
250 CACHE_VALUE cache_value
;
252 int find_result
= this->map_
.find (key
,
255 if (find_result
!= -1)
257 int result
= this->caching_strategy_
.notify_find (find_result
,
260 // Unless the find and notification operations go thru, this
261 // method is not successful.
266 // Since the <cache_value> has now changed after the
267 // notification, we need to bind to the map again.
268 int rebind_result
= this->map_
.rebind (key
,
270 if (rebind_result
== -1)
273 value
= cache_value
.first
;
281 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
282 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::find (const KEY
&key
)
284 // Lookup the key and populate the <value>.
285 CACHE_VALUE cache_value
;
287 int find_result
= this->map_
.find (key
,
290 if (find_result
!= -1)
292 int result
= this->caching_strategy_
.notify_find (find_result
,
295 // Unless the find and notification operations go thru, this
296 // method is not successful.
301 // Since the <cache_value> has now changed after the
302 // notification, we need to bind to the map again.
303 int rebind_result
= this->map_
.rebind (key
,
306 if (rebind_result
== -1)
316 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
317 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::unbind (const KEY
&key
)
319 // Remove the entry from the cache.
320 CACHE_VALUE cache_value
;
322 int unbind_result
= this->map_
.unbind (key
,
325 if (unbind_result
!= -1)
327 int result
= this->caching_strategy_
.notify_unbind (unbind_result
,
334 return unbind_result
;
337 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
338 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::unbind (const KEY
&key
,
341 // Remove the entry from the cache.
342 CACHE_VALUE cache_value
;
344 int unbind_result
= this->map_
.unbind (key
,
347 if (unbind_result
!= -1)
349 int result
= this->caching_strategy_
.notify_unbind (unbind_result
,
350 cache_value
.second ());
355 value
= cache_value
.first ();
358 return unbind_result
;
361 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> void
362 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::dump () const
364 #if defined (ACE_HAS_DUMP)
367 this->caching_strategy_
.dump ();
368 #endif /* ACE_HAS_DUMP */
371 ACE_END_VERSIONED_NAMESPACE_DECL
373 #endif /* ACE_CACHE_MAP_MANAGER_T_CPP */