ObjectCacheRandom Class Reference

provides a random cache replacement policy See also: class ObjectCache More...

#include <cachrand.h>

Inheritance diagram for ObjectCacheRandom:

ObjectCache CCObject SimpleCCObject List of all members.

Public Member Functions

 ObjectCacheRandom ()
 default constructor for ObjectCache Note:
 ObjectCacheRandom (UINT32 ceiling)
 constructor for ObjectCacheRandom. Set the size of the cache. Note:
 ~ObjectCacheRandom ()
 destructor for ObjectCache Note:

Protected Member Functions

BOOL DeleteObject ()
 delete an object in the cache according a radom algorithm. Note:

Private Member Functions

 CC_DECLARE_DYNCREATE (ObjectCacheRandom)

Detailed Description

provides a random cache replacement policy See also: class ObjectCache

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/01/97

Definition at line 119 of file cachrand.h.


Constructor & Destructor Documentation

ObjectCacheRandom::ObjectCacheRandom  ) 
 

default constructor for ObjectCache Note:

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/01/97
See also:

Definition at line 128 of file cachrand.cpp.

00129 {
00130     m_Ceiling = 0;
00131 }

ObjectCacheRandom::ObjectCacheRandom UINT32  ceiling  ) 
 

constructor for ObjectCacheRandom. Set the size of the cache. Note:

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/01/97
Parameters:
ceiling,: max size of the cache. [INPUTS]
See also:

Definition at line 144 of file cachrand.cpp.

00145 {
00146     m_Ceiling = ceiling;
00147 }

ObjectCacheRandom::~ObjectCacheRandom  ) 
 

destructor for ObjectCache Note:

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/01/97
See also:

Definition at line 159 of file cachrand.cpp.

00160 {
00161 }


Member Function Documentation

ObjectCacheRandom::CC_DECLARE_DYNCREATE ObjectCacheRandom   )  [private]
 

BOOL ObjectCacheRandom::DeleteObject  )  [protected, virtual]
 

delete an object in the cache according a radom algorithm. Note:

Author:
Olivier_Gascoin (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/01/97
Returns:
TRUE is success, FALSE otherwise.
See also:

Reimplemented from ObjectCache.

Definition at line 176 of file cachrand.cpp.

00177 {
00178     if (m_NumObjects == 0)
00179         return FALSE;
00180 
00181     srand((unsigned)time(NULL));
00182     BOOL ok = FALSE;
00183     WORD Factory = 0;
00184     CachedObject* pObj = NULL;
00185 
00186     do
00187     {
00188         WORD hObj = rand() % m_HandleFactory + 1;       // generate a handle 
00189         Factory++;                                  // count the number of generated numbers
00190 
00191         pObj = LookUp(hObj);                        // look up in the hash table
00192         ok = (pObj != NULL);
00193 
00194         if(ok)
00195         {
00196             Remove(hObj);                           // remove from the hash table
00197             m_NumObjects--;                         // decrease the number of objects
00198             m_CurrentSize -= pObj->GetSize();           // decrease the used space of cache
00199         }
00200     }
00201     while (!ok && Factory<=m_HandleFactory);
00202 
00203     //if(ok && Factory<=HandleFactory)
00204     if(ok)
00205     {
00206         delete pObj;
00207         pObj = NULL;
00208         return TRUE;
00209     }
00210 
00211     return FALSE;
00212 }


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:57:16 2007 for Camelot by  doxygen 1.4.4