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++; }
87 refCount--; if ( refCount <= 0 ) {
94 size_type m_nGrowBytes;
95 size_type m_nPosition;
96 size_type m_nBufferSize;
97 size_type m_nFileSize;
98 unsigned char* m_pBuffer;
100 void GrowFile( size_type nNewLen );
103 position_type GetPosition() const;
104 int Seek( offset_type lOff, int nFrom );
105 void SetLength( size_type nNewLen );
106 size_type GetLength() const;
108 unsigned char* GetBuffer() const
109 { return m_pBuffer; }
111 size_type read( byte_type* buffer, size_type length );
112 size_type write( const byte_type* buffer, size_type length );
114 char* ReadString( char* pBuf, size_type nMax );
117 int PutChar( int c );
118 void printf( const char*, ... ); ///< \todo implement on MemStream
123 bool Open( const char *filename, const char *mode );
126 class FileStream : public IDataStream
130 virtual ~FileStream();
133 void IncRef() { refCount++; }
135 refCount--; if ( refCount <= 0 ) {
141 // DiscFile specific:
143 bool m_bCloseOnDelete;
146 position_type GetPosition() const;
147 int Seek( offset_type lOff, int nFrom );
148 void SetLength( size_type nNewLen );
149 size_type GetLength() const;
151 size_type read( byte_type* buffer, size_type length );
152 size_type write( const byte_type* buffer, size_type length );
154 char* ReadString( char* pBuf, size_type nMax );
157 int PutChar( int c );
158 void printf( const char*, ... ); ///< completely matches the usual printf behaviour
163 bool Open( const char *filename, const char *mode );