Home · All Classes · Main Classes · Deprecated
Public Types | Public Member Functions | Static Public Attributes

MUniqueStringCache Class Reference

MUniqueStringCache can be used to map strings to unique ids. More...

List of all members.

Public Types

typedef int Index

Public Member Functions

 MUniqueStringCache (const QString &filename)
 ~MUniqueStringCache ()
bool isAttached ()
QLatin1String indexToString (Index id)
Index stringToIndex (const QByteArray &string)
bool lock ()
bool unlock ()
bool isLocked ()

Static Public Attributes

static const Index UndefinedIndex = -1
static const Index EmptyStringIndex = 0

Detailed Description

MUniqueStringCache can be used to map strings to unique ids.

The mapping is backed up by a file on disk which will be mmaped into memory at runtime. Therefor the ids can be shared between several running programs. Additionally the memory occupied by the strings will be shared between the processes. Proper locking will make sure that two processes cannot add strings to the cache at the same time. Reading values from the cache happens without locking.


Member Typedef Documentation


Constructor & Destructor Documentation

MUniqueStringCache::MUniqueStringCache ( const QString filename  ) 
MUniqueStringCache::~MUniqueStringCache (  ) 

Member Function Documentation

QLatin1String MUniqueStringCache::indexToString ( Index  id  ) 

Converts a given index into a string.

This lookup is very fast.

bool MUniqueStringCache::isAttached (  ) 

Returns true when the cache is properly attached to the file on disk.

bool MUniqueStringCache::isLocked (  ) 

Return true if the cache is locked.

bool MUniqueStringCache::lock (  ) 

indexToString() and stringToIndex() internally automatically lock the cache to ensure that no two processes are changing the cache at the same time.

If you know that the cache needs to be locked very often, e.g. because stringToIndex() is called often with strings likely not in the cache, this method can be used to lock it just once. This avoids the need to lock and unlock it seperately for every call to stringToIndex(). Make sure to call unlock() after all strings have been processed.

MUniqueStringCache::Index MUniqueStringCache::stringToIndex ( const QByteArray string  ) 

Returns the id for a given string.

If the string is not in the cache yet it will be added. If possible use this function only to fill the cache. To work it needs to read in the whole cache file to find the given string. Depending on the cache size this might be costly.

bool MUniqueStringCache::unlock (  ) 

Unlocks the cache formerly locked with lock().


Member Data Documentation


Copyright © 2010 Nokia Corporation
MeeGo Touch