CacheIndex Class Reference

Class for managing files for cache entries and storing/loading a database-like representation into/from a XML-file 'cacheindex.xml'. More...

#include <cacheindex.h>

List of all members.

Classes

class  CacheIndexEntry
 A CacheIndexEntry contains conceptionally of one top-level key and multiple CacheIndexSubEntry objects.

Public Types

typedef std::pair< std::string,
std::string > 
IndexKey
 IndexKey contains the top-level key at first position of the pair, and the sub-level key at first position.

Public Member Functions

 ~CacheIndex ()
 Dtor saving the content of this object (and especially the one of all containing CacheIndexEntry objects and the therein contained CacheIndexSubEntry objects) to an XML file by calling writeIndexFile().
std::vector< std::pair
< std::string, std::string > > 
cleanup ()
 Returns a pair of two strings containing the key of the object which has to be deleted from the cache's object map on first position and the name of the corresponding file which has to be deleted, too, on second position.
bool entryExists (const std::string &key) const
 Checks whether a CacheIndexEntry for the given top-level key exists.
std::string findFilename (Processor *const processor, Port *const port, const std::string &inportConfig)
 Returns the file name stored in the CacheIndex for the given processor, port and the input configuration of that processor port.
std::vector< CacheIndexEntry > & getDisplacedEntries ()
 Returns all the CacheIndexEntry which might have been displaced by insertions of new CacheIndexEntry objects into the CacheIndex, and copies of the CacheIndexEntry objects in which CacheIndexSubEntries might have been replaced by insertions of new CacheIndexSubEntries.
void incrementRefCounter (const IndexKey &key)
 Increments the reference counter for the CacheIndexEntry and the CacheIndexSubEntry associated with the respective parts of the given IndexKey.
std::string insert (Processor *const processor, Port *const port, const std::string &objectClassName, const std::string &inportConfig, const std::string &filename)
 Creates a new CacheIndexEntry and an encapsulated CacheIndexSubEntry object based on the given parameters and inserts it.

Static Public Member Functions

static CacheIndexgetInstance ()
 The only possibility to access an instance of this class, for it has been implemented by using the Singleton design pattern.
static IndexKey generateCacheIndexKey (Processor *const processor, Port *const port, const std::string &inportConfig)
 Generates and returns and entire key for the given configuration of processor, port and inportConfig as an IndexKey object, which is actually a pair of strings.

Detailed Description

Class for managing files for cache entries and storing/loading a database-like representation into/from a XML-file 'cacheindex.xml'.

The underlying data of the cache entries are the names of the files where the cached data can be found on hard-disk, associated with keys. An object in the cache is associated with a key which consists of the concatenation of a top-level key and a sub-level key, separated by a dot ("."). The cached data are written to disk by the Cache<T> class, but the file name is mapped to that key by CacheIndex. Besides, CacheIndex checks the existence of the directory the cache uses, and creates it if necessary. CacheIndex is designed using the singleton design pattern, i.e. that there is only one CacheIndex, managing all cached objects. Destinctions between different kinds of object may be made by the key,

The CacheIndex has a two-level hierarchy: it holds 0..* CacheIndexEntry objects, which on their parts consist of a top-level key and may contain 0..* objects of the CacheIndexSubEntry class. CacheIndexSubEntry objects hold one sub-level key (sub-keys) each and the actual file name for the cached data.

Author:
Dirk Feldmann, June/July 2009

Definition at line 67 of file cacheindex.h.


Member Function Documentation

bool entryExists ( const std::string &  key  )  const

Checks whether a CacheIndexEntry for the given top-level key exists.

Parameters:
top-level key which shall be found
Returns:
true, if the CacheIndexEntry exists, false otherwise

Definition at line 234 of file cacheindex.cpp.

std::string findFilename ( Processor *const   processor,
Port *const   port,
const std::string &  inportConfig 
)

Returns the file name stored in the CacheIndex for the given processor, port and the input configuration of that processor port.

Parameters:
processor The processor of which is concerned
port The port of the processor which is concerned
inportConfig The string representation of the input configuration of that port.
Returns:
The file name which holds the cached object for that processor and that port when the port has the given inport configuration, or and empty string, if no data are cached for that combination of processor, port and input data on that port.

Definition at line 239 of file cacheindex.cpp.

CacheIndex::IndexKey generateCacheIndexKey ( Processor *const   processor,
Port *const   port,
const std::string &  inportConfig 
) [static]

Generates and returns and entire key for the given configuration of processor, port and inportConfig as an IndexKey object, which is actually a pair of strings.

The top-level key is located in the first position, the sub-level key in the second one.

Parameters:
processor Processor for which the key shall be generated.
port Port on that processor for which the key shall be generated.
inportConfig String representation of the configuration of the inports of that processor for key generation.
Returns:
The entire key as IndexKey object with the top-level key in the first, and the sub-level key in the second position.

Definition at line 322 of file cacheindex.cpp.

std::vector<CacheIndexEntry>& getDisplacedEntries (  )  [inline]

Returns all the CacheIndexEntry which might have been displaced by insertions of new CacheIndexEntry objects into the CacheIndex, and copies of the CacheIndexEntry objects in which CacheIndexSubEntries might have been replaced by insertions of new CacheIndexSubEntries.

This data are used by the Cache<T> to remove files no longer needed.

Definition at line 425 of file cacheindex.h.

void incrementRefCounter ( const IndexKey key  ) 

Increments the reference counter for the CacheIndexEntry and the CacheIndexSubEntry associated with the respective parts of the given IndexKey.

If one of those objects does not exist, nothing happens.

Parameters:
key IndexKey (composed of top-level and sub-level) of the entries whose reference counters shall be increased to indicate an access by the Cache.

Definition at line 262 of file cacheindex.cpp.

std::string insert ( Processor *const   processor,
Port *const   port,
const std::string &  objectClassName,
const std::string &  inportConfig,
const std::string &  filename 
)

Creates a new CacheIndexEntry and an encapsulated CacheIndexSubEntry object based on the given parameters and inserts it.

This method returns the concatenation of the top-level key from the created CacheIndexEntry and the sub-leve key of the created CacheIndexSubEntry, separated by a dot (".").

Parameters:
processor The processor for which an entry shall be created
port The port on that processor for which the entry shall be created
objectClassName Name of the class of the object which is cached.
inportConfig String representation of the Configuration of the inports of the port on the processor.
filename Name of the file where the cached object is stored on hard disk.
Returns:
The concatenation of the top-level key from the created CacheIndexEntry and the sub-level key of the created CacheIndexSubEntry, separated by a dot (".") if the insertsion is successful. Otherwise an empty string ist retruned.

Definition at line 271 of file cacheindex.cpp.