Ptex
Public Member Functions | Private Types | Private Attributes | List of all members
PtexReaderCache Class Reference

Cache for reading Ptex texture files. More...

Inheritance diagram for PtexReaderCache:
PtexCacheImpl PtexCache

Public Member Functions

 PtexReaderCache (int maxFiles, int maxMem, bool premultiply, PtexInputHandler *handler)
 
 ~PtexReaderCache ()
 
virtual void setSearchPath (const char *path)
 Set a search path for finding textures. More...
 
virtual const char * getSearchPath ()
 Query the search path. More...
 
virtual PtexTextureget (const char *path, Ptex::String &error)
 Open a texture. More...
 
virtual void purge (PtexTexture *texture)
 Remove a texture file from the cache. More...
 
virtual void purge (const char *filename)
 Remove a texture file from the cache by pathname. More...
 
virtual void purgeAll ()
 Remove all texture files from the cache. More...
 
void removeBlankEntries ()
 
- Public Member Functions inherited from PtexCacheImpl
 PtexCacheImpl (int maxFiles, int maxMem)
 
virtual void release ()
 Release resources held by this pointer (pointer becomes invalid). More...
 
void setPendingDelete ()
 
void handlePendingDelete ()
 
void setFileInUse (PtexLruItem *file)
 
void setFileUnused (PtexLruItem *file)
 
void removeFile ()
 
void setDataInUse (PtexLruItem *data, int size)
 
void setDataUnused (PtexLruItem *data, int size)
 
void removeData (int size)
 
void purgeFiles ()
 
void purgeData ()
 

Private Types

typedef PtexDict< PtexReader * > FileMap
 

Private Attributes

PtexInputHandler_io
 
std::string _searchpath
 
std::vector< std::string > _searchdirs
 
FileMap _files
 
int _cleanupCount
 
bool _premultiply
 

Additional Inherited Members

- Static Public Member Functions inherited from PtexCacheImpl
static void addFile ()
 
static void addData ()
 
- Static Public Member Functions inherited from PtexCache
static PtexCachecreate (int maxFiles=0, int maxMem=0, bool premultiply=false, PtexInputHandler *handler=0)
 Create a cache with the specified limits. More...
 
- Public Attributes inherited from PtexCacheImpl
Mutex openlock
 
CacheLock cachelock
 
- Protected Member Functions inherited from PtexCacheImpl
 ~PtexCacheImpl ()
 
- Protected Member Functions inherited from PtexCache
virtual ~PtexCache ()
 Destructor not for public use. Use release() instead. More...
 

Detailed Description

Cache for reading Ptex texture files.

Definition at line 201 of file PtexCache.cpp.

Member Typedef Documentation

Definition at line 304 of file PtexCache.cpp.

Constructor & Destructor Documentation

PtexReaderCache::PtexReaderCache ( int  maxFiles,
int  maxMem,
bool  premultiply,
PtexInputHandler handler 
)
inline

Definition at line 204 of file PtexCache.cpp.

PtexReaderCache::~PtexReaderCache ( )
inline

Definition at line 209 of file PtexCache.cpp.

References purgeAll().

Member Function Documentation

PtexTexture * PtexReaderCache::get ( const char *  path,
Ptex::String error 
)
virtual

Open a texture.

If the specified path was previously opened, and the open file limit hasn't been exceeded, then a pointer to the already open file will be returned.

If the specified path hasn't been opened yet or was closed, either to maintain the open file limit or because the file was explicitly purged from the cache, then the file will be newly opened. If the path is relative (i.e. doesn't begin with a '/') then the search path will be used to locate the file.

The texture file will stay open until the PtexTexture::release method is called, at which point the texture will be returned to the cache. Once released, the file will be closed when either the file handle limit is reached, the cached is released, or when the texture is purged (see purge methods below).

If texture could not be opened, null will be returned and an error string will be set.

Parameters
pathFile path. If path is relative, search path will be used to find the file.
errorError string set if texture could not be opened.

Implements PtexCache.

Definition at line 311 of file PtexCache.cpp.

References _cleanupCount, _files, _io, _premultiply, _searchdirs, Ptex::String::c_str(), PtexCacheImpl::cachelock, PtexInternal::_SpinLock::lock(), PtexReader::open(), PtexCacheImpl::openlock, PtexLruItem::orphan(), PtexCacheImpl::purgeFiles(), PtexCachedFile::ref(), removeBlankEntries(), PtexInternal::_SpinLock::unlock(), and PtexCachedFile::unref().

virtual const char* PtexReaderCache::getSearchPath ( )
inlinevirtual

Query the search path.

Returns string set via setSearchPath.

Implements PtexCache.

Definition at line 242 of file PtexCache.cpp.

References _searchpath, and PtexCacheImpl::openlock.

virtual void PtexReaderCache::purge ( PtexTexture texture)
inlinevirtual

Remove a texture file from the cache.

The texture file will remain open and accessible until the file handle is released, but any future cache accesses for that file will open the file anew.

Implements PtexCache.

Definition at line 251 of file PtexCache.cpp.

References PtexReader::path().

virtual void PtexReaderCache::purge ( const char *  path)
inlinevirtual

Remove a texture file from the cache by pathname.

The path must match the full path as opened. This function will not search for the file, but if a search path was used, the path must match the path as found by the search path.

Implements PtexCache.

Definition at line 261 of file PtexCache.cpp.

References _files, PtexCacheImpl::cachelock, PtexDict< T >::end(), PtexDict< T >::erase(), PtexDict< T >::find(), PtexDict< PtexReader * >::iterator, and PtexLruItem::orphan().

virtual void PtexReaderCache::purgeAll ( )
inlinevirtual

Remove all texture files from the cache.

Open files with active PtexTexture* handles remain open until released.

Implements PtexCache.

Definition at line 275 of file PtexCache.cpp.

References _files, PtexDict< T >::begin(), PtexCacheImpl::cachelock, PtexDict< T >::end(), PtexDict< T >::erase(), PtexDict< PtexReader * >::iterator, and PtexLruItem::orphan().

Referenced by ~PtexReaderCache().

void PtexReaderCache::removeBlankEntries ( )
inline
virtual void PtexReaderCache::setSearchPath ( const char *  path)
inlinevirtual

Set a search path for finding textures.

Note: if an input handler is installed the search path will be ignored.

Parameters
pathcolon-delimited search path.

Implements PtexCache.

Definition at line 216 of file PtexCache.cpp.

References _searchdirs, _searchpath, and PtexCacheImpl::openlock.

Member Data Documentation

int PtexReaderCache::_cleanupCount
private

Definition at line 306 of file PtexCache.cpp.

Referenced by get().

FileMap PtexReaderCache::_files
private

Definition at line 305 of file PtexCache.cpp.

Referenced by get(), purge(), purgeAll(), and removeBlankEntries().

PtexInputHandler* PtexReaderCache::_io
private

Definition at line 301 of file PtexCache.cpp.

Referenced by get().

bool PtexReaderCache::_premultiply
private

Definition at line 307 of file PtexCache.cpp.

Referenced by get().

std::vector<std::string> PtexReaderCache::_searchdirs
private

Definition at line 303 of file PtexCache.cpp.

Referenced by get(), and setSearchPath().

std::string PtexReaderCache::_searchpath
private

Definition at line 302 of file PtexCache.cpp.

Referenced by getSearchPath(), and setSearchPath().


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