00001 #ifndef __vtkExodusIICache_h
00002 #define __vtkExodusIICache_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "vtkObject.h"
00027
00028 #include <vtkstd/map>
00029 #include <vtkstd/list>
00030
00031
00032 class VTK_HYBRID_EXPORT vtkExodusIICacheKey
00033 {
00034 public:
00035 int Time;
00036 int ObjectType;
00037 int ObjectId;
00038 int ArrayId;
00039 vtkExodusIICacheKey()
00040 {
00041 Time = -1;
00042 ObjectType = -1;
00043 ObjectId = -1;
00044 ArrayId = -1;
00045 }
00046 vtkExodusIICacheKey( int time, int objType, int objId, int arrId )
00047 {
00048 Time = time;
00049 ObjectType = objType;
00050 ObjectId = objId;
00051 ArrayId = arrId;
00052 }
00053 vtkExodusIICacheKey( const vtkExodusIICacheKey& src )
00054 {
00055 Time = src.Time;
00056 ObjectType = src.ObjectType;
00057 ObjectId = src.ObjectId;
00058 ArrayId = src.ArrayId;
00059 }
00060 bool match( const vtkExodusIICacheKey&other, const vtkExodusIICacheKey& pattern ) const
00061 {
00062 if ( pattern.Time && this->Time != other.Time )
00063 return false;
00064 if ( pattern.ObjectType && this->ObjectType != other.ObjectType )
00065 return false;
00066 if ( pattern.ObjectId && this->ObjectId != other.ObjectId )
00067 return false;
00068 if ( pattern.ArrayId && this->ArrayId != other.ArrayId )
00069 return false;
00070 return true;
00071 }
00072 bool operator < ( const vtkExodusIICacheKey& other ) const
00073 {
00074 if ( this->Time < other.Time )
00075 return true;
00076 else if ( this->Time > other.Time )
00077 return false;
00078 if ( this->ObjectType < other.ObjectType )
00079 return true;
00080 else if ( this->ObjectType > other.ObjectType )
00081 return false;
00082 if ( this->ObjectId < other.ObjectId )
00083 return true;
00084 else if ( this->ObjectId > other.ObjectId )
00085 return false;
00086 if ( this->ArrayId < other.ArrayId )
00087 return true;
00088 return false;
00089 }
00090 };
00091
00092 class vtkExodusIICacheEntry;
00093 class vtkExodusIICache;
00094 class vtkDataArray;
00095
00096 typedef vtkstd::map<vtkExodusIICacheKey,vtkExodusIICacheEntry*> vtkExodusIICacheSet;
00097 typedef vtkstd::map<vtkExodusIICacheKey,vtkExodusIICacheEntry*>::iterator vtkExodusIICacheRef;
00098 typedef vtkstd::list<vtkExodusIICacheRef> vtkExodusIICacheLRU;
00099 typedef vtkstd::list<vtkExodusIICacheRef>::iterator vtkExodusIICacheLRURef;
00100
00101 class VTK_HYBRID_EXPORT vtkExodusIICacheEntry
00102 {
00103 public:
00104 vtkExodusIICacheEntry();
00105 vtkExodusIICacheEntry( vtkDataArray* arr );
00106 vtkExodusIICacheEntry( const vtkExodusIICacheEntry& other );
00107
00108 ~vtkExodusIICacheEntry();
00109
00110 vtkDataArray* GetValue() { return this->Value; }
00111
00112 protected:
00113 vtkDataArray* Value;
00114 vtkExodusIICacheLRURef LRUEntry;
00115
00116 friend class vtkExodusIICache;
00117 };
00118
00119
00120 class VTK_HYBRID_EXPORT vtkExodusIICache : public vtkObject
00121 {
00122 public:
00123 static vtkExodusIICache* New();
00124 vtkTypeMacro(vtkExodusIICache,vtkObject);
00125 void PrintSelf( ostream& os, vtkIndent indent );
00126
00128 void Clear();
00129
00131 void SetCacheCapacity( double sizeInMiB );
00132
00137 double GetSpaceLeft()
00138 { return this->Capacity - this->Size; }
00139
00143 int ReduceToSize( double newSize );
00144
00145
00147 void Insert( vtkExodusIICacheKey& key, vtkDataArray* value );
00148
00152 vtkDataArray*& Find( vtkExodusIICacheKey );
00153
00158 int Invalidate( vtkExodusIICacheKey key );
00159
00169 int Invalidate( vtkExodusIICacheKey key, vtkExodusIICacheKey pattern );
00170
00171
00172 protected:
00174 vtkExodusIICache();
00175
00177 ~vtkExodusIICache();
00178
00179
00181 void RecomputeSize();
00182
00184 double Capacity;
00185
00187 double Size;
00188
00189
00196 vtkExodusIICacheSet Cache;
00197
00199 vtkExodusIICacheLRU LRU;
00200
00201
00202 private:
00203 vtkExodusIICache( const vtkExodusIICache& );
00204 void operator = ( const vtkExodusIICache& );
00205 };
00206 #endif // __vtkExodusIICache_h