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