1 // $Id: Hash_Cache_Map_Manager_T.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #ifndef ACE_HASH_CACHE_MAP_MANAGER_T_CPP
4 #define ACE_HASH_CACHE_MAP_MANAGER_T_CPP
6 #include "ace/Hash_Cache_Map_Manager_T.h"
8 #if !defined (ACE_LACKS_PRAGMA_ONCE)
10 #endif /* ACE_LACKS_PRAGMA_ONCE */
12 #if !defined (__ACE_INLINE__)
13 #include "ace/Hash_Cache_Map_Manager_T.inl"
14 #endif /* __ACE_INLINE__ */
16 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
18 ACE_ALLOC_HOOK_DEFINE(ACE_Hash_Cache_Map_Manager
)
20 #define ACE_T1 class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES
21 #define ACE_T2 KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES
24 ACE_Hash_Cache_Map_Manager
<ACE_T2
>::ACE_Hash_Cache_Map_Manager (CACHING_STRATEGY
&caching_s
,
27 : ACE_HCMM_BASE (caching_s
,
34 ACE_Hash_Cache_Map_Manager
<ACE_T2
>::~ACE_Hash_Cache_Map_Manager (void)
39 ACE_Hash_Cache_Map_Manager
<ACE_T2
>::bind (const KEY
&key
,
43 // Insert a entry which has the <key> and the <cache_value> which is
44 // the combination of the <value> and the attributes of the caching
46 CACHE_VALUE
cache_value (value
,
47 this->caching_strategy_
.attributes ());
49 int bind_result
= this->map_
.bind (key
,
53 if (bind_result
!= -1)
56 int result
= this->caching_strategy_
.notify_bind (bind_result
,
57 cache_value
.second ());
62 this->map_
.unbind (key
);
64 // Unless the notification goes thru the bind operation is
75 ACE_Hash_Cache_Map_Manager
<ACE_T2
>::rebind (const KEY
&key
,
79 CACHE_VALUE
cache_value (value
,
80 this->caching_strategy_
.attributes ());
82 int rebind_result
= this->map_
.rebind (key
,
86 if (rebind_result
!= -1)
89 int result
= this->caching_strategy_
.notify_rebind (rebind_result
,
90 cache_value
.second ());
95 // Make sure the unbind operation is done only when the
96 // notification fails after a bind which is denoted by
98 if (rebind_result
== 0)
99 this->map_
.unbind (key
);
101 // Unless the notification goes thru the rebind operation is
109 return rebind_result
;
112 template <ACE_T1
> int
113 ACE_Hash_Cache_Map_Manager
<ACE_T2
>::trybind (const KEY
&key
,
117 CACHE_VALUE
cache_value (value
,
118 this->caching_strategy_
.attributes ());
120 int trybind_result
= this->map_
.trybind (key
,
124 if (trybind_result
!= -1)
126 int result
= this->caching_strategy_
.notify_trybind (trybind_result
,
127 cache_value
.second ());
132 // If the entry has got inserted into the map, it is removed
134 if (trybind_result
== 0)
135 this->map_
.unbind (key
);
143 // If an attempt is made to bind an existing entry the value
144 // is overwritten with the value from the map.
145 if (trybind_result
== 1)
146 value
= cache_value
.first ();
152 return trybind_result
;
155 template <ACE_T1
> int
156 ACE_Hash_Cache_Map_Manager
<ACE_T2
>::find (const KEY
&key
,
159 // Lookup the key and populate the <value>.
160 int find_result
= this->map_
.find (key
,
163 if (find_result
!= -1)
166 int result
= this->caching_strategy_
.notify_find (find_result
,
167 entry
->int_id_
.second ());
169 // Unless the find and notification operations go thru, this
170 // method is not successful.
181 template <ACE_T1
> int
182 ACE_Hash_Cache_Map_Manager
<ACE_T2
>::find (const KEY
&key
,
185 CACHE_ENTRY
*entry
= 0;
187 int result
= this->find (key
,
192 value
= entry
->int_id_
.first ();
198 template <ACE_T1
> int
199 ACE_Hash_Cache_Map_Manager
<ACE_T2
>::find (const KEY
&key
)
201 CACHE_ENTRY
*entry
= 0;
203 return this->find (key
,
207 template <ACE_T1
> int
208 ACE_Hash_Cache_Map_Manager
<ACE_T2
>::unbind (CACHE_ENTRY
*entry
)
210 // Remove the entry from the cache.
211 int unbind_result
= this->map_
.unbind (entry
);
213 if (unbind_result
!= -1)
216 int result
= this->caching_strategy_
.notify_unbind (unbind_result
,
217 entry
->int_id_
.second ());
224 return unbind_result
;
227 ACE_END_VERSIONED_NAMESPACE_DECL
232 #endif /* ACE_HASH_CACHE_MAP_MANAGER_T_CPP */