summaryrefslogtreecommitdiff
path: root/ace/Cache_Map_Manager_T.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ace/Cache_Map_Manager_T.cpp')
-rw-r--r--ace/Cache_Map_Manager_T.cpp152
1 files changed, 97 insertions, 55 deletions
diff --git a/ace/Cache_Map_Manager_T.cpp b/ace/Cache_Map_Manager_T.cpp
index 376f981e5e4..0a7cc36ec46 100644
--- a/ace/Cache_Map_Manager_T.cpp
+++ b/ace/Cache_Map_Manager_T.cpp
@@ -20,7 +20,7 @@
ACE_RCSID(ace, Cache_Map_Manager_T, "$Id$")
ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Manager)
-
+
ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Iterator)
ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Reverse_Iterator)
@@ -28,36 +28,78 @@ ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Reverse_Iterator)
#define T_1 class KEY, class VALUE, class MAP, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES
#define T_2 KEY, VALUE, MAP, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES
- template <T_1>
-ACE_Cache_Map_Manager<T_2>::ACE_Cache_Map_Manager (CACHING_STRATEGY &caching_s,
- size_t size,
- ACE_Allocator *alloc)
- : caching_strategy_ (caching_s)
+template <T_1>
+ACE_Cache_Map_Manager<T_2>::ACE_Cache_Map_Manager (size_t size,
+ ACE_Allocator *alloc,
+ CACHING_STRATEGY *caching_s,
+ int delete_caching_strategy)
+ : caching_strategy_ (0)
{
- if (this->open (size, alloc) == -1)
+ if (this->open (size, alloc, caching_s, delete_caching_strategy) == -1)
ACE_ERROR ((LM_ERROR,
ASYS_TEXT ("%p\n"),
ASYS_TEXT ("ACE_Cache_Map_Manager::ACE_Cache_Map_Manager")));
-
+
}
template <T_1>
ACE_Cache_Map_Manager<T_2>::~ACE_Cache_Map_Manager (void)
{
- this->close ();
}
template <T_1> int
ACE_Cache_Map_Manager<T_2>::open (size_t length,
- ACE_Allocator *alloc)
+ ACE_Allocator *alloc,
+ CACHING_STRATEGY *caching_s,
+ int delete_caching_strategy)
{
- return this->map_.open (length,
- alloc);
+ // Create the map.
+ if (this->map_.open (length,
+ alloc) == -1)
+ return -1;
+
+ // Initialise the caching strategy.
+
+ // First we decide whether we need to clean up.
+ if (this->caching_strategy_ != 0 &&
+ this->delete_caching_strategy_ == 1 &&
+ caching_s != 0)
+ {
+
+ delete this->caching_strategy_;
+
+ this->caching_strategy_ = 0;
+
+ this->delete_caching_strategy_ = delete_caching_strategy;
+
+ }
+
+ if (caching_s != 0)
+ this->caching_strategy_ = caching_s;
+ else if (this->caching_strategy_ == 0)
+ {
+
+ ACE_NEW_RETURN (this->caching_strategy_,
+ CACHING_STRATEGY,
+ -1);
+
+ this->delete_caching_strategy_ = delete_caching_strategy;
+
+ }
+
+ return 0;
}
template <T_1> int
ACE_Cache_Map_Manager<T_2>::close (void)
{
+ if (this->delete_caching_strategy_ == 1)
+ delete this->caching_strategy_;
+
+ this->delete_caching_strategy_ = 0;
+
+ this->caching_strategy_ = 0;
+
return this->map_.close ();
}
@@ -69,7 +111,7 @@ ACE_Cache_Map_Manager<T_2>::bind (const KEY &key,
// is the combination of the <value> and the attributes of the
// caching strategy.
CACHE_VALUE cache_value (value,
- this->caching_strategy_.attributes ());
+ this->caching_strategy_->attributes ());
int bind_result = this->map_.bind (key,
cache_value);
@@ -77,8 +119,8 @@ ACE_Cache_Map_Manager<T_2>::bind (const KEY &key,
if (bind_result != -1)
{
- int result = this->caching_strategy_.notify_bind (bind_result,
- cache_value.second ());
+ int result = this->caching_strategy_->notify_bind (bind_result,
+ cache_value.second ());
if (result == -1)
{
@@ -102,7 +144,7 @@ ACE_Cache_Map_Manager<T_2>::rebind (const KEY &key,
const VALUE &value)
{
CACHE_VALUE cache_value (value,
- this->caching_strategy_.attributes ());
+ this->caching_strategy_->attributes ());
int rebind_result = this->map_.rebind (key,
cache_value);
@@ -110,8 +152,8 @@ ACE_Cache_Map_Manager<T_2>::rebind (const KEY &key,
if (rebind_result != -1)
{
- int result = this->caching_strategy_.notify_rebind (rebind_result,
- cache_value.second ());
+ int result = this->caching_strategy_->notify_rebind (rebind_result,
+ cache_value.second ());
if (result == -1)
{
@@ -140,10 +182,10 @@ ACE_Cache_Map_Manager<T_2>::rebind (const KEY &key,
VALUE &old_value)
{
CACHE_VALUE cache_value (value,
- this->caching_strategy_.attributes ());
+ this->caching_strategy_->attributes ());
CACHE_VALUE old_cache_value (old_value,
- this->caching_strategy_.attributes ());
+ this->caching_strategy_->attributes ());
int rebind_result = this->map_.rebind (key,
cache_value,
@@ -152,8 +194,8 @@ ACE_Cache_Map_Manager<T_2>::rebind (const KEY &key,
if (rebind_result != -1)
{
- int result = this->caching_strategy_.notify_rebind (rebind_result,
- cache_value.second ());
+ int result = this->caching_strategy_->notify_rebind (rebind_result,
+ cache_value.second ());
if (result == -1)
{
@@ -188,10 +230,10 @@ ACE_Cache_Map_Manager<T_2>::rebind (const KEY &key,
VALUE &old_value)
{
CACHE_VALUE cache_value (value,
- this->caching_strategy_.attributes ());
+ this->caching_strategy_->attributes ());
CACHE_VALUE old_cache_value (old_value,
- this->caching_strategy_.attributes ());
+ this->caching_strategy_->attributes ());
int rebind_result = this->map_.rebind (key,
cache_value,
@@ -201,8 +243,8 @@ ACE_Cache_Map_Manager<T_2>::rebind (const KEY &key,
if (rebind_result != -1)
{
- int result = this->caching_strategy_.notify_rebind (rebind_result,
- cache_value.second ());
+ int result = this->caching_strategy_->notify_rebind (rebind_result,
+ cache_value.second ());
if (result == -1)
{
@@ -235,17 +277,17 @@ ACE_Cache_Map_Manager<T_2>::trybind (const KEY &key,
VALUE &value)
{
CACHE_VALUE cache_value (value,
- this->caching_strategy_.attributes ());
+ this->caching_strategy_->attributes ());
int trybind_result = this->map_.trybind (key,
cache_value);
if (trybind_result != -1)
{
-
- int result = this->caching_strategy_.notify_trybind (trybind_result,
- cache_value.second ());
-
+
+ int result = this->caching_strategy_->notify_trybind (trybind_result,
+ cache_value.second ());
+
if (result == -1)
{
@@ -259,14 +301,14 @@ ACE_Cache_Map_Manager<T_2>::trybind (const KEY &key,
}
else
{
-
+
// If an attempt is made to bind an existing entry the value
// is overwritten with the value from the map.
if (trybind_result == 1)
value = cache_value.first ();
-
+
}
-
+
}
return trybind_result;
@@ -285,8 +327,8 @@ ACE_Cache_Map_Manager<T_2>::find (const KEY &key,
if (find_result != -1)
{
- int result = this->caching_strategy_.notify_find (find_result,
- cache_value.second ());
+ int result = this->caching_strategy_->notify_find (find_result,
+ cache_value.second ());
// Unless the find and notification operations go thru, this
// method is not successful.
@@ -294,7 +336,7 @@ ACE_Cache_Map_Manager<T_2>::find (const KEY &key,
find_result = -1;
else
{
-
+
// Since the <cache_value> has now changed after the
// notification, we need to bind to the map again.
int rebind_result = this->map_.rebind (key,
@@ -303,9 +345,9 @@ ACE_Cache_Map_Manager<T_2>::find (const KEY &key,
find_result = -1;
else
value = cache_value.first ();
-
+
}
-
+
}
return find_result;
@@ -323,8 +365,8 @@ ACE_Cache_Map_Manager<T_2>::find (const KEY &key)
if (find_result != -1)
{
- int result = this->caching_strategy_.notify_find (find_result,
- cache_value.second ());
+ int result = this->caching_strategy_->notify_find (find_result,
+ cache_value.second ());
// Unless the find and notification operations go thru, this
// method is not successful.
@@ -332,15 +374,15 @@ ACE_Cache_Map_Manager<T_2>::find (const KEY &key)
find_result = -1;
else
{
-
+
// Since the <cache_value> has now changed after the
// notification, we need to bind to the map again.
int rebind_result = this->map_.rebind (key,
cache_value);
-
+
if (rebind_result == -1)
find_result = -1;
-
+
}
}
@@ -360,13 +402,13 @@ ACE_Cache_Map_Manager<T_2>::unbind (const KEY &key)
if (unbind_result != -1)
{
-
- int result = this->caching_strategy_.notify_unbind (unbind_result,
- cache_value.second ());
+
+ int result = this->caching_strategy_->notify_unbind (unbind_result,
+ cache_value.second ());
if (result == -1)
unbind_result = -1;
-
+
}
return unbind_result;
@@ -384,15 +426,15 @@ ACE_Cache_Map_Manager<T_2>::unbind (const KEY &key,
if (unbind_result != -1)
{
-
- int result = this->caching_strategy_.notify_unbind (unbind_result,
- cache_value.second ());
-
+
+ int result = this->caching_strategy_->notify_unbind (unbind_result,
+ cache_value.second ());
+
if (result == -1)
unbind_result = -1;
else
value = cache_value.first ();
-
+
}
return unbind_result;
@@ -403,8 +445,8 @@ template <T_1> void
ACE_Cache_Map_Manager<T_2>::dump (void) const
{
this->map_.dump ();
-
- this->caching_strategy_.dump ();
+
+ this->caching_strategy_->dump ();
}
#undef T_1