/* * Copyright (C) 2007-2013 Xagasoft, All rights reserved. * * This file is part of the libbu++ library and is released under the * terms of the license contained in the file LICENSE. */ #ifndef BU_CACHE_OBJECT_H #define BU_CACHE_OBJECT_H #ifndef NULL #define NULL 0 #endif namespace Bu { template class CacheBase; template class CacheEntry; template class CacheObject { friend class CacheBase; public: CacheObject() : pCache( NULL ), bChanged( false ) { } virtual ~CacheObject() { } typedef CacheBase CacheType; virtual keytype getKey() const=0; virtual int getPersistenceScore() const { return 0; } void lock() { pEntry->lock(); } void unlock() { pEntry->unlock(); } int getRefCount() const { return pEntry->getRefCount(); } bool hasChanged() const { return bChanged; } protected: void changed( bool bChanged=true ) { if( this->bChanged == false && bChanged == true && pCache ) pCache->objectChanged( getKey() ); this->bChanged = bChanged; } CacheType *getCache() { return pCache; } private: typedef CacheEntry Entry; void setCache( CacheType *pCache, Entry *pEntry ) { this->pCache = pCache; this->pEntry = pEntry; } private: CacheType *pCache; Entry *pEntry; bool bChanged; }; } #endif