[6916] Fixed typos in spell checking code.
[getmangos.git] / dep / ACE_wrappers / ace / Cache_Map_Manager_T.cpp
blobf87031eb0d73dfd382128240772c1c785f4882db
1 // $Id: Cache_Map_Manager_T.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #ifndef ACE_CACHE_MAP_MANAGER_T_CPP
4 #define ACE_CACHE_MAP_MANAGER_T_CPP
6 #include "ace/Cache_Map_Manager_T.h"
8 #if !defined (ACE_LACKS_PRAGMA_ONCE)
9 #pragma once
10 #endif /* ACE_LACKS_PRAGMA_ONCE */
12 #include "ace/Log_Msg.h"
13 #include "ace/Malloc_Base.h"
15 #if !defined (__ACE_INLINE__)
16 #include "ace/Cache_Map_Manager_T.inl"
17 #endif /* __ACE_INLINE__ */
19 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
21 ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Manager)
23 ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Iterator)
25 ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Reverse_Iterator)
27 #define ACE_T1 class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES
28 #define ACE_T2 KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES
30 template <ACE_T1>
31 ACE_Cache_Map_Manager<ACE_T2>::ACE_Cache_Map_Manager (CACHING_STRATEGY &caching_s,
32 size_t size,
33 ACE_Allocator *alloc)
34 : caching_strategy_ (caching_s)
36 if (this->open (size, alloc) == -1)
37 ACE_ERROR ((LM_ERROR,
38 ACE_TEXT ("%p\n"),
39 ACE_TEXT ("ACE_Cache_Map_Manager::ACE_Cache_Map_Manager")));
43 template <ACE_T1>
44 ACE_Cache_Map_Manager<ACE_T2>::~ACE_Cache_Map_Manager (void)
46 this->close ();
49 template <ACE_T1> int
50 ACE_Cache_Map_Manager<ACE_T2>::open (size_t length,
51 ACE_Allocator *alloc)
53 return this->map_.open (length,
54 alloc);
57 template <ACE_T1> int
58 ACE_Cache_Map_Manager<ACE_T2>::close (void)
60 return this->map_.close ();
63 template <ACE_T1> int
64 ACE_Cache_Map_Manager<ACE_T2>::bind (const KEY &key,
65 const VALUE &value)
67 // Insert an entry which has the <key> and the <cache_value> which
68 // is the combination of the <value> and the attributes of the
69 // caching strategy.
70 CACHE_VALUE cache_value (value,
71 this->caching_strategy_.attributes ());
73 int bind_result = this->map_.bind (key,
74 cache_value);
76 if (bind_result != -1)
79 int result = this->caching_strategy_.notify_bind (bind_result,
80 cache_value.second ());
82 if (result == -1)
85 this->map_.unbind (key);
87 // Unless the notification goes thru the bind operation is
88 // not complete.
89 bind_result = -1;
95 return bind_result;
99 template <ACE_T1> int
100 ACE_Cache_Map_Manager<ACE_T2>::rebind (const KEY &key,
101 const VALUE &value)
103 CACHE_VALUE cache_value (value,
104 this->caching_strategy_.attributes ());
106 int rebind_result = this->map_.rebind (key,
107 cache_value);
109 if (rebind_result != -1)
112 int result = this->caching_strategy_.notify_rebind (rebind_result,
113 cache_value.second ());
115 if (result == -1)
118 // Make sure the unbind operation is done only when the
119 // notification fails after a bind which is denoted by
120 // rebind_result = 0
121 if (rebind_result == 0)
122 this->map_.unbind (key);
124 // Unless the notification goes thru the rebind operation is
125 // not complete.
126 rebind_result = -1;
132 return rebind_result;
136 template <ACE_T1> int
137 ACE_Cache_Map_Manager<ACE_T2>::rebind (const KEY &key,
138 const VALUE &value,
139 VALUE &old_value)
141 CACHE_VALUE cache_value (value,
142 this->caching_strategy_.attributes ());
144 CACHE_VALUE old_cache_value (old_value,
145 this->caching_strategy_.attributes ());
147 int rebind_result = this->map_.rebind (key,
148 cache_value,
149 old_cache_value);
151 if (rebind_result != -1)
154 int result = this->caching_strategy_.notify_rebind (rebind_result,
155 cache_value.second ());
157 if (result == -1)
160 // Make sure the unbind operation is done only when the
161 // notification fails after a bind which is denoted by
162 // rebind_result = 0
163 if (rebind_result == 0)
164 this->map_.unbind (key);
166 // Unless the notification goes thru the rebind operation is
167 // not complete.
168 rebind_result = -1;
171 else
174 old_value = old_cache_value.first ();
180 return rebind_result;
183 template <ACE_T1> int
184 ACE_Cache_Map_Manager<ACE_T2>::rebind (const KEY &key,
185 const VALUE &value,
186 KEY &old_key,
187 VALUE &old_value)
189 CACHE_VALUE cache_value (value,
190 this->caching_strategy_.attributes ());
192 CACHE_VALUE old_cache_value (old_value,
193 this->caching_strategy_.attributes ());
195 int rebind_result = this->map_.rebind (key,
196 cache_value,
197 old_key,
198 old_cache_value);
200 if (rebind_result != -1)
203 int result = this->caching_strategy_.notify_rebind (rebind_result,
204 cache_value.second ());
206 if (result == -1)
209 // Make sure the unbind operation is done only when the
210 // notification fails after a bind which is denoted by
211 // rebind_result = 0
212 if (rebind_result == 0)
213 this->map_.unbind (key);
215 // Unless the notification goes thru the rebind operation is
216 // not complete.
217 rebind_result = -1;
220 else
223 old_value = old_cache_value.first ();
229 return rebind_result;
232 template <ACE_T1> int
233 ACE_Cache_Map_Manager<ACE_T2>::trybind (const KEY &key,
234 VALUE &value)
236 CACHE_VALUE cache_value (value,
237 this->caching_strategy_.attributes ());
239 int trybind_result = this->map_.trybind (key,
240 cache_value);
242 if (trybind_result != -1)
245 int result = this->caching_strategy_.notify_trybind (trybind_result,
246 cache_value.second ());
248 if (result == -1)
251 // If the entry has got inserted into the map, it is removed
252 // due to failure.
253 if (trybind_result == 0)
254 this->map_.unbind (key);
256 trybind_result = -1;
259 else
262 // If an attempt is made to bind an existing entry the value
263 // is overwritten with the value from the map.
264 if (trybind_result == 1)
265 value = cache_value.first ();
271 return trybind_result;
274 template <ACE_T1> int
275 ACE_Cache_Map_Manager<ACE_T2>::find (const KEY &key,
276 VALUE &value)
278 // Lookup the key and populate the <value>.
279 CACHE_VALUE cache_value;
281 int find_result = this->map_.find (key,
282 cache_value);
284 if (find_result != -1)
287 int result = this->caching_strategy_.notify_find (find_result,
288 cache_value.second ());
290 // Unless the find and notification operations go thru, this
291 // method is not successful.
292 if (result == -1)
293 find_result = -1;
294 else
297 // Since the <cache_value> has now changed after the
298 // notification, we need to bind to the map again.
299 int rebind_result = this->map_.rebind (key,
300 cache_value);
301 if (rebind_result == -1)
302 find_result = -1;
303 else
304 value = cache_value.first ();
310 return find_result;
313 template <ACE_T1> int
314 ACE_Cache_Map_Manager<ACE_T2>::find (const KEY &key)
316 // Lookup the key and populate the <value>.
317 CACHE_VALUE cache_value;
319 int find_result = this->map_.find (key,
320 cache_value);
322 if (find_result != -1)
325 int result = this->caching_strategy_.notify_find (find_result,
326 cache_value.second ());
328 // Unless the find and notification operations go thru, this
329 // method is not successful.
330 if (result == -1)
331 find_result = -1;
332 else
335 // Since the <cache_value> has now changed after the
336 // notification, we need to bind to the map again.
337 int rebind_result = this->map_.rebind (key,
338 cache_value);
340 if (rebind_result == -1)
341 find_result = -1;
347 return find_result;
351 template <ACE_T1> int
352 ACE_Cache_Map_Manager<ACE_T2>::unbind (const KEY &key)
354 // Remove the entry from the cache.
355 CACHE_VALUE cache_value;
357 int unbind_result = this->map_.unbind (key,
358 cache_value);
360 if (unbind_result != -1)
363 int result = this->caching_strategy_.notify_unbind (unbind_result,
364 cache_value.second ());
366 if (result == -1)
367 unbind_result = -1;
371 return unbind_result;
374 template <ACE_T1> int
375 ACE_Cache_Map_Manager<ACE_T2>::unbind (const KEY &key,
376 VALUE &value)
378 // Remove the entry from the cache.
379 CACHE_VALUE cache_value;
381 int unbind_result = this->map_.unbind (key,
382 cache_value);
384 if (unbind_result != -1)
387 int result = this->caching_strategy_.notify_unbind (unbind_result,
388 cache_value.second ());
390 if (result == -1)
391 unbind_result = -1;
392 else
393 value = cache_value.first ();
397 return unbind_result;
400 template <ACE_T1> void
401 ACE_Cache_Map_Manager<ACE_T2>::dump (void) const
403 #if defined (ACE_HAS_DUMP)
404 this->map_.dump ();
406 this->caching_strategy_.dump ();
407 #endif /* ACE_HAS_DUMP */
410 #undef ACE_T1
411 #undef ACE_T2
413 template <class KEY, class VALUE, class IMPLEMENTATION, class CACHING_STRATEGY, class ATTRIBUTES>
414 ACE_Cache_Map_Iterator<KEY, VALUE, IMPLEMENTATION, CACHING_STRATEGY, ATTRIBUTES>::~ACE_Cache_Map_Iterator (void)
418 ACE_END_VERSIONED_NAMESPACE_DECL
420 #endif /* ACE_CACHE_MAP_MANAGER_T_CPP */