Sirikata
Public Member Functions | Private Attributes
Sirikata::Transfer::CacheMap::write_iterator Class Reference

A read-write iterator. More...

#include <CacheMap.hpp>

Inheritance diagram for Sirikata::Transfer::CacheMap::write_iterator:
Collaboration diagram for Sirikata::Transfer::CacheMap::write_iterator:

List of all members.

Public Member Functions

 write_iterator (CacheMap &m)
 Construct from a CacheMap (contains a scoped write lock)
 operator bool () const
bool find (const Fingerprint &id)
 Moves this iterator to id.
CacheDataoperator* ()
const FingerprintgetId () const
cache_usize_type getSize () const
PolicyData getPolicyInfo ()
void use ()
 Sets the use bit in the corresponding cache policy.
void update (cache_usize_type newSize)
 Calls use(), and updates the size of this element.
void erase ()
 Erases the current iterator.
void eraseAll ()
 Iterates through the whole map, destroy()ing everything.
bool insert (const Fingerprint &id, cache_usize_type size)
 Inserts a new entry into the map, unless it already exists.

Private Attributes

CacheMapmCachemap
boost::unique_lock
< boost::shared_mutex > 
mLock
MapClassmMap
MapClass::iterator mIter

Detailed Description

A read-write iterator.

Also contains insert() and erase() functions which also interact with the appropriate CachePolicy. The write_iterator aassumes exclusive ownership of the map. Since creating two write_iterators at once causes deadlock, make sure to call the alloc() function that takes a write_iterator argument if you already own one.


Constructor & Destructor Documentation

Sirikata::Transfer::CacheMap::write_iterator::write_iterator ( CacheMap m) [inline]

Construct from a CacheMap (contains a scoped write lock)


Member Function Documentation

void Sirikata::Transfer::CacheMap::write_iterator::erase ( ) [inline]
void Sirikata::Transfer::CacheMap::write_iterator::eraseAll ( ) [inline]

Iterates through the whole map, destroy()ing everything.

Note that the write_iterator contains no iterate() method because it is generally not safe.

References Sirikata::Transfer::CachePolicy::destroy(), Sirikata::Transfer::CacheMap::destroyCacheLayerEntry(), getId(), getPolicyInfo(), getSize(), mCachemap, mIter, mMap, and Sirikata::Transfer::CacheMap::mPolicy.

Referenced by Sirikata::Transfer::CacheMap::~CacheMap().

bool Sirikata::Transfer::CacheMap::write_iterator::find ( const Fingerprint id) [inline]
const Fingerprint& Sirikata::Transfer::CacheMap::write_iterator::getId ( ) const [inline]
Returns:
the current ID (does not check validity)

Referenced by erase(), eraseAll(), update(), and use().

PolicyData Sirikata::Transfer::CacheMap::write_iterator::getPolicyInfo ( ) [inline]
Returns:
the CachePolicy opaque data (does not check validity)

Referenced by erase(), eraseAll(), update(), and use().

cache_usize_type Sirikata::Transfer::CacheMap::write_iterator::getSize ( ) const [inline]
Returns:
the stored space usage of this item.

Referenced by erase(), eraseAll(), update(), and use().

bool Sirikata::Transfer::CacheMap::write_iterator::insert ( const Fingerprint id,
cache_usize_type  size 
) [inline]

Inserts a new entry into the map, unless it already exists.

Follows the semantics of std::map::insert(id).

The iterator is guaranteed to be valid after this call.

Note:
Make sure to call update(totalSize) with the new size.
Parameters:
idThe Fingerprint to insert under (or search for).
sizeThe amount of space reserved for this entry--used only if the entry did not exist before.
Returns:
If this element was actually inserted.

References Sirikata::Transfer::CachePolicy::create(), mCachemap, mIter, mMap, and Sirikata::Transfer::CacheMap::mPolicy.

Referenced by Sirikata::Transfer::MemoryCacheLayer::populateCache(), Sirikata::Transfer::DiskCacheLayer::unserialize(), and Sirikata::Transfer::DiskCacheLayer::workerThread().

Sirikata::Transfer::CacheMap::write_iterator::operator bool ( ) const [inline]
Returns:
if this iterator can be dereferenced.

References mIter, and mMap.

CacheData& Sirikata::Transfer::CacheMap::write_iterator::operator* ( ) [inline]
Returns:
the current CacheInfo (does not check validity)
void Sirikata::Transfer::CacheMap::write_iterator::update ( cache_usize_type  newSize) [inline]

Calls use(), and updates the size of this element.

This function has no other effect if the size is unchanged.

Parameters:
newSizeThe new total size of this element.

References getId(), getPolicyInfo(), getSize(), mCachemap, Sirikata::Transfer::CacheMap::mPolicy, and Sirikata::Transfer::CachePolicy::useAndUpdate().

Referenced by Sirikata::Transfer::MemoryCacheLayer::populateCache(), and Sirikata::Transfer::DiskCacheLayer::workerThread().

void Sirikata::Transfer::CacheMap::write_iterator::use ( ) [inline]

Member Data Documentation

Referenced by erase(), eraseAll(), insert(), update(), and use().

boost::unique_lock<boost::shared_mutex> Sirikata::Transfer::CacheMap::write_iterator::mLock [private]

The documentation for this class was generated from the following file: