1 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2
3 #line 1 "ostream.oo.h"
4 /* Abstract output stream data type.
5 Copyright (C) 2006, 2019 Free Software Foundation, Inc.
6 Written by Bruno Haible <bruno@clisp.org>, 2006.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program 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
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
20
21 #ifndef _OSTREAM_H
22 #define _OSTREAM_H
23
24 #include <stdarg.h>
25 #include <stddef.h>
26 #include <string.h>
27
28 #include "moo.h"
29
30
31 /* Describes the scope of a flush operation. */
32 typedef enum
33 {
34 /* Flushes buffers in this ostream_t.
35 Use this value if you want to write to the underlying ostream_t. */
36 FLUSH_THIS_STREAM = 0,
37 /* Flushes all buffers in the current process.
38 Use this value if you want to write to the same target through a
39 different file descriptor or a FILE stream. */
40 FLUSH_THIS_PROCESS = 1,
41 /* Flushes buffers in the current process and attempts to flush the buffers
42 in the kernel.
43 Use this value so that some other process (or the kernel itself)
44 may write to the same target. */
45 FLUSH_ALL = 2
46 } ostream_flush_scope_t;
47
48
49 /* An output stream is an object to which one can feed a sequence of bytes. */
50
51 #line 52 "ostream.h"
52 struct any_ostream_representation;
53 /* ostream_t is defined as a pointer to struct any_ostream_representation.
54 In C++ mode, we use a smart pointer class.
55 In C mode, we have no other choice than a typedef to the root class type. */
56 #if IS_CPLUSPLUS
57 struct ostream_t
58 {
59 private:
60 struct any_ostream_representation *_pointer;
61 public:
ostream_tostream_t62 ostream_t () : _pointer (NULL) {}
ostream_tostream_t63 ostream_t (struct any_ostream_representation *pointer) : _pointer (pointer) {}
64 struct any_ostream_representation * operator -> () { return _pointer; }
65 operator struct any_ostream_representation * () { return _pointer; }
66 operator void * () { return _pointer; }
67 bool operator == (const void *p) { return _pointer == p; }
68 bool operator != (const void *p) { return _pointer != p; }
69 };
70 #else
71 typedef struct any_ostream_representation * ostream_t;
72 #endif
73
74 /* Functions that invoke the methods. */
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 extern void ostream_write_mem (ostream_t first_arg, const void *data, size_t len);
79 extern void ostream_flush (ostream_t first_arg, ostream_flush_scope_t scope);
80 extern void ostream_free (ostream_t first_arg);
81 #ifdef __cplusplus
82 }
83 #endif
84
85 /* Type representing an implementation of ostream_t. */
86 struct ostream_implementation
87 {
88 const typeinfo_t * const *superclasses;
89 size_t superclasses_length;
90 size_t instance_size;
91 #define THIS_ARG ostream_t first_arg
92 #include "ostream.vt.h"
93 #undef THIS_ARG
94 };
95
96 /* Public portion of the object pointed to by a ostream_t. */
97 struct ostream_representation_header
98 {
99 const struct ostream_implementation *vtable;
100 };
101
102 #if HAVE_INLINE
103
104 /* Define the functions that invoke the methods as inline accesses to
105 the ostream_implementation.
106 Use #define to avoid a warning because of extern vs. static. */
107
108 # define ostream_write_mem ostream_write_mem_inline
109 static inline void
ostream_write_mem(ostream_t first_arg,const void * data,size_t len)110 ostream_write_mem (ostream_t first_arg, const void *data, size_t len)
111 {
112 const struct ostream_implementation *vtable =
113 ((struct ostream_representation_header *) (struct any_ostream_representation *) first_arg)->vtable;
114 vtable->write_mem (first_arg,data,len);
115 }
116
117 # define ostream_flush ostream_flush_inline
118 static inline void
ostream_flush(ostream_t first_arg,ostream_flush_scope_t scope)119 ostream_flush (ostream_t first_arg, ostream_flush_scope_t scope)
120 {
121 const struct ostream_implementation *vtable =
122 ((struct ostream_representation_header *) (struct any_ostream_representation *) first_arg)->vtable;
123 vtable->flush (first_arg,scope);
124 }
125
126 # define ostream_free ostream_free_inline
127 static inline void
ostream_free(ostream_t first_arg)128 ostream_free (ostream_t first_arg)
129 {
130 const struct ostream_implementation *vtable =
131 ((struct ostream_representation_header *) (struct any_ostream_representation *) first_arg)->vtable;
132 vtable->free (first_arg);
133 }
134
135 #endif
136
137 extern const typeinfo_t ostream_typeinfo;
138 #define ostream_SUPERCLASSES &ostream_typeinfo, NULL
139 #define ostream_SUPERCLASSES_LENGTH (1 + 1)
140
141 extern const struct ostream_implementation ostream_vtable;
142
143 #line 61 "ostream.oo.h"
144
145 #ifdef __cplusplus
146 extern "C" {
147 #endif
148
149 /* Write a string's contents to a stream. */
150 extern void ostream_write_str (ostream_t stream, const char *string);
151
152 /* Writes formatted output to a stream.
153 Returns the size of formatted output, or a negative value in case of an
154 error. */
155 extern ptrdiff_t ostream_printf (ostream_t stream, const char *format, ...)
156 #if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3
157 __attribute__ ((__format__ (__printf__, 2, 3)))
158 #endif
159 ;
160 extern ptrdiff_t ostream_vprintf (ostream_t stream,
161 const char *format, va_list args)
162 #if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3
163 __attribute__ ((__format__ (__printf__, 2, 0)))
164 #endif
165 ;
166
167 #if HAVE_INLINE
168
169 #define ostream_write_str ostream_write_str_inline
170 static inline void
ostream_write_str(ostream_t stream,const char * string)171 ostream_write_str (ostream_t stream, const char *string)
172 {
173 ostream_write_mem (stream, string, strlen (string));
174 }
175
176 #endif
177
178 #ifdef __cplusplus
179 }
180 #endif
181
182 #endif /* _OSTREAM_H */
183