Ptex: PtexCache Class Reference

Ptex

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
PtexCache Class Referenceabstract

File-handle and memory cache for reading ptex files. More...

`#include <Ptexture.h>`

Inheritance diagram for PtexCache:

## Public Member Functions
virtual void | release ()=0
| Release resources held by this pointer (pointer becomes invalid). More...
virtual void | setSearchPath (const char *path)=0
| Set a search path for finding textures. More...
virtual const char * | getSearchPath ()=0
| Query the search path. More...
virtual PtexTexture * | get (const char *path, Ptex::String &error)=0
| Open a texture. More...
virtual void | purge (PtexTexture *texture)=0
| Remove a texture file from the cache. More...
virtual void | purge (const char *path)=0
| Remove a texture file from the cache by pathname. More...
virtual void | purgeAll ()=0
| Remove all texture files from the cache. More...

## Static Public Member Functions
static PtexCache * | create (int maxFiles=0, int maxMem=0, bool premultiply=false, PtexInputHandler *handler=0)
| Create a cache with the specified limits. More...

## Protected Member Functions
virtual | ~PtexCache ()
| Destructor not for public use. Use release() instead. More...

## Detailed Description

File-handle and memory cache for reading ptex files.

The PtexCache class allows cached read access to multiple ptex files while constraining the open file count and memory usage to specified limits. File and data objects accessed via the cache are added back to the cache when their release method is called. Released objects are maintained in an LRU list and only destroyed when the specified resource limits are exceeded.

The cache is fully multi-threaded. Cached data will be shared among all threads that have access to the cache, and the data are protected with internal locks. See PtexCache.cpp for details about the caching and locking implementation.

Definition at line 634 of file Ptexture.h.

## Constructor & Destructor Documentation

virtual PtexCache::~PtexCache | ( |  | ) |
| inlineprotectedvirtual

Destructor not for public use. Use release() instead.

Definition at line 637 of file Ptexture.h.

## Member Function Documentation

PtexCache * PtexCache::create | ( | int | maxFiles = `0`,
|  | int | maxMem = `0`,
|  | bool | premultiply = `false`,
|  | PtexInputHandler * | handler = `0`
| ) |  |
| static

Create a cache with the specified limits.

Parameters

  maxFiles | Maximum open file handles. If unspecified, limit is set to 100 open files.
  maxMem | Maximum allocated memory, in bytes. If unspecified, limit is set to 100MB.
  premultiply | If true, textures will be premultiplied by the alpha channel (if any) when read from disk. See PtexTexture and PtexWriter for more details.
  handler | If specified, all input calls made through this cache will be directed through the handler.

Definition at line 410 of file PtexCache.cpp.

Referenced by PtexTexture::open().

virtual PtexTexture* PtexCache::get | ( | const char * | path,
|  | Ptex::String & | error
| ) |  |
| pure 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

  path | File path. If path is relative, search path will be used to find the file.
  error | Error string set if texture could not be opened.

Implemented in PtexReaderCache.

Referenced by PtexTexture::open().

virtual const char* PtexCache::getSearchPath | ( |  | ) |
| pure virtual

Query the search path.

Returns string set via setSearchPath.

Implemented in PtexReaderCache.

virtual void PtexCache::purge | ( | PtexTexture * | texture | ) |
| pure virtual

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.

Implemented in PtexReaderCache.

virtual void PtexCache::purge | ( | const char * | path | ) |
| pure virtual

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.

Implemented in PtexReaderCache.

virtual void PtexCache::purgeAll | ( |  | ) |
| pure virtual

Remove all texture files from the cache.

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

Implemented in PtexReaderCache.

Referenced by PtexTexture::open().

virtual void PtexCache::release | ( |  | ) |
| pure virtual

Release resources held by this pointer (pointer becomes invalid).

Implemented in PtexCacheImpl.

virtual void PtexCache::setSearchPath | ( | const char * | path | ) |
| pure virtual

Set a search path for finding textures.

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

Parameters

  path | colon-delimited search path.

Implemented in PtexReaderCache.

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

- Ptexture.h
- PtexCache.cpp