00001
00002
00003 #ifndef ACE_CACHE_MAP_MANAGER_T_CPP
00004 #define ACE_CACHE_MAP_MANAGER_T_CPP
00005
00006 #include "ace/Cache_Map_Manager_T.h"
00007
00008 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00009 #pragma once
00010 #endif
00011
00012 #include "ace/Log_Msg.h"
00013 #include "ace/Malloc_Base.h"
00014
00015 #if !defined (__ACE_INLINE__)
00016 #include "ace/Cache_Map_Manager_T.inl"
00017 #endif
00018
00019 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00020
00021 ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Manager)
00022
00023 ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Iterator)
00024
00025 ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Reverse_Iterator)
00026
00027 #define ACE_T1 class KEY, class VALUE, class CMAP_TYPE, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES
00028 #define ACE_T2 KEY, VALUE, CMAP_TYPE, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES
00029
00030 template <ACE_T1>
00031 ACE_Cache_Map_Manager<ACE_T2>::ACE_Cache_Map_Manager (CACHING_STRATEGY &caching_s,
00032 size_t size,
00033 ACE_Allocator *alloc)
00034 : caching_strategy_ (caching_s)
00035 {
00036 if (this->open (size, alloc) == -1)
00037 ACE_ERROR ((LM_ERROR,
00038 ACE_LIB_TEXT ("%p\n"),
00039 ACE_LIB_TEXT ("ACE_Cache_Map_Manager::ACE_Cache_Map_Manager")));
00040
00041 }
00042
00043 template <ACE_T1>
00044 ACE_Cache_Map_Manager<ACE_T2>::~ACE_Cache_Map_Manager (void)
00045 {
00046 this->close ();
00047 }
00048
00049 template <ACE_T1> int
00050 ACE_Cache_Map_Manager<ACE_T2>::open (size_t length,
00051 ACE_Allocator *alloc)
00052 {
00053 return this->map_.open (length,
00054 alloc);
00055 }
00056
00057 template <ACE_T1> int
00058 ACE_Cache_Map_Manager<ACE_T2>::close (void)
00059 {
00060 return this->map_.close ();
00061 }
00062
00063 template <ACE_T1> int
00064 ACE_Cache_Map_Manager<ACE_T2>::bind (const KEY &key,
00065 const VALUE &value)
00066 {
00067
00068
00069
00070 CACHE_VALUE cache_value (value,
00071 this->caching_strategy_.attributes ());
00072
00073 int bind_result = this->map_.bind (key,
00074 cache_value);
00075
00076 if (bind_result != -1)
00077 {
00078
00079 int result = this->caching_strategy_.notify_bind (bind_result,
00080 cache_value.second ());
00081
00082 if (result == -1)
00083 {
00084
00085 this->map_.unbind (key);
00086
00087
00088
00089 bind_result = -1;
00090
00091 }
00092
00093 }
00094
00095 return bind_result;
00096 }
00097
00098
00099 template <ACE_T1> int
00100 ACE_Cache_Map_Manager<ACE_T2>::rebind (const KEY &key,
00101 const VALUE &value)
00102 {
00103 CACHE_VALUE cache_value (value,
00104 this->caching_strategy_.attributes ());
00105
00106 int rebind_result = this->map_.rebind (key,
00107 cache_value);
00108
00109 if (rebind_result != -1)
00110 {
00111
00112 int result = this->caching_strategy_.notify_rebind (rebind_result,
00113 cache_value.second ());
00114
00115 if (result == -1)
00116 {
00117
00118
00119
00120
00121 if (rebind_result == 0)
00122 this->map_.unbind (key);
00123
00124
00125
00126 rebind_result = -1;
00127
00128 }
00129
00130 }
00131
00132 return rebind_result;
00133 }
00134
00135
00136 template <ACE_T1> int
00137 ACE_Cache_Map_Manager<ACE_T2>::rebind (const KEY &key,
00138 const VALUE &value,
00139 VALUE &old_value)
00140 {
00141 CACHE_VALUE cache_value (value,
00142 this->caching_strategy_.attributes ());
00143
00144 CACHE_VALUE old_cache_value (old_value,
00145 this->caching_strategy_.attributes ());
00146
00147 int rebind_result = this->map_.rebind (key,
00148 cache_value,
00149 old_cache_value);
00150
00151 if (rebind_result != -1)
00152 {
00153
00154 int result = this->caching_strategy_.notify_rebind (rebind_result,
00155 cache_value.second ());
00156
00157 if (result == -1)
00158 {
00159
00160
00161
00162
00163 if (rebind_result == 0)
00164 this->map_.unbind (key);
00165
00166
00167
00168 rebind_result = -1;
00169
00170 }
00171 else
00172 {
00173
00174 old_value = old_cache_value.first ();
00175
00176 }
00177
00178 }
00179
00180 return rebind_result;
00181 }
00182
00183 template <ACE_T1> int
00184 ACE_Cache_Map_Manager<ACE_T2>::rebind (const KEY &key,
00185 const VALUE &value,
00186 KEY &old_key,
00187 VALUE &old_value)
00188 {
00189 CACHE_VALUE cache_value (value,
00190 this->caching_strategy_.attributes ());
00191
00192 CACHE_VALUE old_cache_value (old_value,
00193 this->caching_strategy_.attributes ());
00194
00195 int rebind_result = this->map_.rebind (key,
00196 cache_value,
00197 old_key,
00198 old_cache_value);
00199
00200 if (rebind_result != -1)
00201 {
00202
00203 int result = this->caching_strategy_.notify_rebind (rebind_result,
00204 cache_value.second ());
00205
00206 if (result == -1)
00207 {
00208
00209
00210
00211
00212 if (rebind_result == 0)
00213 this->map_.unbind (key);
00214
00215
00216
00217 rebind_result = -1;
00218
00219 }
00220 else
00221 {
00222
00223 old_value = old_cache_value.first ();
00224
00225 }
00226
00227 }
00228
00229 return rebind_result;
00230 }
00231
00232 template <ACE_T1> int
00233 ACE_Cache_Map_Manager<ACE_T2>::trybind (const KEY &key,
00234 VALUE &value)
00235 {
00236 CACHE_VALUE cache_value (value,
00237 this->caching_strategy_.attributes ());
00238
00239 int trybind_result = this->map_.trybind (key,
00240 cache_value);
00241
00242 if (trybind_result != -1)
00243 {
00244
00245 int result = this->caching_strategy_.notify_trybind (trybind_result,
00246 cache_value.second ());
00247
00248 if (result == -1)
00249 {
00250
00251
00252
00253 if (trybind_result == 0)
00254 this->map_.unbind (key);
00255
00256 trybind_result = -1;
00257
00258 }
00259 else
00260 {
00261
00262
00263
00264 if (trybind_result == 1)
00265 value = cache_value.first ();
00266
00267 }
00268
00269 }
00270
00271 return trybind_result;
00272 }
00273
00274 template <ACE_T1> int
00275 ACE_Cache_Map_Manager<ACE_T2>::find (const KEY &key,
00276 VALUE &value)
00277 {
00278
00279 CACHE_VALUE cache_value;
00280
00281 int find_result = this->map_.find (key,
00282 cache_value);
00283
00284 if (find_result != -1)
00285 {
00286
00287 int result = this->caching_strategy_.notify_find (find_result,
00288 cache_value.second ());
00289
00290
00291
00292 if (result == -1)
00293 find_result = -1;
00294 else
00295 {
00296
00297
00298
00299 int rebind_result = this->map_.rebind (key,
00300 cache_value);
00301 if (rebind_result == -1)
00302 find_result = -1;
00303 else
00304 value = cache_value.first ();
00305
00306 }
00307
00308 }
00309
00310 return find_result;
00311 }
00312
00313 template <ACE_T1> int
00314 ACE_Cache_Map_Manager<ACE_T2>::find (const KEY &key)
00315 {
00316
00317 CACHE_VALUE cache_value;
00318
00319 int find_result = this->map_.find (key,
00320 cache_value);
00321
00322 if (find_result != -1)
00323 {
00324
00325 int result = this->caching_strategy_.notify_find (find_result,
00326 cache_value.second ());
00327
00328
00329
00330 if (result == -1)
00331 find_result = -1;
00332 else
00333 {
00334
00335
00336
00337 int rebind_result = this->map_.rebind (key,
00338 cache_value);
00339
00340 if (rebind_result == -1)
00341 find_result = -1;
00342
00343 }
00344
00345 }
00346
00347 return find_result;
00348 }
00349
00350
00351 template <ACE_T1> int
00352 ACE_Cache_Map_Manager<ACE_T2>::unbind (const KEY &key)
00353 {
00354
00355 CACHE_VALUE cache_value;
00356
00357 int unbind_result = this->map_.unbind (key,
00358 cache_value);
00359
00360 if (unbind_result != -1)
00361 {
00362
00363 int result = this->caching_strategy_.notify_unbind (unbind_result,
00364 cache_value.second ());
00365
00366 if (result == -1)
00367 unbind_result = -1;
00368
00369 }
00370
00371 return unbind_result;
00372 }
00373
00374 template <ACE_T1> int
00375 ACE_Cache_Map_Manager<ACE_T2>::unbind (const KEY &key,
00376 VALUE &value)
00377 {
00378
00379 CACHE_VALUE cache_value;
00380
00381 int unbind_result = this->map_.unbind (key,
00382 cache_value);
00383
00384 if (unbind_result != -1)
00385 {
00386
00387 int result = this->caching_strategy_.notify_unbind (unbind_result,
00388 cache_value.second ());
00389
00390 if (result == -1)
00391 unbind_result = -1;
00392 else
00393 value = cache_value.first ();
00394
00395 }
00396
00397 return unbind_result;
00398 }
00399
00400 template <ACE_T1> void
00401 ACE_Cache_Map_Manager<ACE_T2>::dump (void) const
00402 {
00403 #if defined (ACE_HAS_DUMP)
00404 this->map_.dump ();
00405
00406 this->caching_strategy_.dump ();
00407 #endif
00408 }
00409
00410 #undef ACE_T1
00411 #undef ACE_T2
00412
00413 template <class KEY, class VALUE, class IMPLEMENTATION, class CACHING_STRATEGY, class ATTRIBUTES>
00414 ACE_Cache_Map_Iterator<KEY, VALUE, IMPLEMENTATION, CACHING_STRATEGY, ATTRIBUTES>::~ACE_Cache_Map_Iterator (void)
00415 {
00416 }
00417
00418 ACE_END_VERSIONED_NAMESPACE_DECL
00419
00420 #endif