Fixed typos
[ACE_TAO.git] / ACE / ace / Hash_Cache_Map_Manager_T.cpp
blob54ab98c34882770619d7287726cbc0c6fc27a71e
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>
29 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::~ACE_Hash_Cache_Map_Manager (void)
33 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
34 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::bind (const KEY &key,
35 const VALUE &value,
36 CACHE_ENTRY *&entry)
38 // Insert a entry which has the <key> and the <cache_value> which is
39 // the combination of the <value> and the attributes of the caching
40 // strategy.
41 CACHE_VALUE cache_value (value,
42 this->caching_strategy_.attributes ());
44 int bind_result = this->map_.bind (key,
45 cache_value,
46 entry);
48 if (bind_result != -1)
51 int result = this->caching_strategy_.notify_bind (bind_result,
52 cache_value.second);
54 if (result == -1)
57 this->map_.unbind (key);
59 // Unless the notification goes thru the bind operation is
60 // not complete.
61 bind_result = -1;
66 return bind_result;
69 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
70 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::rebind (const KEY &key,
71 const VALUE &value,
72 CACHE_ENTRY *&entry)
74 CACHE_VALUE cache_value (value,
75 this->caching_strategy_.attributes ());
77 int rebind_result = this->map_.rebind (key,
78 cache_value,
79 entry);
81 if (rebind_result != -1)
84 int result = this->caching_strategy_.notify_rebind (rebind_result,
85 cache_value.second ());
87 if (result == -1)
90 // Make sure the unbind operation is done only when the
91 // notification fails after a bind which is denoted by
92 // rebind_result = 0
93 if (rebind_result == 0)
94 this->map_.unbind (key);
96 // Unless the notification goes thru the rebind operation is
97 // not complete.
98 rebind_result = -1;
104 return rebind_result;
107 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
108 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::trybind (const KEY &key,
109 VALUE &value,
110 CACHE_ENTRY *&entry)
112 CACHE_VALUE cache_value (value,
113 this->caching_strategy_.attributes ());
115 int trybind_result = this->map_.trybind (key,
116 cache_value,
117 entry);
119 if (trybind_result != -1)
121 int result = this->caching_strategy_.notify_trybind (trybind_result,
122 cache_value.second ());
124 if (result == -1)
127 // If the entry has got inserted into the map, it is removed
128 // due to failure.
129 if (trybind_result == 0)
130 this->map_.unbind (key);
132 trybind_result = -1;
135 else
138 // If an attempt is made to bind an existing entry the value
139 // is overwritten with the value from the map.
140 if (trybind_result == 1)
141 value = cache_value.first ();
147 return trybind_result;
150 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
151 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::find (const KEY &key,
152 CACHE_ENTRY *&entry)
154 // Lookup the key and populate the <value>.
155 int find_result = this->map_.find (key,
156 entry);
158 if (find_result != -1)
161 int result = this->caching_strategy_.notify_find (find_result,
162 entry->int_id_.second);
164 // Unless the find and notification operations go thru, this
165 // method is not successful.
166 if (result == -1)
167 find_result = -1;
168 else
169 find_result = 0;
173 return find_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,
178 VALUE &value)
180 CACHE_ENTRY *entry = 0;
182 int result = this->find (key,
183 entry);
185 if (result != -1)
187 value = entry->int_id_.first;
190 return result;
193 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
194 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::find (const KEY &key)
196 CACHE_ENTRY *entry = 0;
198 return this->find (key,
199 entry);
202 template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> int
203 ACE_Hash_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES>::unbind (CACHE_ENTRY *entry)
205 // Remove the entry from the cache.
206 int unbind_result = this->map_.unbind (entry);
208 if (unbind_result != -1)
211 int result = this->caching_strategy_.notify_unbind (unbind_result,
212 entry->int_id_.second);
214 if (result == -1)
215 unbind_result = -1;
219 return unbind_result;
222 ACE_END_VERSIONED_NAMESPACE_DECL
224 #endif /* ACE_HASH_CACHE_MAP_MANAGER_T_CPP */