Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Hash_Cache_Map_Manager_T.cpp
blob5eb4bcc825dab1ae270bbf58c04e2e85ae4bc391
1 #ifndef ACE_HASH_CACHE_MAP_MANAGER_T_CPP
2 #define ACE_HASH_CACHE_MAP_MANAGER_T_CPP
4 #include "ace/Hash_Cache_Map_Manager_T.h"
6 #if !defined (ACE_LACKS_PRAGMA_ONCE)
7 #pragma once
8 #endif /* ACE_LACKS_PRAGMA_ONCE */
10 #if !defined (__ACE_INLINE__)
11 #include "ace/Hash_Cache_Map_Manager_T.inl"
12 #endif /* __ACE_INLINE__ */
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_ALLOC_HOOK_DEFINE_Tc6(ACE_Hash_Cache_Map_Manager)
18 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES>
19 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::ACE_Hash_Cache_Map_Manager (CACHING_STRATEGY &caching_s,
20 size_t size,
21 ACE_Allocator *alloc)
22 : ACE_HCMM_BASE (caching_s,
23 size,
24 alloc)
28 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
29 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::bind (const KEY &key,
30 const VALUE &value,
31 CACHE_ENTRY *&entry)
33 // Insert a entry which has the <key> and the <cache_value> which is
34 // the combination of the <value> and the attributes of the caching
35 // strategy.
36 CACHE_VALUE cache_value (value,
37 this->caching_strategy_.attributes ());
39 int bind_result = this->map_.bind (key,
40 cache_value,
41 entry);
43 if (bind_result != -1)
45 int result = this->caching_strategy_.notify_bind (bind_result,
46 cache_value.second);
48 if (result == -1)
50 this->map_.unbind (key);
52 // Unless the notification goes thru the bind operation is
53 // not complete.
54 bind_result = -1;
58 return bind_result;
61 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
62 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::rebind (const KEY &key,
63 const VALUE &value,
64 CACHE_ENTRY *&entry)
66 CACHE_VALUE cache_value (value,
67 this->caching_strategy_.attributes ());
69 int rebind_result = this->map_.rebind (key,
70 cache_value,
71 entry);
73 if (rebind_result != -1)
75 int result = this->caching_strategy_.notify_rebind (rebind_result,
76 cache_value.second ());
78 if (result == -1)
80 // Make sure the unbind operation is done only when the
81 // notification fails after a bind which is denoted by
82 // rebind_result = 0
83 if (rebind_result == 0)
84 this->map_.unbind (key);
86 // Unless the notification goes thru the rebind operation is
87 // not complete.
88 rebind_result = -1;
93 return rebind_result;
96 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
97 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::trybind (const KEY &key,
98 VALUE &value,
99 CACHE_ENTRY *&entry)
101 CACHE_VALUE cache_value (value,
102 this->caching_strategy_.attributes ());
104 int trybind_result = this->map_.trybind (key,
105 cache_value,
106 entry);
108 if (trybind_result != -1)
110 int result = this->caching_strategy_.notify_trybind (trybind_result,
111 cache_value.second ());
113 if (result == -1)
115 // If the entry has got inserted into the map, it is removed
116 // due to failure.
117 if (trybind_result == 0)
118 this->map_.unbind (key);
120 trybind_result = -1;
122 else
124 // If an attempt is made to bind an existing entry the value
125 // is overwritten with the value from the map.
126 if (trybind_result == 1)
127 value = cache_value.first ();
132 return trybind_result;
135 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
136 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::find (const KEY &key,
137 CACHE_ENTRY *&entry)
139 // Lookup the key and populate the <value>.
140 int find_result = this->map_.find (key,
141 entry);
143 if (find_result != -1)
145 int result = this->caching_strategy_.notify_find (find_result,
146 entry->int_id_.second);
148 // Unless the find and notification operations go thru, this
149 // method is not successful.
150 if (result == -1)
151 find_result = -1;
152 else
153 find_result = 0;
156 return find_result;
159 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
160 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::find (const KEY &key,
161 VALUE &value)
163 CACHE_ENTRY *entry = 0;
165 int result = this->find (key,
166 entry);
168 if (result != -1)
170 value = entry->int_id_.first;
173 return result;
176 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
177 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::find (const KEY &key)
179 CACHE_ENTRY *entry = 0;
181 return this->find (key,
182 entry);
185 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
186 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::unbind (CACHE_ENTRY *entry)
188 // Remove the entry from the cache.
189 int unbind_result = this->map_.unbind (entry);
191 if (unbind_result != -1)
193 int result = this->caching_strategy_.notify_unbind (unbind_result,
194 entry->int_id_.second);
196 if (result == -1)
197 unbind_result = -1;
200 return unbind_result;
203 ACE_END_VERSIONED_NAMESPACE_DECL
205 #endif /* ACE_HASH_CACHE_MAP_MANAGER_T_CPP */