v0.3.0
Fast, portable C library for geometry input/output
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Modules
stream.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (c) 2016, Fougue Ltd. <http://www.fougue.pro>
3 ** All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 **
9 ** 1. Redistributions of source code must retain the above copyright
10 ** notice, this list of conditions and the following disclaimer.
11 **
12 ** 2. Redistributions in binary form must reproduce the above
13 ** copyright notice, this list of conditions and the following
14 ** disclaimer in the documentation and/or other materials provided
15 ** with the distribution.
16 **
17 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ****************************************************************************/
29 
37 #ifndef GMIO_STREAM_H
38 #define GMIO_STREAM_H
39 
40 #include "global.h"
41 #include "memblock.h"
42 #include "streampos.h"
43 #include <stdio.h>
44 
45 #ifndef DOXYGEN
46 # ifdef GMIO_HAVE_INT64_TYPE
47 typedef int64_t gmio_streamsize_t;
48 typedef int64_t gmio_streamoffset_t;
49 # else
50 typedef long gmio_streamsize_t;
51 typedef long gmio_streamoffset_t;
52 # endif
53 #else
54 
58 typedef int64_or_long gmio_streamsize_t;
63 typedef int64_or_long gmio_streamoffset_t;
64 #endif
65 
80 {
83  void* cookie;
84 
93  bool (*func_at_end)(void* cookie);
94 
103  int (*func_error)(void* cookie);
104 
116  size_t (*func_read)(void* cookie, void* ptr, size_t size, size_t count);
117 
129  size_t (*func_write)(void* cookie, const void* ptr, size_t size, size_t count);
130 
133 
139  int (*func_get_pos)(void* cookie, struct gmio_streampos* pos);
140 
147  int (*func_set_pos)(void* cookie, const struct gmio_streampos* pos);
148 };
149 
150 
152 
153 /* Initialization */
154 
157 
159 GMIO_API struct gmio_stream gmio_stream_stdio(FILE* file);
160 
162 
163 #endif /* GMIO_STREAM_H */
164 
#define GMIO_API
Expands either to GMIO_DECL_EXPORT or GMIO_DECL_IMPORT when respectively compiling/using the DLL...
Definition: global.h:90
int(* func_get_pos)(void *cookie, struct gmio_streampos *pos)
Pointer on a function that retrieves the current position in the stream.
Definition: stream.h:139
bool(* func_at_end)(void *cookie)
Pointer on a function that checks end-of-stream indicator.
Definition: stream.h:93
size_t(* func_write)(void *cookie, const void *ptr, size_t size, size_t count)
Pointer on a function that writes block of data to stream.
Definition: stream.h:129
Fundamental global declarations, included by almost all other header/source files.
Declaration of gmio_memblock and utility functions.
int(* func_set_pos)(void *cookie, const struct gmio_streampos *pos)
Pointer on a function that restores the current position in the stream to pos.
Definition: stream.h:147
struct gmio_stream gmio_stream_stdio(FILE *file)
Returns a stream for standard FILE* (cookie will hold file)
#define GMIO_C_LINKAGE_BEGIN
Expands to extern "C" { when building with a C++ compiler.
Definition: global.h:195
size_t(* func_read)(void *cookie, void *ptr, size_t size, size_t count)
Pointer on a function that reads block of data from stream.
Definition: stream.h:116
Declaration of gmio_streampos and utility functions.
#define GMIO_C_LINKAGE_END
Expands to } when building with a C++ compiler.
Definition: global.h:197
Specifies a position within a stream.
Definition: streampos.h:55
int64_or_long gmio_streamsize_t
Type able to represent the size(in bytes) of a stream.
Definition: stream.h:58
Stream that can get input from an arbitrary data source or can write output to an arbitrary data sink...
Definition: stream.h:79
int64_or_long gmio_streamoffset_t
Type able to represent the offset position within a stream.
Definition: stream.h:63
void * cookie
Opaque pointer on the user stream, passed as first argument to hook functions.
Definition: stream.h:83
int(* func_error)(void *cookie)
Pointer on a function that checks error indicator.
Definition: stream.h:103
gmio_streamsize_t(* func_size)(void *cookie)
Pointer on a function that returns the size(in bytes) of the stream.
Definition: stream.h:132
struct gmio_stream gmio_stream_null()
Returns a null stream.
Fougue © 2016