Changeset 13848
- Timestamp:
- 02/23/08 06:50:48 (4 months ago)
- Files:
-
- trunk/gdal/frmts/mrsid/mrsidstream.cpp (modified) (11 diffs)
- trunk/gdal/frmts/mrsid/mrsidstream.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/gdal/frmts/mrsid/mrsidstream.cpp
r13827 r13848 41 41 /************************************************************************/ 42 42 43 LTIVSIStream::LTIVSIStream() : poFileHandle(NULL), nError(0) 43 LTIVSIStream::LTIVSIStream() : poFileHandle(NULL), nError(0), pnRefCount(NULL) 44 44 { 45 45 } … … 51 51 LTIVSIStream::~LTIVSIStream() 52 52 { 53 if ( poFileHandle ) 54 { 55 VSIFCloseL( (FILE *)poFileHandle ); 56 nError = errno; 53 if ( poFileHandle) 54 { 55 (*pnRefCount)--; 56 if (*pnRefCount == 0) 57 { 58 VSIFCloseL( (FILE *)poFileHandle ); 59 nError = errno; 60 delete pnRefCount; 61 } 57 62 } 58 63 } … … 65 70 const char *pszAccess ) 66 71 { 72 CPLAssert(poFileHandle == NULL); 73 67 74 poFileHandle = (VSIVirtualHandle *)VSIFOpenL( pszFilename, pszAccess ); 75 if (poFileHandle) 76 { 77 pnRefCount = new int; 78 *pnRefCount = 1; 79 } 68 80 nError = errno; 69 81 … … 75 87 /************************************************************************/ 76 88 77 LT_STATUS LTIVSIStream::initialize( VSIVirtualHandle *poFileHandle ) 78 { 79 this->poFileHandle = poFileHandle; 89 LT_STATUS LTIVSIStream::initialize( LTIVSIStream* ltiVSIStream ) 90 { 91 CPLAssert(poFileHandle == NULL); 92 93 poFileHandle = ltiVSIStream->poFileHandle; 94 if (poFileHandle) 95 { 96 pnRefCount = ltiVSIStream->pnRefCount; 97 (*pnRefCount) ++; 98 } 80 99 81 100 return poFileHandle ? LT_STS_Success : LT_STS_Failure; … … 88 107 bool LTIVSIStream::isEOF() 89 108 { 109 CPLAssert(poFileHandle); 110 90 111 bool bIsEOF = (0 != poFileHandle->Eof()); 91 112 nError = errno; … … 118 139 LT_STATUS LTIVSIStream::close() 119 140 { 141 CPLAssert(poFileHandle); 142 120 143 if ( poFileHandle->Seek( 0, SEEK_SET ) == 0 ) 121 144 return LT_STS_Success; … … 133 156 lt_uint32 LTIVSIStream::read( lt_uint8 *pDest, lt_uint32 nBytes ) 134 157 { 158 CPLAssert(poFileHandle); 159 135 160 lt_uint32 nBytesRead = 136 161 (lt_uint32)poFileHandle->Read( pDest, 1, nBytes ); … … 146 171 lt_uint32 LTIVSIStream::write( const lt_uint8 *pSrc, lt_uint32 nBytes ) 147 172 { 173 CPLAssert(poFileHandle); 174 148 175 lt_uint32 nBytesWritten = 149 176 (lt_uint32)poFileHandle->Write( pSrc, 1, nBytes ); … … 159 186 LT_STATUS LTIVSIStream::seek( lt_int64 nOffset, LTIOSeekDir nOrigin ) 160 187 { 188 CPLAssert(poFileHandle); 189 161 190 int nWhence; 162 191 switch (nOrigin) … … 193 222 lt_int64 LTIVSIStream::tell() 194 223 { 224 CPLAssert(poFileHandle); 225 195 226 lt_int64 nPos = (lt_int64)poFileHandle->Tell(); 196 227 nError = errno; … … 206 237 { 207 238 LTIVSIStream *poNew = new LTIVSIStream; 208 poNew->initialize( poFileHandle);239 poNew->initialize( this ); 209 240 210 241 return poNew; trunk/gdal/frmts/mrsid/mrsidstream.h
r13827 r13848 43 43 LTIVSIStream(); 44 44 LT_STATUS initialize( const char *, const char * ); 45 LT_STATUS initialize( VSIVirtualHandle *);45 LT_STATUS initialize( LTIVSIStream* ltiVSIStream ); 46 46 ~LTIVSIStream(); 47 47 … … 67 67 VSIVirtualHandle *poFileHandle; 68 68 int nError; 69 int *pnRefCount; 69 70 }; 70 71
