00001 #include "ace_pch.h"
00002
00003
00004 #ifndef ACE_HASH_CACHE_MAP_MANAGER_T_C
00005 #define ACE_HASH_CACHE_MAP_MANAGER_T_C
00006
00007 #include "ace/Hash_Cache_Map_Manager_T.h"
00008
00009 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00010 #define ACE_LACKS_PRAGMA_ONCE
00011 #endif
00012
00013 #if !defined (__ACE_INLINE__)
00014 #include "ace/Hash_Cache_Map_Manager_T.i"
00015 #endif
00016
00017 ACE_RCSID(ace, Hash_Cache_Map_Manager_T, "$Id: Hash_Cache_Map_Manager_T.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:21 chad Exp $")
00018
00019 ACE_ALLOC_HOOK_DEFINE(ACE_Hash_Cache_Map_Manager)
00020
00021 #define T_1 class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES
00022 #define T_2 KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES
00023
00024 template <T_1>
00025 ACE_Hash_Cache_Map_Manager<T_2>::ACE_Hash_Cache_Map_Manager (CACHING_STRATEGY &caching_s,
00026 size_t size,
00027 ACE_Allocator *alloc)
00028 : ACE_HCMM_BASE (caching_s,
00029 size,
00030 alloc)
00031 {
00032 }
00033
00034 template <T_1>
00035 ACE_Hash_Cache_Map_Manager<T_2>::~ACE_Hash_Cache_Map_Manager (void)
00036 {
00037 }
00038
00039 template <T_1> int
00040 ACE_Hash_Cache_Map_Manager<T_2>:: bind (const KEY &key,
00041 const VALUE &value,
00042 CACHE_ENTRY *&entry)
00043 {
00044
00045
00046
00047 CACHE_VALUE cache_value (value,
00048 this->caching_strategy_.attributes ());
00049
00050 int bind_result = this->map_.bind (key,
00051 cache_value,
00052 entry);
00053
00054 if (bind_result != -1)
00055 {
00056
00057 int result = this->caching_strategy_.notify_bind (bind_result,
00058 cache_value.second ());
00059
00060 if (result == -1)
00061 {
00062
00063 this->map_.unbind (key);
00064
00065
00066
00067 bind_result = -1;
00068
00069 }
00070 }
00071
00072 return bind_result;
00073 }
00074
00075 template <T_1> int
00076 ACE_Hash_Cache_Map_Manager<T_2>::rebind (const KEY &key,
00077 const VALUE &value,
00078 CACHE_ENTRY *&entry)
00079 {
00080 CACHE_VALUE cache_value (value,
00081 this->caching_strategy_.attributes ());
00082
00083 int rebind_result = this->map_.rebind (key,
00084 cache_value,
00085 entry);
00086
00087 if (rebind_result != -1)
00088 {
00089
00090 int result = this->caching_strategy_.notify_rebind (rebind_result,
00091 cache_value.second ());
00092
00093 if (result == -1)
00094 {
00095
00096
00097
00098
00099 if (rebind_result == 0)
00100 this->map_.unbind (key);
00101
00102
00103
00104 rebind_result = -1;
00105
00106 }
00107
00108 }
00109
00110 return rebind_result;
00111 }
00112
00113 template <T_1> int
00114 ACE_Hash_Cache_Map_Manager<T_2>::trybind (const KEY &key,
00115 VALUE &value,
00116 CACHE_ENTRY *&entry)
00117 {
00118 CACHE_VALUE cache_value (value,
00119 this->caching_strategy_.attributes ());
00120
00121 int trybind_result = this->map_.trybind (key,
00122 cache_value,
00123 entry);
00124
00125 if (trybind_result != -1)
00126 {
00127 int result = this->caching_strategy_.notify_trybind (trybind_result,
00128 cache_value.second ());
00129
00130 if (result == -1)
00131 {
00132
00133
00134
00135 if (trybind_result == 0)
00136 this->map_.unbind (key);
00137
00138 trybind_result = -1;
00139
00140 }
00141 else
00142 {
00143
00144
00145
00146 if (trybind_result == 1)
00147 value = cache_value.first ();
00148
00149 }
00150
00151 }
00152
00153 return trybind_result;
00154 }
00155
00156 template <T_1> int
00157 ACE_Hash_Cache_Map_Manager<T_2>::find (const KEY &key,
00158 CACHE_ENTRY *&entry)
00159 {
00160
00161 int find_result = this->map_.find (key,
00162 entry);
00163
00164 if (find_result != -1)
00165 {
00166
00167 int result = this->caching_strategy_.notify_find (find_result,
00168 entry->int_id_.second ());
00169
00170
00171
00172 if (result == -1)
00173 find_result = -1;
00174 else
00175 find_result = 0;
00176
00177 }
00178
00179 return find_result;
00180 }
00181
00182 template <T_1> int
00183 ACE_Hash_Cache_Map_Manager<T_2>::find (const KEY &key,
00184 VALUE &value)
00185 {
00186 CACHE_ENTRY *entry = 0;
00187
00188 int result = this->find (key,
00189 entry);
00190
00191 if (result != -1)
00192 {
00193 value = entry->int_id_.first ();
00194 }
00195
00196 return result;
00197 }
00198
00199 template <T_1> int
00200 ACE_Hash_Cache_Map_Manager<T_2>::find (const KEY &key)
00201 {
00202 CACHE_ENTRY *entry = 0;
00203
00204 return this->find (key,
00205 entry);
00206 }
00207
00208 template <T_1> int
00209 ACE_Hash_Cache_Map_Manager<T_2>::unbind (CACHE_ENTRY *entry)
00210 {
00211
00212 int unbind_result = this->map_.unbind (entry);
00213
00214 if (unbind_result != -1)
00215 {
00216
00217 int result = this->caching_strategy_.notify_unbind (unbind_result,
00218 entry->int_id_.second ());
00219
00220 if (result == -1)
00221 unbind_result = -1;
00222
00223 }
00224
00225 return unbind_result;
00226 }
00227
00228 #undef T_1
00229 #undef T_2
00230
00231 #endif