ruby: Use nestlevel instead of string lists
[geany-mirror.git] / tagmanager / mio / mio.h
blob5fd8d03b4c3e05407d6f29fff2bd9672e1c22d52
1 /*
2 * MIO, an I/O abstraction layer replicating C file I/O API.
3 * Copyright (C) 2010 Colomban Wendling <ban@herbesfolles.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifndef H_MIO_H
22 #define H_MIO_H
24 #include <glib.h>
25 #include <stdio.h>
26 #include <stdarg.h>
29 /**
30 * MIOType:
31 * @MIO_TYPE_FILE: #MIO object works on a file
32 * @MIO_TYPE_MEMORY: #MIO object works in-memory
34 * Existing implementations.
36 enum _MIOType {
37 MIO_TYPE_FILE,
38 MIO_TYPE_MEMORY
41 typedef enum _MIOType MIOType;
42 typedef struct _MIO MIO;
43 typedef struct _MIOPos MIOPos;
44 /**
45 * MIOReallocFunc:
46 * @ptr: Pointer to the memory to resize
47 * @size: New size of the memory pointed by @ptr
49 * A function following the realloc() semantic.
51 * Returns: A pointer to the start of the new memory, or %NULL on failure.
53 /* should be GReallocFunc but it's only defined by GIO */
54 typedef gpointer (* MIOReallocFunc) (gpointer ptr,
55 gsize size);
57 /**
58 * MIOFOpenFunc:
59 * @filename: The filename to open
60 * @mode: fopen() modes for opening @filename
62 * A function following the fclose() semantic, used to close a #FILE
63 * object.
65 * Returns: A new #FILE object, or %NULL on failure
67 typedef FILE *(* MIOFOpenFunc) (const gchar *filename,
68 const gchar *mode);
70 /**
71 * MIOFCloseFunc:
72 * @fp: An opened #FILE object
74 * A function following the fclose() semantic, used to close a #FILE
75 * object.
77 * Returns: 0 on success, EOF otherwise.
79 typedef gint (* MIOFCloseFunc) (FILE *fp);
81 /**
82 * MIOPos:
84 * An object representing the state of a #MIO stream. This object can be
85 * statically allocated but all its fields are private and should not be
86 * accessed directly.
88 struct _MIOPos {
89 /*< private >*/
90 guint type;
91 #ifdef MIO_DEBUG
92 void *tag;
93 #endif
94 union {
95 fpos_t file;
96 gsize mem;
97 } impl;
101 * MIO:
103 * An object representing a #MIO stream. No assumptions should be made about
104 * what compose this object, and none of its fields should be accessed directly.
106 struct _MIO {
107 /*< private >*/
108 guint type;
109 union {
110 struct {
111 FILE *fp;
112 MIOFCloseFunc close_func;
113 } file;
114 struct {
115 guchar *buf;
116 gint ungetch;
117 gsize pos;
118 gsize size;
119 gsize allocated_size;
120 MIOReallocFunc realloc_func;
121 GDestroyNotify free_func;
122 gboolean error;
123 gboolean eof;
124 } mem;
125 } impl;
126 /* virtual function table */
127 void (*v_free) (MIO *mio);
128 gsize (*v_read) (MIO *mio,
129 void *ptr,
130 gsize size,
131 gsize nmemb);
132 gsize (*v_write) (MIO *mio,
133 const void *ptr,
134 gsize size,
135 gsize nmemb);
136 gint (*v_getc) (MIO *mio);
137 gchar *(*v_gets) (MIO *mio,
138 gchar *s,
139 gsize size);
140 gint (*v_ungetc) (MIO *mio,
141 gint ch);
142 gint (*v_putc) (MIO *mio,
143 gint c);
144 gint (*v_puts) (MIO *mio,
145 const gchar *s);
146 gint (*v_vprintf) (MIO *mio,
147 const gchar *format,
148 va_list ap) G_GNUC_PRINTF (2, 0);
149 void (*v_clearerr) (MIO *mio);
150 gint (*v_eof) (MIO *mio);
151 gint (*v_error) (MIO *mio);
152 gint (*v_seek) (MIO *mio,
153 glong offset,
154 gint whence);
155 glong (*v_tell) (MIO *mio);
156 void (*v_rewind) (MIO *mio);
157 gint (*v_getpos) (MIO *mio,
158 MIOPos *pos);
159 gint (*v_setpos) (MIO *mio,
160 MIOPos *pos);
164 MIO *mio_new_file (const gchar *filename,
165 const gchar *mode);
166 MIO *mio_new_file_full (const gchar *filename,
167 const gchar *mode,
168 MIOFOpenFunc open_func,
169 MIOFCloseFunc close_func);
170 MIO *mio_new_fp (FILE *fp,
171 MIOFCloseFunc close_func);
172 MIO *mio_new_memory (guchar *data,
173 gsize size,
174 MIOReallocFunc realloc_func,
175 GDestroyNotify free_func);
176 void mio_free (MIO *mio);
177 FILE *mio_file_get_fp (MIO *mio);
178 guchar *mio_memory_get_data (MIO *mio,
179 gsize *size);
180 gsize mio_read (MIO *mio,
181 void *ptr,
182 gsize size,
183 gsize nmemb);
184 gsize mio_write (MIO *mio,
185 const void *ptr,
186 gsize size,
187 gsize nmemb);
188 gint mio_getc (MIO *mio);
189 gchar *mio_gets (MIO *mio,
190 gchar *s,
191 gsize size);
192 gint mio_ungetc (MIO *mio,
193 gint ch);
194 gint mio_putc (MIO *mio,
195 gint c);
196 gint mio_puts (MIO *mio,
197 const gchar *s);
199 gint mio_vprintf (MIO *mio,
200 const gchar *format,
201 va_list ap) G_GNUC_PRINTF (2, 0);
202 gint mio_printf (MIO *mio,
203 const gchar *format,
204 ...) G_GNUC_PRINTF (2, 3);
206 void mio_clearerr (MIO *mio);
207 gint mio_eof (MIO *mio);
208 gint mio_error (MIO *mio);
209 gint mio_seek (MIO *mio,
210 glong offset,
211 gint whence);
212 glong mio_tell (MIO *mio);
213 void mio_rewind (MIO *mio);
214 gint mio_getpos (MIO *mio,
215 MIOPos *pos);
216 gint mio_setpos (MIO *mio,
217 MIOPos *pos);
221 #endif /* guard */