v0.4.1
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) 2017, 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 #pragma once
38 
39 #include "global.h"
40 #include "memblock.h"
41 #include "streampos.h"
42 #include <stdio.h>
43 
44 #ifndef DOXYGEN
45 # ifdef GMIO_HAVE_INT64_TYPE
46 typedef int64_t gmio_streamsize_t;
47 typedef int64_t gmio_streamoffset_t;
48 # else
49 typedef long gmio_streamsize_t;
50 typedef long gmio_streamoffset_t;
51 # endif
52 #else
53 
57 typedef int64_or_long gmio_streamsize_t;
62 typedef int64_or_long gmio_streamoffset_t;
63 #endif
64 
79 {
82  void* cookie;
83 
92  bool (*func_at_end)(void* cookie);
93 
102  int (*func_error)(void* cookie);
103 
115  size_t (*func_read)(void* cookie, void* ptr, size_t size, size_t count);
116 
128  size_t (*func_write)(void* cookie, const void* ptr, size_t size, size_t count);
129 
132 
138  int (*func_get_pos)(void* cookie, struct gmio_streampos* pos);
139 
146  int (*func_set_pos)(void* cookie, const struct gmio_streampos* pos);
147 };
148 
149 
151 
152 /* Initialization */
153 
156 
158 GMIO_API struct gmio_stream gmio_stream_stdio(FILE* file);
159 
161 
#define GMIO_API
Expands either to GMIO_DECL_EXPORT or GMIO_DECL_IMPORT when respectively compiling/using the DLL...
Definition: global.h:89
int(* func_get_pos)(void *cookie, struct gmio_streampos *pos)
Function that retrieves the current position in the stream.
Definition: stream.h:138
bool(* func_at_end)(void *cookie)
Function that checks end-of-stream indicator.
Definition: stream.h:92
size_t(* func_write)(void *cookie, const void *ptr, size_t size, size_t count)
Function that writes block of data to stream.
Definition: stream.h:128
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)
Function that restores the current position in the stream to pos.
Definition: stream.h:146
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:203
size_t(* func_read)(void *cookie, void *ptr, size_t size, size_t count)
Function that reads block of data from stream.
Definition: stream.h:115
Declaration of gmio_streampos and utility functions.
#define GMIO_C_LINKAGE_END
Expands to } when building with a C++ compiler.
Definition: global.h:205
Specifies a position within a stream.
Definition: streampos.h:54
int64_or_long gmio_streamsize_t
Type able to represent the size(in bytes) of a stream.
Definition: stream.h:57
Stream that can get input from an arbitrary data source or can write output to an arbitrary data sink...
Definition: stream.h:78
int64_or_long gmio_streamoffset_t
Type able to represent the offset position within a stream.
Definition: stream.h:62
void * cookie
Opaque pointer on the user stream, passed as first argument to hook functions.
Definition: stream.h:82
int(* func_error)(void *cookie)
Function that checks error indicator.
Definition: stream.h:102
gmio_streamsize_t(* func_size)(void *cookie)
Function that returns the size(in bytes) of the stream.
Definition: stream.h:131
struct gmio_stream gmio_stream_null()
Returns a null stream.
Fougue © 2017