Vault
4.1
|
00001 /* 00002 Copyright c1997-2014 Trygve Isaacson. All rights reserved. 00003 This file is part of the Code Vault version 4.1 00004 http://www.bombaydigital.com/ 00005 License: MIT. See LICENSE.md in the Vault top level directory. 00006 */ 00007 00008 #ifndef vstream_h 00009 #define vstream_h 00010 00013 #include "vstring.h" 00014 00104 // Allows us to declare our static streamCopy functions here. 00105 class VIOStream; 00106 00199 class VStream { 00200 public: 00201 00205 VStream(); 00209 VStream(const VString& name); 00213 virtual ~VStream() {} 00214 00221 void readGuaranteed(Vu8* targetBuffer, Vs64 numBytesToRead); 00226 Vu8 readGuaranteedByte(); 00233 virtual Vs64 read(Vu8* targetBuffer, Vs64 numBytesToRead) = 0; 00234 00241 virtual Vs64 write(const Vu8* buffer, Vs64 numBytesToWrite) = 0; 00247 virtual void flush() = 0; 00248 00256 virtual bool skip(Vs64 numBytesToSkip) = 0; 00300 virtual bool seek(Vs64 offset, int whence) = 0; 00307 bool seek0() { return this->seek(0, SEEK_SET); } 00323 virtual Vs64 getIOOffset() const = 0; 00333 virtual Vs64 available() const = 0; 00334 00358 static Vs64 streamCopy(VStream& fromStream, VStream& toStream, Vs64 numBytesToCopy, Vs64 tempBufferSize = 16384); 00359 static Vs64 streamCopy(VIOStream& fromStream, VIOStream& toStream, Vs64 numBytesToCopy, Vs64 tempBufferSize = 16384); 00360 static Vs64 streamCopy(VIOStream& fromStream, VStream& toStream, Vs64 numBytesToCopy, Vs64 tempBufferSize = 16384); 00361 static Vs64 streamCopy(VStream& fromStream, VIOStream& toStream, Vs64 numBytesToCopy, Vs64 tempBufferSize = 16384); 00362 00363 friend class VWriteBufferedStream; 00364 00371 const VString& getName() const { return mName; } 00378 void setName(const VString& name) { mName = name; } 00379 00393 static bool needSizeConversion(Vs64 sizeValue); 00401 static void copyMemory(Vu8* toBuffer, const Vu8* fromBuffer, Vs64 numBytesToCopy); 00411 static Vu8* newNewBuffer(Vs64 bufferSize); 00416 static Vu8* mallocNewBuffer(Vs64 bufferSize); 00417 00418 protected: 00419 00420 /* 00421 These methods are ONLY overridden by buffer-based subclasses, 00422 for example VMemoryStream. They are called by the friend function 00423 streamCopy() so that it can efficiently copy data directly to/from 00424 streams that have data buffers (namely, VMemoryStream). 00425 */ 00426 00433 virtual Vu8* _getReadIOPtr() const; 00440 virtual Vu8* _getWriteIOPtr() const; 00447 virtual Vs64 _prepareToRead(Vs64 numBytesToRead) const; 00454 virtual void _prepareToWrite(Vs64 numBytesToWrite); 00460 virtual void _finishRead(Vs64 numBytesRead); 00466 virtual void _finishWrite(Vs64 numBytesWritten); 00467 00468 VString mName; 00469 }; 00470 00473 #endif /* vstream_h */