Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Pair_Caching_Utility Class Template Reference

Defines a helper class for the Caching Strategies. More...

#include <Caching_Utility_T.h>

Collaboration diagram for ACE_Pair_Caching_Utility:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_Cleanup_Strategy<
KEY, VALUE, CONTAINER > 
CLEANUP_STRATEGY

Public Methods

 ACE_Pair_Caching_Utility (ACE_Cleanup_Strategy< KEY, VALUE, CONTAINER > *cleanup_strategy=0, int delete_cleanup_strategy=0)
 Constructor. More...

 ~ACE_Pair_Caching_Utility (void)
 Destructor. More...

int clear_cache (CONTAINER &container, double purge_percent)

Protected Methods

void minimum (CONTAINER &container, KEY *&key_to_remove, VALUE *&value_to_remove)
 Find the entry with minimum caching attributes. More...

void operator= (const APUTIL< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &)
 APUTIL (const APUTIL< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &)

Protected Attributes

CLEANUP_STRATEGYcleanup_strategy_
 The cleanup strategy which can be used to destroy the entries of the container. More...

int delete_cleanup_strategy_
 Whether the cleanup_strategy should be destroyed or not. More...


Detailed Description

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
class ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >

Defines a helper class for the Caching Strategies.

This class defines the methods commonly used by the different caching strategies. For instance: <clear_cache> method which decides and purges the entry from the container. Note: This class helps in the caching_strategies using a container containing entries of <KEY, ACE_Pair<VALUE, attributes>> kind. The attributes helps in deciding the entries to be purged. The Cleanup_Strategy is the callback class to which the entries to be cleaned up will be delegated.

Definition at line 45 of file Caching_Utility_T.h.


Member Typedef Documentation

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
typedef ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> ACE_Pair_Caching_Utility::CLEANUP_STRATEGY
 

Definition at line 49 of file Caching_Utility_T.h.


Constructor & Destructor Documentation

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::ACE_Pair_Caching_Utility ACE_Cleanup_Strategy< KEY, VALUE, CONTAINER > *    cleanup_strategy = 0,
int    delete_cleanup_strategy = 0
 

Constructor.

Definition at line 22 of file Caching_Utility_T.cpp.

References ACE_NEW, and delete_cleanup_strategy_.

00024   : cleanup_strategy_ (cleanup_strategy),
00025     delete_cleanup_strategy_ (delete_cleanup_strategy)
00026 {
00027   if (cleanup_strategy == 0)
00028     {
00029       ACE_NEW (this->cleanup_strategy_,
00030                CLEANUP_STRATEGY);
00031       this->delete_cleanup_strategy_ = 1;
00032     }
00033 }

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::~ACE_Pair_Caching_Utility void   
 

Destructor.

Definition at line 36 of file Caching_Utility_T.cpp.

References cleanup_strategy_, and delete_cleanup_strategy_.

00037 {
00038   if (this->delete_cleanup_strategy_)
00039     delete this->cleanup_strategy_;
00040 }


Member Function Documentation

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::APUTIL const APUTIL< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &    [protected]
 

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
int ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::clear_cache CONTAINER &    container,
double    purge_percent
 

Purge entries from the <container>. The Cleanup_Strategy will do the actual job of cleanup once the entries to be cleaned up are decided.

Definition at line 43 of file Caching_Utility_T.cpp.

References ACE_MAX, ACE_Cleanup_Strategy::cleanup, cleanup_strategy_, and minimum.

00045 {
00046   // Check that the purge_percent is non-zero.
00047   if (purge_percent == 0)
00048     return 0;
00049 
00050   // Get the number of entries in the container.
00051   size_t current_map_size = container.current_size ();
00052 
00053   // Also whether the number of entries in the cache!
00054   // Oops! then there is no way out but exiting. So return an error.
00055   if (current_map_size == 0)
00056     return 0;
00057 
00058   // Calculate the no of entries to remove from the cache depending
00059   // upon the <purge_percent>.
00060   size_t entries_to_remove
00061     = ACE_MAX (ACE_static_cast (size_t, 1),
00062                ACE_static_cast (size_t,
00063                                 ACE_static_cast(double, purge_percent)
00064                                 / 100 * current_map_size));
00065   KEY *key_to_remove = 0;
00066   VALUE *value_to_remove = 0;
00067 
00068   for (size_t i = 0; i < entries_to_remove ; ++i)
00069     {
00070       this->minimum (container,
00071                      key_to_remove,
00072                      value_to_remove);
00073 
00074       // Simply verifying that the key is non-zero.
00075       // This is important for strategies where the minimum
00076       // entry cant be found due to constraints on the type of entry
00077       // to remove.
00078       if (key_to_remove == 0)
00079         return 0;
00080 
00081       if (this->cleanup_strategy_->cleanup (container,
00082                                             key_to_remove,
00083                                             value_to_remove) == -1)
00084         return -1;
00085 
00086     }
00087 
00088   return 0;
00089 }

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
void ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::minimum CONTAINER &    container,
KEY *&    key_to_remove,
VALUE *&    value_to_remove
[protected]
 

Find the entry with minimum caching attributes.

Definition at line 92 of file Caching_Utility_T.cpp.

Referenced by clear_cache.

00095 {
00096   // Starting values.
00097   ITERATOR iter = container.begin ();
00098   ITERATOR end = container.end ();
00099   ATTRIBUTES min = (*iter).int_id_.second ();
00100   key_to_remove = &(*iter).ext_id_;
00101   value_to_remove = &(*iter).int_id_;
00102 
00103   // The iterator moves thru the container searching for the entry
00104   // with the lowest ATTRIBUTES.
00105   for (++iter;
00106        iter != end;
00107        ++iter)
00108     {
00109       if (min > (*iter).int_id_.second ())
00110         {
00111           // Ah! an item with lower ATTTRIBUTES...
00112           min = (*iter).int_id_.second ();
00113           key_to_remove = &(*iter).ext_id_;
00114           value_to_remove = &(*iter).int_id_;
00115         }
00116     }
00117 }

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
void ACE_Pair_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::operator= const APUTIL< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &    [protected]
 


Member Data Documentation

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
CLEANUP_STRATEGY* ACE_Pair_Caching_Utility::cleanup_strategy_ [protected]
 

The cleanup strategy which can be used to destroy the entries of the container.

Definition at line 74 of file Caching_Utility_T.h.

Referenced by clear_cache, and ~ACE_Pair_Caching_Utility.

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
int ACE_Pair_Caching_Utility::delete_cleanup_strategy_ [protected]
 

Whether the cleanup_strategy should be destroyed or not.

Definition at line 77 of file Caching_Utility_T.h.

Referenced by ACE_Pair_Caching_Utility, and ~ACE_Pair_Caching_Utility.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:51:59 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002