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")));
36 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
>
37 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::~ACE_Cache_Map_Manager (void)
42 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
43 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::open (size_t length
,
46 return this->map_
.open (length
,
50 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
51 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::close (void)
53 return this->map_
.close ();
56 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
57 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::bind (const KEY
&key
,
60 // Insert an entry which has the <key> and the <cache_value> which
61 // is the combination of the <value> and the attributes of the
63 CACHE_VALUE
cache_value (value
,
64 this->caching_strategy_
.attributes ());
66 int bind_result
= this->map_
.bind (key
,
69 if (bind_result
!= -1)
72 int result
= this->caching_strategy_
.notify_bind (bind_result
,
78 this->map_
.unbind (key
);
80 // Unless the notification goes thru the bind operation is
92 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
93 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::rebind (const KEY
&key
,
96 CACHE_VALUE
cache_value (value
,
97 this->caching_strategy_
.attributes ());
99 int rebind_result
= this->map_
.rebind (key
,
102 if (rebind_result
!= -1)
105 int result
= this->caching_strategy_
.notify_rebind (rebind_result
,
106 cache_value
.second ());
111 // Make sure the unbind operation is done only when the
112 // notification fails after a bind which is denoted by
114 if (rebind_result
== 0)
115 this->map_
.unbind (key
);
117 // Unless the notification goes thru the rebind operation is
125 return rebind_result
;
129 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
130 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::rebind (const KEY
&key
,
134 CACHE_VALUE
cache_value (value
,
135 this->caching_strategy_
.attributes ());
137 CACHE_VALUE
old_cache_value (old_value
,
138 this->caching_strategy_
.attributes ());
140 int rebind_result
= this->map_
.rebind (key
,
144 if (rebind_result
!= -1)
147 int result
= this->caching_strategy_
.notify_rebind (rebind_result
,
148 cache_value
.second ());
153 // Make sure the unbind operation is done only when the
154 // notification fails after a bind which is denoted by
156 if (rebind_result
== 0)
157 this->map_
.unbind (key
);
159 // Unless the notification goes thru the rebind operation is
167 old_value
= old_cache_value
.first ();
173 return rebind_result
;
176 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
177 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::rebind (const KEY
&key
,
182 CACHE_VALUE
cache_value (value
,
183 this->caching_strategy_
.attributes ());
185 CACHE_VALUE
old_cache_value (old_value
,
186 this->caching_strategy_
.attributes ());
188 int rebind_result
= this->map_
.rebind (key
,
193 if (rebind_result
!= -1)
196 int result
= this->caching_strategy_
.notify_rebind (rebind_result
,
197 cache_value
.second ());
202 // Make sure the unbind operation is done only when the
203 // notification fails after a bind which is denoted by
205 if (rebind_result
== 0)
206 this->map_
.unbind (key
);
208 // Unless the notification goes thru the rebind operation is
216 old_value
= old_cache_value
.first ();
222 return rebind_result
;
225 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
226 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::trybind (const KEY
&key
,
229 CACHE_VALUE
cache_value (value
,
230 this->caching_strategy_
.attributes ());
232 int trybind_result
= this->map_
.trybind (key
,
235 if (trybind_result
!= -1)
238 int result
= this->caching_strategy_
.notify_trybind (trybind_result
,
239 cache_value
.second ());
244 // If the entry has got inserted into the map, it is removed
246 if (trybind_result
== 0)
247 this->map_
.unbind (key
);
255 // If an attempt is made to bind an existing entry the value
256 // is overwritten with the value from the map.
257 if (trybind_result
== 1)
258 value
= cache_value
.first ();
264 return trybind_result
;
267 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
268 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::find (const KEY
&key
,
271 // Lookup the key and populate the <value>.
272 CACHE_VALUE cache_value
;
274 int find_result
= this->map_
.find (key
,
277 if (find_result
!= -1)
280 int result
= this->caching_strategy_
.notify_find (find_result
,
283 // Unless the find and notification operations go thru, this
284 // method is not successful.
290 // Since the <cache_value> has now changed after the
291 // notification, we need to bind to the map again.
292 int rebind_result
= this->map_
.rebind (key
,
294 if (rebind_result
== -1)
297 value
= cache_value
.first
;
306 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
307 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::find (const KEY
&key
)
309 // Lookup the key and populate the <value>.
310 CACHE_VALUE cache_value
;
312 int find_result
= this->map_
.find (key
,
315 if (find_result
!= -1)
318 int result
= this->caching_strategy_
.notify_find (find_result
,
321 // Unless the find and notification operations go thru, this
322 // method is not successful.
328 // Since the <cache_value> has now changed after the
329 // notification, we need to bind to the map again.
330 int rebind_result
= this->map_
.rebind (key
,
333 if (rebind_result
== -1)
344 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
345 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::unbind (const KEY
&key
)
347 // Remove the entry from the cache.
348 CACHE_VALUE cache_value
;
350 int unbind_result
= this->map_
.unbind (key
,
353 if (unbind_result
!= -1)
356 int result
= this->caching_strategy_
.notify_unbind (unbind_result
,
364 return unbind_result
;
367 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> int
368 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::unbind (const KEY
&key
,
371 // Remove the entry from the cache.
372 CACHE_VALUE cache_value
;
374 int unbind_result
= this->map_
.unbind (key
,
377 if (unbind_result
!= -1)
380 int result
= this->caching_strategy_
.notify_unbind (unbind_result
,
381 cache_value
.second ());
386 value
= cache_value
.first ();
390 return unbind_result
;
393 template <class KEY
, class VALUE
, class CMAP_TYPE
, class ITERATOR_IMPL
, class REVERSE_ITERATOR_IMPL
, class CACHING_STRATEGY
, class ATTRIBUTES
> void
394 ACE_Cache_Map_Manager
<KEY
, VALUE
, CMAP_TYPE
, ITERATOR_IMPL
, REVERSE_ITERATOR_IMPL
, CACHING_STRATEGY
, ATTRIBUTES
>::dump (void) const
396 #if defined (ACE_HAS_DUMP)
399 this->caching_strategy_
.dump ();
400 #endif /* ACE_HAS_DUMP */
403 template <class KEY
, class VALUE
, class IMPLEMENTATION
, class CACHING_STRATEGY
, class ATTRIBUTES
>
404 ACE_Cache_Map_Iterator
<KEY
, VALUE
, IMPLEMENTATION
, CACHING_STRATEGY
, ATTRIBUTES
>::~ACE_Cache_Map_Iterator (void)
408 ACE_END_VERSIONED_NAMESPACE_DECL
410 #endif /* ACE_CACHE_MAP_MANAGER_T_CPP */