Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / ace / Cache_Map_Manager_T.cpp
blob229b982ac961334e184c3b460674cf9a7763cc06
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)
7 #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,
25 size_t size,
26 ACE_Allocator *alloc)
27 : caching_strategy_ (caching_s)
29 if (this->open (size, alloc) == -1)
30 ACELIB_ERROR ((LM_ERROR,
31 ACE_TEXT ("%p\n"),
32 ACE_TEXT ("ACE_Cache_Map_Manager::ACE_Cache_Map_Manager")));
35 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES>
36 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::~ACE_Cache_Map_Manager ()
38 this->close ();
41 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> int
42 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::open (size_t length,
43 ACE_Allocator *alloc)
45 return this->map_.open (length,
46 alloc);
49 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> int
50 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::close ()
52 return this->map_.close ();
55 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> int
56 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::bind (const KEY &key,
57 const VALUE &value)
59 // Insert an entry which has the <key> and the <cache_value> which
60 // is the combination of the <value> and the attributes of the
61 // caching strategy.
62 CACHE_VALUE cache_value (value,
63 this->caching_strategy_.attributes ());
65 int bind_result = this->map_.bind (key,
66 cache_value);
68 if (bind_result != -1)
70 int result = this->caching_strategy_.notify_bind (bind_result,
71 cache_value.second);
73 if (result == -1)
75 this->map_.unbind (key);
77 // Unless the notification goes thru the bind operation is
78 // not complete.
79 bind_result = -1;
84 return bind_result;
88 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> int
89 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::rebind (const KEY &key,
90 const VALUE &value)
92 CACHE_VALUE cache_value (value,
93 this->caching_strategy_.attributes ());
95 int rebind_result = this->map_.rebind (key,
96 cache_value);
98 if (rebind_result != -1)
100 int result = this->caching_strategy_.notify_rebind (rebind_result,
101 cache_value.second ());
103 if (result == -1)
105 // Make sure the unbind operation is done only when the
106 // notification fails after a bind which is denoted by
107 // rebind_result = 0
108 if (rebind_result == 0)
109 this->map_.unbind (key);
111 // Unless the notification goes thru the rebind operation is
112 // not complete.
113 rebind_result = -1;
118 return rebind_result;
122 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> int
123 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::rebind (const KEY &key,
124 const VALUE &value,
125 VALUE &old_value)
127 CACHE_VALUE cache_value (value,
128 this->caching_strategy_.attributes ());
130 CACHE_VALUE old_cache_value (old_value,
131 this->caching_strategy_.attributes ());
133 int rebind_result = this->map_.rebind (key,
134 cache_value,
135 old_cache_value);
137 if (rebind_result != -1)
139 int result = this->caching_strategy_.notify_rebind (rebind_result,
140 cache_value.second ());
142 if (result == -1)
144 // Make sure the unbind operation is done only when the
145 // notification fails after a bind which is denoted by
146 // rebind_result = 0
147 if (rebind_result == 0)
148 this->map_.unbind (key);
150 // Unless the notification goes thru the rebind operation is
151 // not complete.
152 rebind_result = -1;
154 else
156 old_value = old_cache_value.first ();
161 return rebind_result;
164 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> int
165 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::rebind (const KEY &key,
166 const VALUE &value,
167 KEY &old_key,
168 VALUE &old_value)
170 CACHE_VALUE cache_value (value,
171 this->caching_strategy_.attributes ());
173 CACHE_VALUE old_cache_value (old_value,
174 this->caching_strategy_.attributes ());
176 int rebind_result = this->map_.rebind (key,
177 cache_value,
178 old_key,
179 old_cache_value);
181 if (rebind_result != -1)
183 int result = this->caching_strategy_.notify_rebind (rebind_result,
184 cache_value.second ());
186 if (result == -1)
188 // Make sure the unbind operation is done only when the
189 // notification fails after a bind which is denoted by
190 // rebind_result = 0
191 if (rebind_result == 0)
192 this->map_.unbind (key);
194 // Unless the notification goes thru the rebind operation is
195 // not complete.
196 rebind_result = -1;
198 else
200 old_value = old_cache_value.first ();
205 return rebind_result;
208 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> int
209 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::trybind (const KEY &key,
210 VALUE &value)
212 CACHE_VALUE cache_value (value,
213 this->caching_strategy_.attributes ());
215 int trybind_result = this->map_.trybind (key,
216 cache_value);
218 if (trybind_result != -1)
220 int result = this->caching_strategy_.notify_trybind (trybind_result,
221 cache_value.second ());
223 if (result == -1)
225 // If the entry has got inserted into the map, it is removed
226 // due to failure.
227 if (trybind_result == 0)
228 this->map_.unbind (key);
230 trybind_result = -1;
232 else
234 // If an attempt is made to bind an existing entry the value
235 // is overwritten with the value from the map.
236 if (trybind_result == 1)
237 value = cache_value.first ();
242 return trybind_result;
245 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> int
246 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::find (const KEY &key,
247 VALUE &value)
249 // Lookup the key and populate the <value>.
250 CACHE_VALUE cache_value;
252 int find_result = this->map_.find (key,
253 cache_value);
255 if (find_result != -1)
257 int result = this->caching_strategy_.notify_find (find_result,
258 cache_value.second);
260 // Unless the find and notification operations go thru, this
261 // method is not successful.
262 if (result == -1)
263 find_result = -1;
264 else
266 // Since the <cache_value> has now changed after the
267 // notification, we need to bind to the map again.
268 int rebind_result = this->map_.rebind (key,
269 cache_value);
270 if (rebind_result == -1)
271 find_result = -1;
272 else
273 value = cache_value.first;
278 return find_result;
281 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> int
282 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::find (const KEY &key)
284 // Lookup the key and populate the <value>.
285 CACHE_VALUE cache_value;
287 int find_result = this->map_.find (key,
288 cache_value);
290 if (find_result != -1)
292 int result = this->caching_strategy_.notify_find (find_result,
293 cache_value.second);
295 // Unless the find and notification operations go thru, this
296 // method is not successful.
297 if (result == -1)
298 find_result = -1;
299 else
301 // Since the <cache_value> has now changed after the
302 // notification, we need to bind to the map again.
303 int rebind_result = this->map_.rebind (key,
304 cache_value);
306 if (rebind_result == -1)
307 find_result = -1;
312 return find_result;
316 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> int
317 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::unbind (const KEY &key)
319 // Remove the entry from the cache.
320 CACHE_VALUE cache_value;
322 int unbind_result = this->map_.unbind (key,
323 cache_value);
325 if (unbind_result != -1)
327 int result = this->caching_strategy_.notify_unbind (unbind_result,
328 cache_value.second);
330 if (result == -1)
331 unbind_result = -1;
334 return unbind_result;
337 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> int
338 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::unbind (const KEY &key,
339 VALUE &value)
341 // Remove the entry from the cache.
342 CACHE_VALUE cache_value;
344 int unbind_result = this->map_.unbind (key,
345 cache_value);
347 if (unbind_result != -1)
349 int result = this->caching_strategy_.notify_unbind (unbind_result,
350 cache_value.second ());
352 if (result == -1)
353 unbind_result = -1;
354 else
355 value = cache_value.first ();
358 return unbind_result;
361 template <class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES> void
362 ACE_Cache_Map_Manager<KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES>::dump () const
364 #if defined (ACE_HAS_DUMP)
365 this->map_.dump ();
367 this->caching_strategy_.dump ();
368 #endif /* ACE_HAS_DUMP */
371 ACE_END_VERSIONED_NAMESPACE_DECL
373 #endif /* ACE_CACHE_MAP_MANAGER_T_CPP */