]> git.cworth.org Git - vogl/blob - src/voglcore/lzma_Types.h
Initial vogl checkin
[vogl] / src / voglcore / lzma_Types.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 /* Types.h -- Basic types
28 2008-11-23 : Igor Pavlov : Public domain */
29
30 #ifndef __7Z_TYPES_H
31 #define __7Z_TYPES_H
32
33 #include <stddef.h>
34
35 #if defined(_WIN32)
36 #include <windows.h>
37 #define COMPRESS_MF_MT
38 #endif
39
40 namespace vogl
41 {
42
43 #define SZ_OK 0
44
45 #define SZ_ERROR_DATA 1
46 #define SZ_ERROR_MEM 2
47 #define SZ_ERROR_CRC 3
48 #define SZ_ERROR_UNSUPPORTED 4
49 #define SZ_ERROR_PARAM 5
50 #define SZ_ERROR_INPUT_EOF 6
51 #define SZ_ERROR_OUTPUT_EOF 7
52 #define SZ_ERROR_READ 8
53 #define SZ_ERROR_WRITE 9
54 #define SZ_ERROR_PROGRESS 10
55 #define SZ_ERROR_FAIL 11
56 #define SZ_ERROR_THREAD 12
57
58 #define SZ_ERROR_ARCHIVE 16
59 #define SZ_ERROR_NO_ARCHIVE 17
60
61     typedef int SRes;
62
63 #ifdef _WIN32
64     typedef DWORD WRes;
65 #else
66     typedef int WRes;
67 #endif
68
69 #ifndef RINOK
70 #define RINOK(x)               \
71     {                          \
72         int __result__ = (x);  \
73         if (__result__ != 0)   \
74             return __result__; \
75     }
76 #endif
77
78     typedef unsigned char Byte;
79     typedef short Int16;
80     typedef unsigned short UInt16;
81
82 #ifdef _LZMA_UINT32_IS_ULONG
83     typedef long Int32;
84     typedef unsigned long UInt32;
85 #else
86     typedef int Int32;
87     typedef unsigned int UInt32;
88 #endif
89
90 #ifdef _SZ_NO_INT_64
91
92     /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
93    NOTES: Some code will work incorrectly in that case! */
94
95     typedef long Int64;
96     typedef unsigned long UInt64;
97
98 #else
99
100 #if defined(_MSC_VER) || defined(__BORLANDC__)
101     typedef __int64 Int64;
102     typedef unsigned __int64 UInt64;
103 #else
104     typedef long long int Int64;
105     typedef unsigned long long int UInt64;
106 #endif
107
108 #endif
109
110 #ifdef _LZMA_NO_SYSTEM_SIZE_T
111     typedef UInt32 SizeT;
112 #else
113     typedef size_t SizeT;
114 #endif
115
116     typedef int Bool;
117 #define True 1
118 #define False 0
119
120 #ifdef _MSC_VER
121
122 #if _MSC_VER >= 1300
123 #define MY_NO_INLINE __declspec(noinline)
124 #else
125 #define MY_NO_INLINE
126 #endif
127
128 #define MY_CDECL __cdecl
129 #define MY_STD_CALL __stdcall
130 #define MY_FAST_CALL MY_NO_INLINE __fastcall
131
132 #else
133
134 #define MY_CDECL
135 #define MY_STD_CALL
136 #define MY_FAST_CALL
137
138 #endif
139
140     /* The following interfaces use first parameter as pointer to structure */
141
142     typedef struct
143     {
144         SRes (*Read)(void *p, void *buf, size_t *size);
145         /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
146            (output(*size) < input(*size)) is allowed */
147     } ISeqInStream;
148
149     /* it can return SZ_ERROR_INPUT_EOF */
150     SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
151     SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
152     SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
153
154     typedef struct
155     {
156         size_t (*Write)(void *p, const void *buf, size_t size);
157         /* Returns: result - the number of actually written bytes.
158            (result < size) means error */
159     } ISeqOutStream;
160
161     typedef enum
162     {
163         SZ_SEEK_SET = 0,
164         SZ_SEEK_CUR = 1,
165         SZ_SEEK_END = 2
166     } ESzSeek;
167
168     typedef struct
169     {
170         SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
171         SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
172     } ISeekInStream;
173
174     typedef struct
175     {
176         SRes (*Look)(void *p, void **buf, size_t *size);
177         /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
178            (output(*size) > input(*size)) is not allowed
179            (output(*size) < input(*size)) is allowed */
180         SRes (*Skip)(void *p, size_t offset);
181         /* offset must be <= output(*size) of Look */
182
183         SRes (*Read)(void *p, void *buf, size_t *size);
184         /* reads directly (without buffer). It's same as ISeqInStream::Read */
185         SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
186     } ILookInStream;
187
188     SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
189     SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
190
191     /* reads via ILookInStream::Read */
192     SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
193     SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
194
195 #define LookToRead_BUF_SIZE (1 << 14)
196
197     typedef struct
198     {
199         ILookInStream s;
200         ISeekInStream *realStream;
201         size_t pos;
202         size_t size;
203         Byte buf[LookToRead_BUF_SIZE];
204     } CLookToRead;
205
206     void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
207     void LookToRead_Init(CLookToRead *p);
208
209     typedef struct
210     {
211         ISeqInStream s;
212         ILookInStream *realStream;
213     } CSecToLook;
214
215     void SecToLook_CreateVTable(CSecToLook *p);
216
217     typedef struct
218     {
219         ISeqInStream s;
220         ILookInStream *realStream;
221     } CSecToRead;
222
223     void SecToRead_CreateVTable(CSecToRead *p);
224
225     typedef struct
226     {
227         SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
228         /* Returns: result. (result != SZ_OK) means break.
229            Value (UInt64)(Int64)-1 for size means unknown value. */
230     } ICompressProgress;
231
232     typedef struct
233     {
234         void *(*Alloc)(void *p, size_t size);
235         void (*Free)(void *p, void *address); /* address can be 0 */
236     } ISzAlloc;
237
238 #define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
239 #define IAlloc_Free(p, a) (p)->Free((p), a)
240 }
241
242 #endif