aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/libg3d-0.0.8/include/g3d/stream.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/include/g3d/stream.h')
-rw-r--r--src/others/mimesh/libg3d-0.0.8/include/g3d/stream.h541
1 files changed, 541 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/include/g3d/stream.h b/src/others/mimesh/libg3d-0.0.8/include/g3d/stream.h
new file mode 100644
index 0000000..f3f9630
--- /dev/null
+++ b/src/others/mimesh/libg3d-0.0.8/include/g3d/stream.h
@@ -0,0 +1,541 @@
1/* $Id:$ */
2
3/*
4 libg3d - 3D object loading library
5
6 Copyright (C) 2005-2009 Markus Dahms <mad@automagically.de>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21*/
22
23#ifndef _G3D_STREAM_H
24#define _G3D_STREAM_H
25
26#include <glib.h>
27#include <g3d/types.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif /* ifdef __cplusplus */
32
33/**
34 * SECTION:stream
35 * @short_description: I/O abstraction layer for plugins
36 * @see_also: #G3DStream
37 * @include: g3d/stream.h
38 *
39 * A stream is an abstraction for data input. It enables plugins to read
40 * data from a file, a memory buffer, a container file or some other medium.
41 */
42
43enum {
44 /* shift offsets */
45 G3D_STREAM_SEEKABLE = 0x00,
46 G3D_STREAM_READABLE = 0x01,
47 G3D_STREAM_WRITABLE = 0x02
48};
49
50/**
51 * G3DStreamReadFunc:
52 * @ptr: buffer to read bytes into
53 * @size: number of bytes to read
54 * @data: opaque stream data
55 *
56 * Callback function for g3d_stream_read().
57 *
58 * Returns: number of bytes actually read.
59 */
60typedef gsize (* G3DStreamReadFunc)(gpointer ptr, gsize size, gpointer data);
61
62/**
63 * G3DStreamReadLineFunc:
64 * @buf: buffer to read bytes into
65 * @size: maximum size of buffer
66 * @data: opaque stream data
67 *
68 * Callback function for g3d_stream_read_line().
69 *
70 * Returns: The line buffer or NULL in case of an error.
71 */
72typedef gchar *(* G3DStreamReadLineFunc)(gchar *buf, gsize size,
73 gpointer data);
74
75/**
76 * G3DStreamSeekFunc:
77 * @data: opaque stream data
78 * @offset: seek offset
79 * @whence: seek type
80 *
81 * Callback function for g3d_stream_seek().
82 *
83 * Returns: 0 on success, -1 else.
84 */
85typedef gint (*G3DStreamSeekFunc)(gpointer data, goffset offset,
86 GSeekType whence);
87
88/**
89 * G3DStreamTellFunc:
90 * @data: opaque stream data
91 *
92 * Callback function for g3d_stream_tell().
93 *
94 * Returns: current stream position.
95 */
96typedef goffset (*G3DStreamTellFunc)(gpointer data);
97
98/**
99 * G3DStreamSizeFunc:
100 * @data: opaque stream data
101 *
102 * Callback function for g3d_stream_size().
103 *
104 * Returns: size of stream.
105 */
106typedef goffset (*G3DStreamSizeFunc)(gpointer data);
107
108/**
109 * G3DStreamEofFunc:
110 * @data: opaque stream data
111 *
112 * Callback function for g3d_stream_eof().
113 *
114 * Returns: TRUE on stream end-of-file, FALSE else.
115 */
116typedef gboolean (*G3DStreamEofFunc)(gpointer data);
117
118/**
119 * G3DStreamCloseFunc:
120 * @data: opaque stream data
121 *
122 * Callback function for g3d_stream_close().
123 *
124 * Returns: 0 on success, -1 else.
125 */
126typedef gint (*G3DStreamCloseFunc)(gpointer data);
127
128/**
129 * G3DStream:
130 *
131 * An abstraction of input handling.
132 */
133struct _G3DStream {
134 /*< private >*/
135 guint32 flags;
136 gchar *uri;
137 G3DStreamReadFunc read;
138 G3DStreamReadLineFunc readline;
139 G3DStreamSeekFunc seek;
140 G3DStreamTellFunc tell;
141 G3DStreamSizeFunc size;
142 G3DStreamEofFunc eof;
143 G3DStreamCloseFunc close;
144 gpointer data;
145 guint32 linecount;
146 struct _G3DStream *zip_container;
147};
148
149/* public interface */
150
151/**
152 * g3d_stream_is_seekable:
153 * @stream: the stream
154 *
155 * Get information whether it is possible to seek in a stream.
156 *
157 * Returns: TRUE if seekable, FALSE else
158 */
159EAPI
160gboolean g3d_stream_is_seekable(G3DStream *stream);
161
162/**
163 * g3d_stream_get_uri:
164 * @stream: the stream
165 *
166 * Get the URI of a stream
167 *
168 * Returns: a non-NULL, zero-terminated string containing the URI of the
169 * string. This return value should not be freed.
170 */
171EAPI
172gchar *g3d_stream_get_uri(G3DStream *stream);
173
174/**
175 * g3d_stream_read_int8:
176 * @stream: the stream to read from
177 *
178 * Read a 1 byte signed integer from file.
179 *
180 * Returns: The read value, 0 in case of error
181 */
182EAPI
183gint32 g3d_stream_read_int8(G3DStream *stream);
184
185/**
186 * g3d_stream_read_int16_be:
187 * @stream: the stream to read from
188 *
189 * Read a 2 byte big-endian signed integer from file.
190 *
191 * Returns: The read value, 0 in case of error
192 */
193EAPI
194gint32 g3d_stream_read_int16_be(G3DStream *stream);
195
196/**
197 * g3d_stream_read_int16_le:
198 * @stream: the stream to read from
199 *
200 * Read a 2 byte little-endian signed integer from file.
201 *
202 * Returns: The read value, 0 in case of error
203 */
204EAPI
205gint32 g3d_stream_read_int16_le(G3DStream *stream);
206
207/**
208 * g3d_stream_read_int32_be:
209 * @stream: the stream to read from
210 *
211 * Read a 4 byte big-endian signed integer from file.
212 *
213 * Returns: The read value, 0 in case of error
214 */
215EAPI
216gint32 g3d_stream_read_int32_be(G3DStream *stream);
217
218/**
219 * g3d_stream_read_int32_le:
220 * @stream: the stream to read from
221 *
222 * Read a 4 byte little-endian signed integer from file.
223 *
224 * Returns: The read value, 0 in case of error
225 */
226EAPI
227gint32 g3d_stream_read_int32_le(G3DStream *stream);
228
229/**
230 * g3d_stream_read_float_be:
231 * @stream: the stream to read from
232 *
233 * Read a 4 byte big-endian floating point number from file.
234 *
235 * Returns: The read value, 0 in case of error
236 */
237EAPI
238G3DFloat g3d_stream_read_float_be(G3DStream *stream);
239
240/**
241 * g3d_stream_read_float_le:
242 * @stream: the stream to read from
243 *
244 * Read a 4 byte little-endian floating point number from file.
245 *
246 * Returns: The read value, 0 in case of error
247 */
248EAPI
249G3DFloat g3d_stream_read_float_le(G3DStream *stream);
250
251/**
252 * g3d_stream_read_double_be:
253 * @stream: the stream to read from
254 *
255 * Read a 8 byte big-endian double-precision floating point number from file.
256 *
257 * Returns: The read value, 0 in case of error
258 */
259EAPI
260G3DDouble g3d_stream_read_double_be(G3DStream *stream);
261
262/**
263 * g3d_stream_read_double_le:
264 * @stream: the stream to read from
265 *
266 * Read a 8 byte little-endian double-precision floating point number from
267 * file.
268 *
269 * Returns: The read value, 0 in case of error
270 */
271EAPI
272G3DDouble g3d_stream_read_double_le(G3DStream *stream);
273
274/**
275 * g3d_stream_read_cstr:
276 * @stream: the stream to read from
277 * @buffer: the buffer to fill
278 * @max_len: maximum number to read from stream
279 *
280 * Read a string (terminated by '\0') from stream
281 *
282 * Returns: number of bytes read from stream
283 */
284EAPI
285gint32 g3d_stream_read_cstr(G3DStream *stream, gchar *buffer, gint32 max_len);
286
287/**
288 * g3d_stream_read:
289 * @stream: the stream to read from
290 * @ptr: pointer to memory storage
291 * @size: number of bytes to read
292 *
293 * Reads a number of bytes from the stream.
294 *
295 * Returns: number of bytes successfully read.
296 */
297EAPI
298gsize g3d_stream_read(G3DStream *stream, gpointer ptr, gsize size);
299
300/**
301 * g3d_stream_read_line:
302 * @stream: stream to read a line from
303 * @buf: an allocated buffer to be filled
304 * @size: maximum length of line including terminating zero
305 *
306 * Read a line (terminated by a newline character or end of file) from a
307 * stream.
308 *
309 * Returns: the read line or NULL in case of an error.
310 */
311EAPI
312gchar *g3d_stream_read_line(G3DStream *stream, gchar *buf, gsize size);
313
314/**
315 * g3d_stream_skip:
316 * @stream: stream to skip bytes from
317 * @offset: number of bytes to skip
318 *
319 * Skip a number of bytes (>= 0) in stream even if it does not support
320 * seeking.
321 *
322 * Returns: 0 on success, -1 else
323 */
324EAPI
325gint g3d_stream_skip(G3DStream *stream, goffset offset);
326
327/**
328 * g3d_stream_seek:
329 * @stream: stream to seek in
330 * @offset: number of bytes to seek
331 * @whence: seek type
332 *
333 * Moves around the current position in the stream.
334 *
335 * Returns: 0 on success, -1 else
336 */
337EAPI
338gint g3d_stream_seek(G3DStream *stream, goffset offset, GSeekType whence);
339
340/**
341 * g3d_stream_tell:
342 * @stream: stream to get position from
343 *
344 * Tells the current position in the stream.
345 *
346 * Returns: current stream position
347 */
348EAPI
349goffset g3d_stream_tell(G3DStream *stream);
350
351/**
352 * g3d_stream_line:
353 * @stream: stream to get line from
354 *
355 * Get the current line number from stream. This only works if line are
356 * consequently read with g3d_stream_read_line(), so it's only applicable
357 * for text streams.
358 *
359 * Returns: current line number, may be 0
360 */
361EAPI
362guint32 g3d_stream_line(G3DStream *stream);
363
364/**
365 * g3d_stream_size:
366 * @stream: stream to get size from
367 *
368 * Get the size in bytes of a stream.
369 *
370 * Returns: size of stream in bytes
371 */
372EAPI
373goffset g3d_stream_size(G3DStream *stream);
374
375/**
376 * g3d_stream_eof:
377 * @stream: the stream
378 *
379 * Checks whether the stream has reached its end.
380 *
381 * Returns: TRUE if no more data can be read, FALSE else.
382 */
383EAPI
384gboolean g3d_stream_eof(G3DStream *stream);
385
386/**
387 * g3d_stream_close:
388 * @stream: the stream
389 *
390 * Closes an open stream.
391 *
392 * Returns: 0 on success.
393 */
394EAPI
395gint g3d_stream_close(G3DStream *stream);
396
397/**
398 * g3d_stream_new_custom:
399 * @flags: stream capability flags
400 * @uri: URI of new stream, must not be NULL
401 * @readfunc: read callback function
402 * @readlinefunc: read line callback function, may be NULL in which case
403 * line reading is emulated with g3d_stream_read()
404 * @seekfunc: seek callback function
405 * @tellfunc: tell callback function
406 * @sizefunc: size callback function
407 * @eoffunc: end-of-file callback function
408 * @closefunc: close callback function
409 * @data: opaque data for all callback functions
410 * @zip_container: original zip container
411 *
412 * Creates a new #G3DStream with custom callback functions.
413 *
414 * Returns: a newly allocated #G3DStream or NULL in case of an error.
415 */
416EAPI
417G3DStream *g3d_stream_new_custom(guint32 flags, const gchar *uri,
418 G3DStreamReadFunc readfunc, G3DStreamReadLineFunc readlinefunc,
419 G3DStreamSeekFunc seekfunc, G3DStreamTellFunc tellfunc,
420 G3DStreamSizeFunc sizefunc,
421 G3DStreamEofFunc eoffunc, G3DStreamCloseFunc closefunc, gpointer data,
422 G3DStream *zip_container);
423
424/**
425 * g3d_stream_open_file:
426 * @filename: the name of the file to open
427 * @mode: the mode to open the file, as given to fopen()
428 *
429 * Opens a file with the C stdio routines.
430 *
431 * Returns: a newly allocated #G3DStream or NULL in case of an error.
432 */
433EAPI
434G3DStream *g3d_stream_open_file(const gchar *filename, const gchar *mode);
435
436/**
437 * g3d_stream_from_buffer:
438 * @buffer: memory buffer to use
439 * @size: size of buffer
440 * @title: optional title of stream, may be NULL
441 * @free_buffer: whether to free the memory with g_free() on g3d_stream_close()
442 *
443 * Use a buffer in memory as #G3DStream.
444 *
445 * Returns: a newly allocated #G3DStream or NULL in case of an error.
446 */
447EAPI
448G3DStream *g3d_stream_from_buffer(guint8 *buffer, gsize size,
449 const gchar *title, gboolean free_buffer);
450
451#ifdef HAVE_ZLIB
452
453/**
454 * g3d_stream_zlib_inflate_stream:
455 * @stream: a parent stream
456 * @cmp_size: the compressed size of the deflated part
457 *
458 * Opens a new stream to decompress zlib-deflated parts of a stream.
459 *
460 * Returns: a newly allocated #G3DStream or NULL in case of an error
461 */
462EAPI
463G3DStream *g3d_stream_zlib_inflate_stream(G3DStream *stream, gsize cmp_size);
464
465#endif /* HAVE_ZLIB */
466
467#ifdef HAVE_LIBGSF
468
469/**
470 * g3d_stream_open_gzip_from_stream:
471 * @stream: stream to read from
472 *
473 * Reads data from a gzip-compressed stream.
474 *
475 * Returns: a newly allocated #G3DStream or NULL in case of an error.
476 */
477EAPI
478G3DStream *g3d_stream_open_gzip_from_stream(G3DStream *stream);
479
480/**
481 * g3d_stream_open_structured_file:
482 * @filename: name of container file
483 * @subfile: name of (contained) sub-file
484 *
485 * Open a file within a Structured File as #G3DStream.
486 *
487 * Returns: a newly allocated #G3DStream or NULL in case of an error.
488 */
489EAPI
490G3DStream *g3d_stream_open_structured_file(const gchar *filename,
491 const gchar *subfile);
492
493/**
494 * g3d_stream_open_structured_file_from_stream:
495 * @stream: stream of container file
496 * @subfile: name of (contained) sub-file
497 *
498 * Open a file within a Structured File which is opened as a stream. At the
499 * moment this only works for streams opened by g3d_stream_open_file() as
500 * the file is directly opened again.
501 *
502 * Returns: a newly allocated #G3DStream or NULL in case of an error.
503 */
504EAPI
505G3DStream *g3d_stream_open_structured_file_from_stream(G3DStream *stream,
506 const gchar *subfile);
507
508/**
509 * g3d_stream_open_zip:
510 * @filename: name of container file
511 * @subfile: name of (contained) sub-file
512 *
513 * Open a file within a Zip archive.
514 *
515 * Returns: a newly allocated #G3DStream or NULL in case of an error.
516 */
517EAPI
518G3DStream *g3d_stream_open_zip(const gchar *filename, const gchar *subfile);
519
520/**
521 * g3d_stream_open_zip_from_stream:
522 * @stream: stream of container file
523 * @subfile: name of (contained) sub-file
524 *
525 * Open a file within a Zip archive which is opened as a stream. At the
526 * moment this only works for streams opened by g3d_stream_open_file() as
527 * the file is directly opened again.
528 *
529 * Returns: a newly allocated #G3DStream or NULL in case of an error.
530 */
531EAPI
532G3DStream *g3d_stream_open_zip_from_stream(G3DStream *stream,
533 const gchar *subfile);
534#endif
535
536#ifdef __cplusplus
537}
538#endif /* ifdef __cplusplus */
539
540#endif /* _G3D_STREAM_H */
541