Subversion Repositories Scribus

Rev

Rev 16775 | Rev 19721 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16775 fschmid 1
/*
2
 * The Progressive Graphics File; http://www.libpgf.org
3
 *
4
 * $Date: 2007-06-11 10:56:17 +0200 (Mo, 11 Jun 2007) $
5
 * $Revision: 299 $
6
 *
7
 * This file Copyright (C) 2006 xeraina GmbH, Switzerland
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
11
 * as published by the Free Software Foundation; either version 2.1
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
18122 mrdocs 21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16775 fschmid 22
 */
23
 
24
//////////////////////////////////////////////////////////////////////
25
/// @file PGFstream.h
26
/// @brief PGF stream class
27
/// @author C. Stamm
28
 
29
#ifndef PGF_STREAM_H
30
#define PGF_STREAM_H
31
 
32
#include "PGFtypes.h"
33
 
34
/////////////////////////////////////////////////////////////////////
35
/// Abstract stream base class.
36
/// @author C. Stamm
37
/// @brief Abstract stream base class
38
class CPGFStream {
39
public:
40
        //////////////////////////////////////////////////////////////////////
41
        /// Standard constructor.
42
        CPGFStream() {}
43
 
44
        //////////////////////////////////////////////////////////////////////
45
        /// Standard destructor.
46
        virtual ~CPGFStream() {}
47
 
48
        //////////////////////////////////////////////////////////////////////
49
        /// Write some bytes out of a buffer into this stream.
50
        /// @param count A pointer to a value containing the number of bytes should be written. After this call it contains the number of written bytes.
51
        /// @param buffer A memory buffer
52
        virtual void Write(int *count, void *buffer)=0;
53
 
54
        //////////////////////////////////////////////////////////////////////
55
        /// Read some bytes from this stream and stores them into a buffer.
56
        /// @param count A pointer to a value containing the number of bytes should be read. After this call it contains the number of read bytes.
57
        /// @param buffer A memory buffer
58
        virtual void Read(int *count, void *buffer)=0;
59
 
60
        //////////////////////////////////////////////////////////////////////
61
        /// Set stream position either absolute or relative.
62
        /// @param posMode A position mode (FSFromStart, FSFromCurrent, FSFromEnd)
63
        /// @param posOff A new stream position (absolute positioning) or a position offset (relative positioning)
64
        virtual void SetPos(short posMode, INT64 posOff)=0;
65
 
66
        //////////////////////////////////////////////////////////////////////
67
        /// Get current stream position.
68
        /// @return Current stream position
69
        virtual UINT64 GetPos() const=0;
70
 
71
        //////////////////////////////////////////////////////////////////////
72
        /// Check stream validity.
73
        /// @return True if stream and current position is valid
74
        virtual bool IsValid() const=0;
75
};
76
 
77
/////////////////////////////////////////////////////////////////////
78
/// A PGF stream subclass for external storage files.
79
/// @author C. Stamm
80
/// @brief File stream class
81
class CPGFFileStream : public CPGFStream {
82
protected:
83
        HANDLE m_hFile;
84
 
85
public:
86
        CPGFFileStream() : m_hFile(0) {}
87
        /// Constructor
88
        /// @param hFile File handle
89
        CPGFFileStream(HANDLE hFile) : m_hFile(hFile) {}
90
        /// @return File handle
91
        HANDLE GetHandle() { return m_hFile; }
92
 
93
        virtual ~CPGFFileStream() { m_hFile = 0; }
94
        virtual void Write(int *count, void *buffer) THROW_; // throws IOException
95
        virtual void Read(int *count, void *buffer) THROW_; // throws IOException
96
        virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException
97
        virtual UINT64 GetPos() const THROW_; // throws IOException
98
        virtual bool   IsValid() const  { return m_hFile != 0; }
99
};
100
 
101
/////////////////////////////////////////////////////////////////////
102
/// A PGF stream subclass for internal memory.
103
/// @author C. Stamm
104
/// @brief Memory stream class
105
class CPGFMemoryStream : public CPGFStream {
106
protected:
107
        UINT8 *m_buffer, *m_pos; // buffer start address and current buffer address
108
        size_t m_size; // buffer size
109
        bool   m_allocated; // indicates a new allocated buffer
110
 
111
public:
112
        /// Constructor
113
        /// @param size Size of new allocated memory buffer
114
        CPGFMemoryStream(size_t size) THROW_;
115
        /// Constructor. Use already allocated memory of given size
116
        /// @param pBuffer Memory location
117
        /// @param size Memory size
118
        CPGFMemoryStream(UINT8 *pBuffer, size_t size) THROW_;
119
        /// Constructor. Use already allocated memory of given size
120
        /// @param pBuffer Memory location
121
        /// @param size Memory size
122
        void Reinitialize(UINT8 *pBuffer, size_t size) THROW_;
123
 
124
        virtual ~CPGFMemoryStream() {
125
                m_pos = 0;
126
                if (m_allocated) {
127
                        // the memory buffer has been allocated inside of CPGFMemoryStream constructor
128
                        delete[] m_buffer; m_buffer = 0;
129
                }
130
        }
131
 
132
        virtual void Write(int *count, void *buffer) THROW_; // throws IOException
133
        virtual void Read(int *count, void *buffer) THROW_; // throws IOException
134
        virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException
135
        virtual UINT64 GetPos() const THROW_; // throws IOException
136
        virtual bool   IsValid() const  { return m_buffer != 0; }
137
 
138
        /// @return Memory size
139
        size_t GetSize() const                  { return m_size; }
140
        /// @return Memory buffer
141
        const UINT8* GetBuffer() const  { return m_buffer; }
142
        /// @return Memory buffer
143
        UINT8* GetBuffer()                              { return m_buffer; }
144
};
145
 
146
/////////////////////////////////////////////////////////////////////
147
/// A PGF stream subclass for internal memory files. Usable only with MFC.
148
/// @author C. Stamm
149
/// @brief Cached memory file stream class
150
#ifdef _MFC_VER
151
class CPGFMemFileStream : public CPGFStream {
152
protected:
153
        CMemFile *m_memFile;
154
public:
155
        CPGFMemFileStream(CMemFile *memFile) : m_memFile(memFile) {}
156
        virtual bool    IsValid() const { return m_memFile != NULL; }
157
        virtual ~CPGFMemFileStream() {}
158
        virtual void Write(int *count, void *buffer) THROW_; // throws IOException
159
        virtual void Read(int *count, void *buffer) THROW_; // throws IOException
160
        virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException
161
        virtual UINT64 GetPos() const THROW_; // throws IOException
162
};
163
#endif
164
 
165
/////////////////////////////////////////////////////////////////////
166
/// A PGF stream subclass for IStream. Usable only with COM.
167
/// @author C. Stamm
168
/// @brief COM IStream class
169
#if defined(WIN32) || defined(WINCE)
170
class CPGFIStream : public CPGFStream {
171
protected:
172
        IStream *m_stream;
173
public:
174
        CPGFIStream(IStream *stream) : m_stream(stream) {}
175
        virtual bool IsValid() const    { return m_stream != 0; }
176
        virtual ~CPGFIStream() {}
177
        virtual void Write(int *count, void *buffer) THROW_; // throws IOException
178
        virtual void Read(int *count, void *buffer) THROW_; // throws IOException
179
        virtual void SetPos(short posMode, INT64 posOff) THROW_; // throws IOException
180
        virtual UINT64 GetPos() const THROW_; // throws IOException
181
        IStream* GetIStream() const             { return m_stream; }
182
};
183
#endif
184
 
185
#endif // PGF_STREAM_H