svn-gvsig-desktop / trunk / libraries / libjni-mrsid / sdk / include / support / lt_ioFile64Stream.h @ 20023
History | View | Annotate | Download (6.25 KB)
1 |
/* $Id: lt_ioFile64Stream.h 3539 2006-01-09 12:23:20Z nacho $ */
|
---|---|
2 |
/* //////////////////////////////////////////////////////////////////////////
|
3 |
// //
|
4 |
// This code is Copyright (c) 2004 LizardTech, Inc, 1008 Western Avenue, //
|
5 |
// Suite 200, Seattle, WA 98104. Unauthorized use or distribution //
|
6 |
// prohibited. Access to and use of this code is permitted only under //
|
7 |
// license from LizardTech, Inc. Portions of the code are protected by //
|
8 |
// US and foreign patents and other filings. All Rights Reserved. //
|
9 |
// //
|
10 |
////////////////////////////////////////////////////////////////////////// */
|
11 |
/* PUBLIC */
|
12 |
|
13 |
#ifndef LT_IOFILE64STREAM_H
|
14 |
#define LT_IOFILE64STREAM_H
|
15 |
|
16 |
#include "lt_ioStreamInf.h" |
17 |
#include "lt_fileSpec.h" |
18 |
|
19 |
#if defined(LT_OS_WIN)
|
20 |
#include <Windows.h> |
21 |
#elif defined(LT_OS_SUNOS) || defined(LT_OS_LINUX) || defined(LT_OS_DARWIN)
|
22 |
#include <stdio.h> |
23 |
#else
|
24 |
#error Platform not yet supported.
|
25 |
#endif
|
26 |
|
27 |
|
28 |
LT_BEGIN_NAMESPACE( LizardTech ) |
29 |
|
30 |
/**
|
31 |
* File stream for large files
|
32 |
*
|
33 |
* This class implements a file-based stream. It works correctly for large
|
34 |
* files (greater than 2GB), although on some systems performance may be less
|
35 |
* than the normal file stream (LTFileStream).
|
36 |
*/
|
37 |
class LTIOFile64Stream : public LTIOStreamInf |
38 |
{ |
39 |
public:
|
40 |
/**
|
41 |
* @name Construction, destruction, initialization
|
42 |
*/
|
43 |
//@{
|
44 |
|
45 |
/**
|
46 |
* Default Constructor
|
47 |
*/
|
48 |
LTIOFile64Stream(); |
49 |
|
50 |
/**
|
51 |
* Destructor
|
52 |
*/
|
53 |
virtual ~LTIOFile64Stream(); |
54 |
|
55 |
/**
|
56 |
* Initializes the stream
|
57 |
*
|
58 |
* @param path A LTFileSpec to the file
|
59 |
* @param mode mode (see stdio.h)
|
60 |
*/
|
61 |
virtual LT_STATUS initialize( const LTFileSpec &path, const char* mode ); |
62 |
virtual LT_STATUS initialize( const char *path, const char* mode ); |
63 |
|
64 |
//@}
|
65 |
|
66 |
/**
|
67 |
* @name Status accessors
|
68 |
*/
|
69 |
//@{
|
70 |
|
71 |
/**
|
72 |
* Indicates whether the stream is at the end of its data or not.
|
73 |
*
|
74 |
* @return true the stream is valid and at the end of its data.
|
75 |
* @retval false otherwise
|
76 |
*/
|
77 |
virtual bool isEOF();
|
78 |
|
79 |
|
80 |
/**
|
81 |
* @name Opening and closing
|
82 |
*/
|
83 |
//@{
|
84 |
|
85 |
/**
|
86 |
* Is the stream open?
|
87 |
*
|
88 |
* @retval true the stream is valid and in a state that allows data access.
|
89 |
* @retval false otherwise
|
90 |
*/
|
91 |
virtual bool isOpen();
|
92 |
|
93 |
/**
|
94 |
* Opens the stream.
|
95 |
*
|
96 |
* Opening a stream puts it in a state that allows data access based on cached
|
97 |
* initialization parameters.
|
98 |
*
|
99 |
* @retval LT_STS_IOStreamUninitialized The stream has not been initialized with enough
|
100 |
* information to open the stream
|
101 |
* @retval LT_STS_IOStreamInvalidState The the stream is already open
|
102 |
* @retval LT_STS_Success On success.
|
103 |
* @retval LT_STS_Failure Otherwise.
|
104 |
*/
|
105 |
virtual LT_STATUS open(); |
106 |
|
107 |
/**
|
108 |
* Closes the stream.
|
109 |
*
|
110 |
* Puts the stream in a state that does not allow data access. May
|
111 |
* free up resources, but only in such a way that doesn't inhibit
|
112 |
* successful future calls to open()
|
113 |
*
|
114 |
* @retval LT_STS_Success On success, or if the stream is already closed.
|
115 |
* @retval LT_STS_Failure Otherwise.
|
116 |
*/
|
117 |
virtual LT_STATUS close(); |
118 |
|
119 |
//@}
|
120 |
|
121 |
|
122 |
/**
|
123 |
* @name Data access
|
124 |
*/
|
125 |
//@{
|
126 |
|
127 |
/**
|
128 |
* Retrieve the specified number of bytes from the data source and
|
129 |
* place them in pDest.
|
130 |
*
|
131 |
* @param pDest buffer in which to store read data
|
132 |
* @param numBytes number of bytes to read from stream
|
133 |
*
|
134 |
* @retval numBytes The number of bytes actually read
|
135 |
*/
|
136 |
virtual lt_uint32 read( lt_uint8 *pDest, lt_uint32 numBytes ); |
137 |
|
138 |
/**
|
139 |
* Store the specified number of bytes in the data source.
|
140 |
*
|
141 |
* @param pSrc buffer from which to store data
|
142 |
* @param numBytes number of bytes to write to stream
|
143 |
*
|
144 |
* @retval numBytes number of bytes actually written
|
145 |
*/
|
146 |
virtual lt_uint32 write( const lt_uint8 *pSrc, lt_uint32 numBytes );
|
147 |
|
148 |
//@}
|
149 |
|
150 |
/**
|
151 |
* @name Positioning
|
152 |
*/
|
153 |
//@{
|
154 |
|
155 |
/**
|
156 |
* Moves the the data access position to origin + offset
|
157 |
*
|
158 |
* @param offset number of bytes from origin at which to the next read or write will take place
|
159 |
* @param origin place in stream from which to seek
|
160 |
*
|
161 |
* @retval LT_STS_IOStreamUnsupported The stream is not seekable
|
162 |
* @retval LT_STS_IOStreamInvalidArgs The offset and origin do not specify a valid location in the stream
|
163 |
* @retval LT_STS_Success On success
|
164 |
* @retval LT_STS_Failure Otherwise
|
165 |
*/
|
166 |
virtual LT_STATUS seek( lt_int64 offset, LTIOSeekDir origin ); |
167 |
|
168 |
/**
|
169 |
* Returns the current data access position as an offset from the start of the data
|
170 |
*
|
171 |
* @retval postion Number of bytes from the start of the data
|
172 |
* @retval -1 On error.
|
173 |
*/
|
174 |
virtual lt_int64 tell(); |
175 |
|
176 |
//@}
|
177 |
|
178 |
/**
|
179 |
* @name Other operations
|
180 |
*/
|
181 |
//@{
|
182 |
|
183 |
/**
|
184 |
* @brief Clone the stream
|
185 |
*
|
186 |
* Create new stream of the same type with the same initialization parameters.
|
187 |
* The transmission of these parameters is the responsibility of the derived type.
|
188 |
* The new stream should initially return false for isOpen().
|
189 |
*
|
190 |
* @retval NULL the stream could not be duplicated; valid LTIOStreamInf* otherwise.
|
191 |
*/
|
192 |
virtual LTIOStreamInf* duplicate(); |
193 |
|
194 |
virtual LT_STATUS getLastError() const;
|
195 |
|
196 |
virtual const char* getID() const; |
197 |
|
198 |
//@}
|
199 |
private:
|
200 |
|
201 |
/** cleanup method */
|
202 |
void cleanup();
|
203 |
/** sets url id */
|
204 |
void setID();
|
205 |
|
206 |
protected:
|
207 |
|
208 |
/** pointer to open file */
|
209 |
#if defined(LT_OS_WIN)
|
210 |
HANDLE m_file; |
211 |
// The win32 I/O primitives have different semantics than the Unix file
|
212 |
// primitives, which are our reference model -- so we need to track the
|
213 |
// EOF condition ourselves.
|
214 |
bool m_isEOF;
|
215 |
#elif defined(LT_OS_SUNOS) || defined(LT_OS_LINUX) || defined(LT_OS_DARWIN)
|
216 |
FILE * m_file; |
217 |
#else
|
218 |
#error Platform not yet supported.
|
219 |
#endif
|
220 |
|
221 |
/** path */
|
222 |
LTFileSpec m_path; |
223 |
|
224 |
/** mode */
|
225 |
char *m_mode;
|
226 |
char *m_uri;
|
227 |
|
228 |
// (state code taken copied from LTIOFileStream)
|
229 |
enum
|
230 |
{ |
231 |
unknown_state = 1,
|
232 |
reading_state = 2,
|
233 |
writing_state = 3
|
234 |
} m_state; |
235 |
}; |
236 |
|
237 |
|
238 |
|
239 |
LT_END_NAMESPACE( LizardTech ) |
240 |
|
241 |
|
242 |
#endif // LT_IOFILE64STREAM_H |