1 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2
3 #line 1 "fd-ostream.oo.h"
4 /* Output stream referring to a file descriptor.
5 Copyright (C) 2006, 2020 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 _FD_OSTREAM_H
22 #define _FD_OSTREAM_H
23
24 #include <stdbool.h>
25
26 #include "ostream.h"
27
28
29 #line 30 "fd-ostream.h"
30 struct fd_ostream_representation;
31 /* fd_ostream_t is defined as a pointer to struct fd_ostream_representation.
32 In C++ mode, we use a smart pointer class.
33 In C mode, we have no other choice than a typedef to the root class type. */
34 #if IS_CPLUSPLUS
35 struct fd_ostream_t
36 {
37 private:
38 struct fd_ostream_representation *_pointer;
39 public:
40 fd_ostream_t () : _pointer (NULL) {}
41 fd_ostream_t (struct fd_ostream_representation *pointer) : _pointer (pointer) {}
42 struct fd_ostream_representation * operator -> () { return _pointer; }
43 operator struct fd_ostream_representation * () { return _pointer; }
44 operator struct any_ostream_representation * () { return (struct any_ostream_representation *) _pointer; }
45 operator void * () { return _pointer; }
46 bool operator == (const void *p) { return _pointer == p; }
47 bool operator != (const void *p) { return _pointer != p; }
48 operator ostream_t () { return (ostream_t) (struct any_ostream_representation *) _pointer; }
49 explicit fd_ostream_t (ostream_t x) : _pointer ((struct fd_ostream_representation *) (void *) x) {}
50 };
51 #else
52 typedef ostream_t fd_ostream_t;
53 #endif
54
55 /* Functions that invoke the methods. */
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 extern void fd_ostream_write_mem (fd_ostream_t first_arg, const void *data, size_t len);
60 extern void fd_ostream_flush (fd_ostream_t first_arg, ostream_flush_scope_t scope);
61 extern void fd_ostream_free (fd_ostream_t first_arg);
62 extern int fd_ostream_get_descriptor (fd_ostream_t first_arg);
63 extern const char * fd_ostream_get_filename (fd_ostream_t first_arg);
64 extern bool fd_ostream_is_buffered (fd_ostream_t first_arg);
65 #ifdef __cplusplus
66 }
67 #endif
68
69 /* Type representing an implementation of fd_ostream_t. */
70 struct fd_ostream_implementation
71 {
72 const typeinfo_t * const *superclasses;
73 size_t superclasses_length;
74 size_t instance_size;
75 #define THIS_ARG fd_ostream_t first_arg
76 #include "fd_ostream.vt.h"
77 #undef THIS_ARG
78 };
79
80 /* Public portion of the object pointed to by a fd_ostream_t. */
81 struct fd_ostream_representation_header
82 {
83 const struct fd_ostream_implementation *vtable;
84 };
85
86 #if HAVE_INLINE
87
88 /* Define the functions that invoke the methods as inline accesses to
89 the fd_ostream_implementation.
90 Use #define to avoid a warning because of extern vs. static. */
91
92 # define fd_ostream_write_mem fd_ostream_write_mem_inline
93 static inline void
94 fd_ostream_write_mem (fd_ostream_t first_arg, const void *data, size_t len)
95 {
96 const struct fd_ostream_implementation *vtable =
97 ((struct fd_ostream_representation_header *) (struct fd_ostream_representation *) first_arg)->vtable;
98 vtable->write_mem (first_arg,data,len);
99 }
100
101 # define fd_ostream_flush fd_ostream_flush_inline
102 static inline void
103 fd_ostream_flush (fd_ostream_t first_arg, ostream_flush_scope_t scope)
104 {
105 const struct fd_ostream_implementation *vtable =
106 ((struct fd_ostream_representation_header *) (struct fd_ostream_representation *) first_arg)->vtable;
107 vtable->flush (first_arg,scope);
108 }
109
110 # define fd_ostream_free fd_ostream_free_inline
111 static inline void
112 fd_ostream_free (fd_ostream_t first_arg)
113 {
114 const struct fd_ostream_implementation *vtable =
115 ((struct fd_ostream_representation_header *) (struct fd_ostream_representation *) first_arg)->vtable;
116 vtable->free (first_arg);
117 }
118
119 # define fd_ostream_get_descriptor fd_ostream_get_descriptor_inline
120 static inline int
121 fd_ostream_get_descriptor (fd_ostream_t first_arg)
122 {
123 const struct fd_ostream_implementation *vtable =
124 ((struct fd_ostream_representation_header *) (struct fd_ostream_representation *) first_arg)->vtable;
125 return vtable->get_descriptor (first_arg);
126 }
127
128 # define fd_ostream_get_filename fd_ostream_get_filename_inline
129 static inline const char *
130 fd_ostream_get_filename (fd_ostream_t first_arg)
131 {
132 const struct fd_ostream_implementation *vtable =
133 ((struct fd_ostream_representation_header *) (struct fd_ostream_representation *) first_arg)->vtable;
134 return vtable->get_filename (first_arg);
135 }
136
137 # define fd_ostream_is_buffered fd_ostream_is_buffered_inline
138 static inline bool
139 fd_ostream_is_buffered (fd_ostream_t first_arg)
140 {
141 const struct fd_ostream_implementation *vtable =
142 ((struct fd_ostream_representation_header *) (struct fd_ostream_representation *) first_arg)->vtable;
143 return vtable->is_buffered (first_arg);
144 }
145
146 #endif
147
148 extern const typeinfo_t fd_ostream_typeinfo;
149 #define fd_ostream_SUPERCLASSES &fd_ostream_typeinfo, ostream_SUPERCLASSES
150 #define fd_ostream_SUPERCLASSES_LENGTH (1 + ostream_SUPERCLASSES_LENGTH)
151
152 extern const struct fd_ostream_implementation fd_ostream_vtable;
153
154 #line 34 "fd-ostream.oo.h"
155
156
157 #ifdef __cplusplus
158 extern "C" {
159 #endif
160
161
162 /* Create an output stream referring to the file descriptor FD.
163 FILENAME is used only for error messages.
164 Note that the resulting stream must be closed before FD can be closed. */
165 extern fd_ostream_t fd_ostream_create (int fd, const char *filename,
166 bool buffered);
167
168
169 /* Test whether a given output stream is a fd_ostream. */
170 extern bool is_instance_of_fd_ostream (ostream_t stream);
171
172
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #endif /* _FD_OSTREAM_H */