00001 //---------------------------------------------------------------------------- 00002 // 00003 // cel_storagecache.h - Storage Cache implementation 00004 // 00005 // (C) 2003-2006 Celartem Technology Inc. All rights reserved. 00006 // 00007 //---------------------------------------------------------------------------- 00008 #ifndef _cel_storagecache_h_ 00009 #define _cel_storagecache_h_ 00010 00011 #include "cel_storage.h" 00012 00013 namespace Celartem 00014 { 00015 //------------------------------------------------------------------------ 00019 template<typename T> struct Range 00020 { 00021 T offset; 00022 T length; 00023 00027 Range(const T& _offset = 0, const T& _length = 0) 00028 : offset(_offset), length(_length) 00029 { 00030 } 00031 00039 T end() const {return offset + length;} 00040 00048 bool contains(const Range<T>& r) const 00049 { 00050 if(r.offset < offset || r.end() > end()) 00051 return false; 00052 return true; 00053 } 00054 00064 bool contains(uint64_t inPos, size_t inSize) const 00065 { 00066 if(inPos < offset || inPos + inSize > end()) 00067 return false; 00068 return true; 00069 } 00070 00078 bool contains(uint64_t inPos) const 00079 { 00080 if(inPos < offset || inPos >= end()) 00081 return false; 00082 return true; 00083 } 00084 00091 void merge(const Range& inRange) 00092 { 00093 length = inRange.end() - offset; 00094 } 00095 }; 00096 00097 //------------------------------------------------------------------------ 00102 typedef Range<uint64_t> StorageRange; 00103 00104 //------------------------------------------------------------------------ 00109 class StorageLoader : public Referable 00110 { 00111 public: 00124 virtual StorageRange load( 00125 Storage* inStorage, 00126 uint64_t inPos, 00127 size_t inSize) = 0; 00128 00136 virtual uint64_t getSize() const = 0; 00137 00143 virtual String getStorageId() const = 0; 00144 00150 virtual Time getLastUpdateTime() const = 0; 00151 00157 virtual AutoPtr<StorageLoader> duplicate() const = 0; 00158 00165 virtual void setBufferingSize(size_t inSize = 1024) = 0; 00166 00175 virtual void setCallback( 00176 DuplicateStreamCallback inCallback, 00177 void* inContext) = 0; 00178 }; 00179 00180 //------------------------------------------------------------------------ 00185 class AdvCachedStorage : public Storage 00186 { 00187 public: 00196 static AutoPtr<AdvCachedStorage> create(StorageLoader* inLoader); 00197 00204 virtual void setBufferingSize(size_t inSize = 1024) = 0; 00205 00214 virtual void setCallback( 00215 DuplicateStreamCallback inCallback, 00216 void* inContext) = 0; 00217 }; 00218 } 00219 00220 #endif // _cel_storagecache_h_