1 // $Id: Cache_Map_Manager_T.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #ifndef ACE_CACHE_MAP_MANAGER_T_CPP
4 #define ACE_CACHE_MAP_MANAGER_T_CPP
6 #include "ace/Cache_Map_Manager_T.h"
8 #if !defined (ACE_LACKS_PRAGMA_ONCE)
10 #endif /* ACE_LACKS_PRAGMA_ONCE */
12 #include "ace/Log_Msg.h"
13 #include "ace/Malloc_Base.h"
15 #if !defined (__ACE_INLINE__)
16 #include "ace/Cache_Map_Manager_T.inl"
17 #endif /* __ACE_INLINE__ */
19 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
21 ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Manager
)
23 ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Iterator
)
25 ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Reverse_Iterator
)
27 #define ACE_T1 class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES
28 #define ACE_T2 KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES
31 ACE_Cache_Map_Manager
<ACE_T2
>::ACE_Cache_Map_Manager (CACHING_STRATEGY
&caching_s
,
34 : caching_strategy_ (caching_s
)
36 if (this->open (size
, alloc
) == -1)
39 ACE_TEXT ("ACE_Cache_Map_Manager::ACE_Cache_Map_Manager")));
44 ACE_Cache_Map_Manager
<ACE_T2
>::~ACE_Cache_Map_Manager (void)
50 ACE_Cache_Map_Manager
<ACE_T2
>::open (size_t length
,
53 return this->map_
.open (length
,
58 ACE_Cache_Map_Manager
<ACE_T2
>::close (void)
60 return this->map_
.close ();
64 ACE_Cache_Map_Manager
<ACE_T2
>::bind (const KEY
&key
,
67 // Insert an entry which has the <key> and the <cache_value> which
68 // is the combination of the <value> and the attributes of the
70 CACHE_VALUE
cache_value (value
,
71 this->caching_strategy_
.attributes ());
73 int bind_result
= this->map_
.bind (key
,
76 if (bind_result
!= -1)
79 int result
= this->caching_strategy_
.notify_bind (bind_result
,
80 cache_value
.second ());
85 this->map_
.unbind (key
);
87 // Unless the notification goes thru the bind operation is
100 ACE_Cache_Map_Manager
<ACE_T2
>::rebind (const KEY
&key
,
103 CACHE_VALUE
cache_value (value
,
104 this->caching_strategy_
.attributes ());
106 int rebind_result
= this->map_
.rebind (key
,
109 if (rebind_result
!= -1)
112 int result
= this->caching_strategy_
.notify_rebind (rebind_result
,
113 cache_value
.second ());
118 // Make sure the unbind operation is done only when the
119 // notification fails after a bind which is denoted by
121 if (rebind_result
== 0)
122 this->map_
.unbind (key
);
124 // Unless the notification goes thru the rebind operation is
132 return rebind_result
;
136 template <ACE_T1
> int
137 ACE_Cache_Map_Manager
<ACE_T2
>::rebind (const KEY
&key
,
141 CACHE_VALUE
cache_value (value
,
142 this->caching_strategy_
.attributes ());
144 CACHE_VALUE
old_cache_value (old_value
,
145 this->caching_strategy_
.attributes ());
147 int rebind_result
= this->map_
.rebind (key
,
151 if (rebind_result
!= -1)
154 int result
= this->caching_strategy_
.notify_rebind (rebind_result
,
155 cache_value
.second ());
160 // Make sure the unbind operation is done only when the
161 // notification fails after a bind which is denoted by
163 if (rebind_result
== 0)
164 this->map_
.unbind (key
);
166 // Unless the notification goes thru the rebind operation is
174 old_value
= old_cache_value
.first ();
180 return rebind_result
;
183 template <ACE_T1
> int
184 ACE_Cache_Map_Manager
<ACE_T2
>::rebind (const KEY
&key
,
189 CACHE_VALUE
cache_value (value
,
190 this->caching_strategy_
.attributes ());
192 CACHE_VALUE
old_cache_value (old_value
,
193 this->caching_strategy_
.attributes ());
195 int rebind_result
= this->map_
.rebind (key
,
200 if (rebind_result
!= -1)
203 int result
= this->caching_strategy_
.notify_rebind (rebind_result
,
204 cache_value
.second ());
209 // Make sure the unbind operation is done only when the
210 // notification fails after a bind which is denoted by
212 if (rebind_result
== 0)
213 this->map_
.unbind (key
);
215 // Unless the notification goes thru the rebind operation is
223 old_value
= old_cache_value
.first ();
229 return rebind_result
;
232 template <ACE_T1
> int
233 ACE_Cache_Map_Manager
<ACE_T2
>::trybind (const KEY
&key
,
236 CACHE_VALUE
cache_value (value
,
237 this->caching_strategy_
.attributes ());
239 int trybind_result
= this->map_
.trybind (key
,
242 if (trybind_result
!= -1)
245 int result
= this->caching_strategy_
.notify_trybind (trybind_result
,
246 cache_value
.second ());
251 // If the entry has got inserted into the map, it is removed
253 if (trybind_result
== 0)
254 this->map_
.unbind (key
);
262 // If an attempt is made to bind an existing entry the value
263 // is overwritten with the value from the map.
264 if (trybind_result
== 1)
265 value
= cache_value
.first ();
271 return trybind_result
;
274 template <ACE_T1
> int
275 ACE_Cache_Map_Manager
<ACE_T2
>::find (const KEY
&key
,
278 // Lookup the key and populate the <value>.
279 CACHE_VALUE cache_value
;
281 int find_result
= this->map_
.find (key
,
284 if (find_result
!= -1)
287 int result
= this->caching_strategy_
.notify_find (find_result
,
288 cache_value
.second ());
290 // Unless the find and notification operations go thru, this
291 // method is not successful.
297 // Since the <cache_value> has now changed after the
298 // notification, we need to bind to the map again.
299 int rebind_result
= this->map_
.rebind (key
,
301 if (rebind_result
== -1)
304 value
= cache_value
.first ();
313 template <ACE_T1
> int
314 ACE_Cache_Map_Manager
<ACE_T2
>::find (const KEY
&key
)
316 // Lookup the key and populate the <value>.
317 CACHE_VALUE cache_value
;
319 int find_result
= this->map_
.find (key
,
322 if (find_result
!= -1)
325 int result
= this->caching_strategy_
.notify_find (find_result
,
326 cache_value
.second ());
328 // Unless the find and notification operations go thru, this
329 // method is not successful.
335 // Since the <cache_value> has now changed after the
336 // notification, we need to bind to the map again.
337 int rebind_result
= this->map_
.rebind (key
,
340 if (rebind_result
== -1)
351 template <ACE_T1
> int
352 ACE_Cache_Map_Manager
<ACE_T2
>::unbind (const KEY
&key
)
354 // Remove the entry from the cache.
355 CACHE_VALUE cache_value
;
357 int unbind_result
= this->map_
.unbind (key
,
360 if (unbind_result
!= -1)
363 int result
= this->caching_strategy_
.notify_unbind (unbind_result
,
364 cache_value
.second ());
371 return unbind_result
;
374 template <ACE_T1
> int
375 ACE_Cache_Map_Manager
<ACE_T2
>::unbind (const KEY
&key
,
378 // Remove the entry from the cache.
379 CACHE_VALUE cache_value
;
381 int unbind_result
= this->map_
.unbind (key
,
384 if (unbind_result
!= -1)
387 int result
= this->caching_strategy_
.notify_unbind (unbind_result
,
388 cache_value
.second ());
393 value
= cache_value
.first ();
397 return unbind_result
;
400 template <ACE_T1
> void
401 ACE_Cache_Map_Manager
<ACE_T2
>::dump (void) const
403 #if defined (ACE_HAS_DUMP)
406 this->caching_strategy_
.dump ();
407 #endif /* ACE_HAS_DUMP */
413 template <class KEY
, class VALUE
, class IMPLEMENTATION
, class CACHING_STRATEGY
, class ATTRIBUTES
>
414 ACE_Cache_Map_Iterator
<KEY
, VALUE
, IMPLEMENTATION
, CACHING_STRATEGY
, ATTRIBUTES
>::~ACE_Cache_Map_Iterator (void)
418 ACE_END_VERSIONED_NAMESPACE_DECL
420 #endif /* ACE_CACHE_MAP_MANAGER_T_CPP */