GitHub Actions: Try MSVC builds with /std:c++17 and 20
[ACE_TAO.git] / ACE / ace / Cache_Map_Manager_T.cpp
blobb92876a7ffd6e2d1568e467b2780cdcf98649fc2
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")));
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)
39 this->close ();
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,
44 ACE_Allocator *alloc)
46 return this->map_.open (length,
47 alloc);
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,
58 const VALUE &value)
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
62 // caching strategy.
63 CACHE_VALUE cache_value (value,
64 this->caching_strategy_.attributes ());
66 int bind_result = this->map_.bind (key,
67 cache_value);
69 if (bind_result != -1)
72 int result = this->caching_strategy_.notify_bind (bind_result,
73 cache_value.second);
75 if (result == -1)
78 this->map_.unbind (key);
80 // Unless the notification goes thru the bind operation is
81 // not complete.
82 bind_result = -1;
88 return bind_result;
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,
94 const VALUE &value)
96 CACHE_VALUE cache_value (value,
97 this->caching_strategy_.attributes ());
99 int rebind_result = this->map_.rebind (key,
100 cache_value);
102 if (rebind_result != -1)
105 int result = this->caching_strategy_.notify_rebind (rebind_result,
106 cache_value.second ());
108 if (result == -1)
111 // Make sure the unbind operation is done only when the
112 // notification fails after a bind which is denoted by
113 // rebind_result = 0
114 if (rebind_result == 0)
115 this->map_.unbind (key);
117 // Unless the notification goes thru the rebind operation is
118 // not complete.
119 rebind_result = -1;
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,
131 const VALUE &value,
132 VALUE &old_value)
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,
141 cache_value,
142 old_cache_value);
144 if (rebind_result != -1)
147 int result = this->caching_strategy_.notify_rebind (rebind_result,
148 cache_value.second ());
150 if (result == -1)
153 // Make sure the unbind operation is done only when the
154 // notification fails after a bind which is denoted by
155 // rebind_result = 0
156 if (rebind_result == 0)
157 this->map_.unbind (key);
159 // Unless the notification goes thru the rebind operation is
160 // not complete.
161 rebind_result = -1;
164 else
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,
178 const VALUE &value,
179 KEY &old_key,
180 VALUE &old_value)
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,
189 cache_value,
190 old_key,
191 old_cache_value);
193 if (rebind_result != -1)
196 int result = this->caching_strategy_.notify_rebind (rebind_result,
197 cache_value.second ());
199 if (result == -1)
202 // Make sure the unbind operation is done only when the
203 // notification fails after a bind which is denoted by
204 // rebind_result = 0
205 if (rebind_result == 0)
206 this->map_.unbind (key);
208 // Unless the notification goes thru the rebind operation is
209 // not complete.
210 rebind_result = -1;
213 else
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,
227 VALUE &value)
229 CACHE_VALUE cache_value (value,
230 this->caching_strategy_.attributes ());
232 int trybind_result = this->map_.trybind (key,
233 cache_value);
235 if (trybind_result != -1)
238 int result = this->caching_strategy_.notify_trybind (trybind_result,
239 cache_value.second ());
241 if (result == -1)
244 // If the entry has got inserted into the map, it is removed
245 // due to failure.
246 if (trybind_result == 0)
247 this->map_.unbind (key);
249 trybind_result = -1;
252 else
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,
269 VALUE &value)
271 // Lookup the key and populate the <value>.
272 CACHE_VALUE cache_value;
274 int find_result = this->map_.find (key,
275 cache_value);
277 if (find_result != -1)
280 int result = this->caching_strategy_.notify_find (find_result,
281 cache_value.second);
283 // Unless the find and notification operations go thru, this
284 // method is not successful.
285 if (result == -1)
286 find_result = -1;
287 else
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,
293 cache_value);
294 if (rebind_result == -1)
295 find_result = -1;
296 else
297 value = cache_value.first;
303 return find_result;
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,
313 cache_value);
315 if (find_result != -1)
318 int result = this->caching_strategy_.notify_find (find_result,
319 cache_value.second);
321 // Unless the find and notification operations go thru, this
322 // method is not successful.
323 if (result == -1)
324 find_result = -1;
325 else
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,
331 cache_value);
333 if (rebind_result == -1)
334 find_result = -1;
340 return find_result;
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,
351 cache_value);
353 if (unbind_result != -1)
356 int result = this->caching_strategy_.notify_unbind (unbind_result,
357 cache_value.second);
359 if (result == -1)
360 unbind_result = -1;
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,
369 VALUE &value)
371 // Remove the entry from the cache.
372 CACHE_VALUE cache_value;
374 int unbind_result = this->map_.unbind (key,
375 cache_value);
377 if (unbind_result != -1)
380 int result = this->caching_strategy_.notify_unbind (unbind_result,
381 cache_value.second ());
383 if (result == -1)
384 unbind_result = -1;
385 else
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)
397 this->map_.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 */