108 #include <sys/types.h> 
  109 #include <sys/stat.h> 
  119     CacheStats::~CacheStats() { 
 
  120         if (getenv(
"PTEX_STATS"))
 
  124     void CacheStats::print()
 
  126         if (nfilesOpened || ndataAllocated || nblocksRead) {
 
  127             printf(
"Ptex Stats:\n");
 
  128             printf(
"  nfilesOpened:   %6d\n", nfilesOpened);
 
  129             printf(
"  nfilesClosed:   %6d\n", nfilesClosed);
 
  130             printf(
"  ndataAllocated: %6d\n", ndataAllocated);
 
  131             printf(
"  ndataFreed:     %6d\n", ndataFreed);
 
  132             printf(
"  nblocksRead:    %6d\n", nblocksRead);
 
  133             printf(
"  nseeks:         %6d\n", nseeks);
 
  135                 printf(
"  avgReadSize:    %6d\n", 
int(nbytesRead/nblocksRead));
 
  137                 printf(
"  avgSeqReadSize: %6d\n", 
int(nbytesRead/nseeks));
 
  138             printf(
"  MbytesRead:     %6.2f\n", nbytesRead/(1024.0*1024.0));
 
  228             const char* cp = path;
 
  230                 const char* delim = strchr(cp, 
':');
 
  235                 int len = int(delim-cp);
 
  236                 if (len) 
_searchdirs.push_back(std::string(cp, len));
 
  261     virtual void purge(
const char* filename)
 
  267             if (reader && intptr_t(reader) != -1) {
 
  281             if (reader && intptr_t(reader) != -1) {
 
  319         if (intptr_t(reader) == -1) 
return 0;
 
  337             if (intptr_t(*entry) == -1) 
return 0;
 
  348         const char* pathToOpen = filename;
 
  350             bool isAbsolute = (filename[0] == 
'/' 
  352                                || filename[0] == 
'\\' 
  353                                || (isalpha(filename[0]) && filename[1] == 
':')
 
  358                 tmppath.reserve(256); 
 
  361                 for (
size_t i = 0, size = 
_searchdirs.size(); i < size; i++) {
 
  365                     if (stat(tmppath.c_str(), &statbuf) == 0) {
 
  367                         pathToOpen = tmppath.c_str();
 
  372                     std::string errstr = 
"Can't find ptex file: ";
 
  374                     error = errstr.
c_str();
 
  379         if (ok) ok = reader->
open(pathToOpen, error);
 
  414     if (maxFiles <= 0) maxFiles = 100;
 
  417     const int MB = 1024*1024;
 
  418     if (maxMem <= 0) maxMem = 100 * MB;
 
  421     if (maxMem < 1 * MB) {
 
  422         std::cerr << 
"Warning, PtexCache created with < 1 MB" << std::endl;
 
virtual PtexTexture * get(const char *path, Ptex::String &error)
Open a texture. 
void setDataInUse(PtexLruItem *data, int size)
PtexReaderCache(int maxFiles, int maxMem, bool premultiply, PtexInputHandler *handler)
bool erase(const char *key)
Will remove an entry. It will return TRUE if an entry was found. 
iterator end()
Returns an iterator referencing the end of the table. 
File-handle and memory cache for reading ptex files. 
virtual void setSearchPath(const char *path)
Set a search path for finding textures. 
virtual const char * path()
Path that file was opened with. 
virtual void purge(const char *filename)
Remove a texture file from the cache by pathname. 
iterator begin()
Returns an iterator referencing the beginning of the table. 
static PtexCache * create(int maxFiles=0, int maxMem=0, bool premultiply=false, PtexInputHandler *handler=0)
Create a cache with the specified limits. 
virtual const char * getSearchPath()
Query the search path. 
void setFileUnused(PtexLruItem *file)
void removeData(int size)
std::vector< std::string > _searchdirs
void push(PtexLruItem *node)
void setDataUnused(PtexLruItem *data, int size)
virtual void purgeAll()
Remove all texture files from the cache. 
iterator find(const char *key)
Locates an entry, without creating a new one. 
One item in a cache, typically an open file or a block of memory. 
Cache for reading Ptex texture files. 
void setFileInUse(PtexLruItem *file)
void removeBlankEntries()
Interface for reading data from a ptex file. 
virtual void purge(PtexTexture *texture)
Remove a texture file from the cache. 
bool open(const char *path, Ptex::String &error)
Ptex cache implementation. 
Automatically acquire and release lock within enclosing scope. 
friend class iterator
forward declared class 
const char * c_str() const 
PtexDict< PtexReader * > FileMap
Public API classes for reading, writing, caching, and filtering Ptex files. 
void extract(PtexLruItem *node)