svn-gvsig-desktop / tags / v1_1_1_Build_1021 / libraries / libjni-readecw-linux / include / NCSJPCFileIOStream.h @ 33831
History | View | Annotate | Download (7.53 KB)
1 | 1448 | igbrotru | /********************************************************
|
---|---|---|---|
2 | ** Copyright 2002 Earth Resource Mapping Ltd.
|
||
3 | ** This document contains proprietary source code of
|
||
4 | ** Earth Resource Mapping Ltd, and can only be used under
|
||
5 | ** one of the three licenses as described in the
|
||
6 | ** license.txt file supplied with this distribution.
|
||
7 | ** See separate license.txt file for license details
|
||
8 | ** and conditions.
|
||
9 | **
|
||
10 | ** This software is covered by US patent #6,442,298,
|
||
11 | ** #6,102,897 and #6,633,688. Rights to use these patents
|
||
12 | ** is included in the license agreements.
|
||
13 | **
|
||
14 | ** FILE: $Archive: /NCS/Source/include/NCSJP2IOStream.h $
|
||
15 | ** CREATED: 28/11/2002 3:27:34 PM
|
||
16 | ** AUTHOR: Simon Cope
|
||
17 | ** PURPOSE: CNCSJPCIOStream class header
|
||
18 | ** EDITS: [xx] ddMmmyy NAME COMMENTS
|
||
19 | *******************************************************/
|
||
20 | |||
21 | #ifndef NCSJPCFILEIOSTREAM_H
|
||
22 | #define NCSJPCFILEIOSTREAM_H
|
||
23 | |||
24 | #ifndef NCSJPCIOSTREAM_H
|
||
25 | #include "NCSJPCIOStream.h" |
||
26 | #endif // NCSJPCIOSTREAM_H |
||
27 | |||
28 | #ifndef NCSUTIL_H
|
||
29 | #include "NCSUtil.h" |
||
30 | #endif // NCSUTIL_H |
||
31 | |||
32 | /**
|
||
33 | * CNCSJPCFileIOStream class - 64bit File-based IO "Stream" class.
|
||
34 | * This class is the IO mechanism used to access JP2 files.
|
||
35 | * << and >> Operators are not implemented as we can't use exception handling for portability reasons.
|
||
36 | *
|
||
37 | * @author Simon Cope
|
||
38 | * @version $Revision$ $Author$ $Date$
|
||
39 | */
|
||
40 | class NCSJPC_EXPORT_ALL CNCSJPCFileIOStream: public CNCSJPCIOStream { |
||
41 | public:
|
||
42 | /** Default constructor, initialises members */
|
||
43 | CNCSJPCFileIOStream(); |
||
44 | /** Virtual destructor, releases members */
|
||
45 | virtual ~CNCSJPCFileIOStream(); |
||
46 | |||
47 | #if defined(_WCHAR_T_DEFINED)||defined(_WCHAR_T)
|
||
48 | /**
|
||
49 | * Open the stream on the specified file.
|
||
50 | * @param pFileName Full path Name of JP2 file being parsed
|
||
51 | * @param bWrite Open for writing flag.
|
||
52 | * @return CNCSError NCS_SUCCESS, or error code on failure.
|
||
53 | */
|
||
54 | virtual CNCSError Open(wchar_t *pFileName, bool bWrite = false); |
||
55 | #endif
|
||
56 | /**
|
||
57 | * Open the stream on the specified file.
|
||
58 | * @param pFileName Full path Name of JP2 file being parsed
|
||
59 | * @param bWrite Open for writing flag.
|
||
60 | * @return CNCSError NCS_SUCCESS, or error code on failure.
|
||
61 | */
|
||
62 | virtual CNCSError Open(char *pFileName, bool bWrite = false); |
||
63 | /**
|
||
64 | * Close the stream.
|
||
65 | * @return CNCSError NCS_SUCCESS, or error code on failure.
|
||
66 | */
|
||
67 | virtual CNCSError Close(); |
||
68 | /**
|
||
69 | * Seek on the file to the specified location.
|
||
70 | * @param offset Signed 64bit offset to seek by
|
||
71 | * @param origin Origin to calculate new position from.
|
||
72 | * @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
||
73 | */
|
||
74 | virtual bool NCS_FASTCALL Seek(INT64 offset, Origin origin = CURRENT);
|
||
75 | /**
|
||
76 | * Is stream seekable.
|
||
77 | * @return bool true if seekable, or false if not.
|
||
78 | */
|
||
79 | virtual bool NCS_FASTCALL Seek();
|
||
80 | /**
|
||
81 | * Get the current file pointer position.
|
||
82 | * @return INT64 Current file pointer position, or -1 on error.
|
||
83 | */
|
||
84 | virtual INT64 NCS_FASTCALL Tell(); |
||
85 | /**
|
||
86 | * Get the total current size of the file, in bytes.
|
||
87 | * @return INT64 Size of the file, or -1 on error.
|
||
88 | */
|
||
89 | virtual INT64 NCS_FASTCALL Size(); |
||
90 | |||
91 | /**
|
||
92 | * Read some data from the stream into the supplied buffer.
|
||
93 | * @param buffer Buffer to read the data into
|
||
94 | * @param count How many bytes of data to read.
|
||
95 | * @param pRead How many bytes of data were actually read.
|
||
96 | * @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
||
97 | */
|
||
98 | virtual bool NCS_FASTCALL Read(void* buffer, UINT32 count); |
||
99 | /**
|
||
100 | * Write some data to the stream.
|
||
101 | * @param buffer Buffer of data to write to the stream
|
||
102 | * @param count How many bytes of data to write to the stream.
|
||
103 | * @param pWrote How many bytes of data were actually written to the stream.
|
||
104 | * @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
||
105 | */
|
||
106 | virtual bool NCS_FASTCALL Write(void* buffer, UINT32 count); |
||
107 | |||
108 | /**
|
||
109 | * Read a UINT8 from the stream.
|
||
110 | * @param buffer Buffer to receive the data
|
||
111 | * @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
||
112 | */
|
||
113 | virtual bool NCS_FASTCALL ReadUINT8(UINT8 &Buffer);
|
||
114 | |||
115 | #if defined(_WCHAR_T_DEFINED)||defined(_WCHAR_T)
|
||
116 | /**
|
||
117 | * Set some IO callback functions to use instead of the normal crt IO routines.
|
||
118 | * @param pOpenACB Open function - CHAR *.
|
||
119 | * @param pOpenWCB Open function - WCHAR_T.
|
||
120 | * @param pCloseCB Close function.
|
||
121 | * @param pReadCB Read function.
|
||
122 | * @param pSeekCB Seek function.
|
||
123 | * @param pTellCB Tell function.
|
||
124 | * @return CNCSError Error return.
|
||
125 | */
|
||
126 | static CNCSError SetIOCallbacks(NCSError (NCS_CALL *pOpenACB)(char *szFileName, void **ppClientData), |
||
127 | NCSError (NCS_CALL *pOpenWCB)(wchar_t *szFileName, void **ppClientData),
|
||
128 | NCSError (NCS_CALL *pCloseCB)(void *pClientData),
|
||
129 | NCSError (NCS_CALL *pReadCB)(void *pClientData, void *pBuffer, UINT32 nLength), |
||
130 | NCSError (NCS_CALL *pSeekCB)(void *pClientData, UINT64 nOffset),
|
||
131 | NCSError (NCS_CALL *pTellCB)(void *pClientData, UINT64 *pOffset));
|
||
132 | #else
|
||
133 | /**
|
||
134 | * Set some IO callback functions to use instead of the normal crt IO routines.
|
||
135 | * @param pOpenCB Open function.
|
||
136 | * @param pCloseCB Close function.
|
||
137 | * @param pReadCB Read function.
|
||
138 | * @param pSeekCB Seek function.
|
||
139 | * @param pTellCB Tell function.
|
||
140 | * @return CNCSError Error return.
|
||
141 | */
|
||
142 | static CNCSError SetIOCallbacks(NCSError (NCS_CALL *pOpenCB)(char *szFileName, void **ppClientData), |
||
143 | NCSError (NCS_CALL *pCloseCB)(void *pClientData),
|
||
144 | NCSError (NCS_CALL *pReadCB)(void *pClientData, void *pBuffer, UINT32 nLength), |
||
145 | NCSError (NCS_CALL *pSeekCB)(void *pClientData, UINT64 nOffset),
|
||
146 | NCSError (NCS_CALL *pTellCB)(void *pClientData, UINT64 *pOffset));
|
||
147 | #endif
|
||
148 | UINT32 GetIOCacheSize(); |
||
149 | void SetIOCacheSize(UINT32 nBytes);
|
||
150 | |||
151 | protected:
|
||
152 | /** NCS 64bit file handle */
|
||
153 | NCS_FILE_HANDLE m_hFile; |
||
154 | |||
155 | /** IOCache buffer */
|
||
156 | UINT8 *m_pIOCache; |
||
157 | /** Number of bytes in Write cache */
|
||
158 | UINT32 m_nIOWriteCache; |
||
159 | /** Current Index into read cache */
|
||
160 | UINT32 m_iIOReadCache; |
||
161 | /** Max IO Cache size */
|
||
162 | UINT32 m_nMaxIOCache; |
||
163 | /** Global Max IO Cache size */
|
||
164 | static UINT32 sm_nMaxIOCache;
|
||
165 | /** Precalculates file size for read only stream */
|
||
166 | INT64 m_nFileSize; |
||
167 | |||
168 | /**
|
||
169 | * Flush write cache to file.
|
||
170 | * @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
||
171 | */
|
||
172 | virtual __inline void WriteFlush() {
|
||
173 | if(m_bWrite && m_pIOCache && m_nIOWriteCache) {
|
||
174 | NCSError eError = NCSFileWrite(m_hFile, m_pIOCache, m_nIOWriteCache, NULL);
|
||
175 | if(eError == NCS_SUCCESS) {
|
||
176 | m_nOffset += m_nIOWriteCache; |
||
177 | m_nFileSize = NCSMax(m_nFileSize, m_nOffset); |
||
178 | m_nIOWriteCache = 0;
|
||
179 | } else {
|
||
180 | *(CNCSError*)this = eError; |
||
181 | } |
||
182 | } |
||
183 | } |
||
184 | |||
185 | /**
|
||
186 | * Flush read cache .
|
||
187 | * @return bool true, or false on failure. Instance inherits CNCSError object containing error value.
|
||
188 | */
|
||
189 | virtual __inline void ReadFlush() {
|
||
190 | // Current just invalidate the cache.
|
||
191 | m_iIOReadCache = GetIOCacheSize(); |
||
192 | } |
||
193 | |||
194 | static NCSError (NCS_CALL *sm_pOpenACB)(char *szFileName, void **ppClientData); |
||
195 | static NCSError (NCS_CALL *sm_pOpenWCB)(wchar_t *szFileName, void **ppClientData); |
||
196 | static NCSError (NCS_CALL *sm_pCloseCB)(void *pClientData); |
||
197 | static NCSError (NCS_CALL *sm_pReadCB)(void *pClientData, void *pBuffer, UINT32 nLength); |
||
198 | static NCSError (NCS_CALL *sm_pSeekCB)(void *pClientData, UINT64 nOffset); |
||
199 | static NCSError (NCS_CALL *sm_pTellCB)(void *pClientData, UINT64 *pOffset); |
||
200 | }; |
||
201 | |||
202 | #endif // !NCSJPCFILEIOSTREAM_H |