libpgf
6.11.42
PGF - Progressive Graphics File
|
00001 /* 00002 * The Progressive Graphics File; http://www.libpgf.org 00003 * 00004 * $Date: 2007-06-11 10:56:17 +0200 (Mo, 11 Jun 2007) $ 00005 * $Revision: 299 $ 00006 * 00007 * This file Copyright (C) 2006 xeraina GmbH, Switzerland 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE 00011 * as published by the Free Software Foundation; either version 2.1 00012 * of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 00028 00029 #ifndef PGF_STREAM_H 00030 #define PGF_STREAM_H 00031 00032 #include "PGFtypes.h" 00033 #include <new> 00034 00039 class CPGFStream { 00040 public: 00043 CPGFStream() {} 00044 00047 virtual ~CPGFStream() {} 00048 00053 virtual void Write(int *count, void *buffer)=0; 00054 00059 virtual void Read(int *count, void *buffer)=0; 00060 00065 virtual void SetPos(short posMode, INT64 posOff)=0; 00066 00070 virtual UINT64 GetPos() const=0; 00071 00075 virtual bool IsValid() const=0; 00076 }; 00077 00082 class CPGFFileStream : public CPGFStream { 00083 protected: 00084 HANDLE m_hFile; 00085 00086 public: 00087 CPGFFileStream() : m_hFile(0) {} 00090 CPGFFileStream(HANDLE hFile) : m_hFile(hFile) {} 00092 HANDLE GetHandle() { return m_hFile; } 00093 00094 virtual ~CPGFFileStream() { m_hFile = 0; } 00095 virtual void Write(int *count, void *buffer) THROW_; // throws IOException 00096 virtual void Read(int *count, void *buffer) THROW_; // throws IOException 00097 virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException 00098 virtual UINT64 GetPos() const THROW_; // throws IOException 00099 virtual bool IsValid() const { return m_hFile != 0; } 00100 }; 00101 00106 class CPGFMemoryStream : public CPGFStream { 00107 protected: 00108 UINT8 *m_buffer, *m_pos; 00109 UINT8 *m_eos; 00110 size_t m_size; 00111 bool m_allocated; 00112 00113 public: 00116 CPGFMemoryStream(size_t size) THROW_; 00120 CPGFMemoryStream(UINT8 *pBuffer, size_t size) THROW_; 00124 void Reinitialize(UINT8 *pBuffer, size_t size) THROW_; 00125 00126 virtual ~CPGFMemoryStream() { 00127 m_pos = 0; 00128 if (m_allocated) { 00129 // the memory buffer has been allocated inside of CPMFmemoryStream constructor 00130 delete[] m_buffer; m_buffer = 0; 00131 } 00132 } 00133 00134 virtual void Write(int *count, void *buffer) THROW_; // throws IOException 00135 virtual void Read(int *count, void *buffer); 00136 virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException 00137 virtual UINT64 GetPos() const { ASSERT(IsValid()); return m_pos - m_buffer; } 00138 virtual bool IsValid() const { return m_buffer != 0; } 00139 00141 size_t GetSize() const { return m_size; } 00143 const UINT8* GetBuffer() const { return m_buffer; } 00145 UINT8* GetBuffer() { return m_buffer; } 00147 UINT64 GetEOS() const { ASSERT(IsValid()); return m_eos - m_buffer; } 00149 void SetEOS(UINT64 length) { ASSERT(IsValid()); m_eos = m_buffer + length; } 00150 }; 00151 00156 #ifdef _MFC_VER 00157 class CPGFMemFileStream : public CPGFStream { 00158 protected: 00159 CMemFile *m_memFile; 00160 public: 00161 CPGFMemFileStream(CMemFile *memFile) : m_memFile(memFile) {} 00162 virtual bool IsValid() const { return m_memFile != NULL; } 00163 virtual ~CPGFMemFileStream() {} 00164 virtual void Write(int *count, void *buffer) THROW_; // throws IOException 00165 virtual void Read(int *count, void *buffer) THROW_; // throws IOException 00166 virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException 00167 virtual UINT64 GetPos() const THROW_; // throws IOException 00168 }; 00169 #endif 00170 00175 #if defined(WIN32) || defined(WINCE) 00176 class CPGFIStream : public CPGFStream { 00177 protected: 00178 IStream *m_stream; 00179 public: 00180 CPGFIStream(IStream *stream) : m_stream(stream) {} 00181 virtual bool IsValid() const { return m_stream != 0; } 00182 virtual ~CPGFIStream() {} 00183 virtual void Write(int *count, void *buffer) THROW_; // throws IOException 00184 virtual void Read(int *count, void *buffer) THROW_; // throws IOException 00185 virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException 00186 virtual UINT64 GetPos() const THROW_; // throws IOException 00187 IStream* GetIStream() const { return m_stream; } 00188 }; 00189 #endif 00190 00191 #endif // PGF_STREAM_H