2 Copyright (c) 2001, Loki software, inc.
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
8 Redistributions of source code must retain the above copyright notice, this list
9 of conditions and the following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this
12 list of conditions and the following disclaimer in the documentation and/or
13 other materials provided with the distribution.
15 Neither the name of Loki software nor the names of its contributors may be used
16 to endorse or promote products derived from this software without specific prior
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
23 DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ////////////////////////////////////////////////////
35 #if !defined(INCLUDED_PROFILE_FILE_H)
36 #define INCLUDED_PROFILE_FILE_H
38 #include "idatastream.h"
43 Based on an initial implementation by Loki software
44 modified to be abstracted and shared across modules
46 NOTE: why IDataStream and not IStream? because IStream is defined in windows IDL headers
49 class IDataStream : public InputStream, public OutputStream
52 typedef int offset_type;
53 typedef std::size_t position_type;
55 virtual void IncRef() = 0; ///< Increment the number of references to this object
56 virtual void DecRef() = 0; ///< Decrement the reference count
58 virtual position_type GetPosition() const = 0;
59 virtual int Seek(offset_type lOff, int nFrom) = 0;
61 virtual void SetLength(size_type nNewLen) = 0;
62 virtual size_type GetLength() const = 0;
64 virtual char* ReadString(char* pBuf, size_type nMax) = 0;
65 virtual int GetChar()=0;
67 virtual int PutChar(int c)=0;
68 virtual void printf(const char*, ...) = 0; ///< completely matches the usual printf behaviour
70 virtual void Abort() = 0;
71 virtual void Flush() = 0;
72 virtual void Close() = 0;
77 class MemStream : public IDataStream
81 MemStream(size_type nLen);
85 void IncRef() { refCount++; }
86 void DecRef() { refCount--; if (refCount <= 0) delete this; }
90 size_type m_nGrowBytes;
91 size_type m_nPosition;
92 size_type m_nBufferSize;
93 size_type m_nFileSize;
94 unsigned char* m_pBuffer;
96 void GrowFile(size_type nNewLen);
99 position_type GetPosition() const;
100 int Seek(offset_type lOff, int nFrom);
101 void SetLength(size_type nNewLen);
102 size_type GetLength() const;
104 unsigned char* GetBuffer() const
105 { return m_pBuffer; }
107 size_type read(byte_type* buffer, size_type length);
108 size_type write(const byte_type* buffer, size_type length);
110 char* ReadString(char* pBuf, size_type nMax);
114 void printf(const char*, ...); ///< \todo implement on MemStream
119 bool Open(const char *filename, const char *mode);
122 class FileStream : public IDataStream
126 virtual ~FileStream();
129 void IncRef() { refCount++; }
130 void DecRef() { refCount--; if (refCount <= 0) delete this; }
133 // DiscFile specific:
135 bool m_bCloseOnDelete;
138 position_type GetPosition() const;
139 int Seek(offset_type lOff, int nFrom);
140 void SetLength(size_type nNewLen);
141 size_type GetLength() const;
143 size_type read(byte_type* buffer, size_type length);
144 size_type write(const byte_type* buffer, size_type length);
146 char* ReadString(char* pBuf, size_type nMax);
150 void printf(const char*, ...); ///< completely matches the usual printf behaviour
155 bool Open(const char *filename, const char *mode);