00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef LIBAEGIS_OUTPUT_H
00021 #define LIBAEGIS_OUTPUT_H
00022
00023 #include <common/ac/stdarg.h>
00024 #include <common/ac/stddef.h>
00025 #include <common/main.h>
00026 #include <common/nstring.h>
00027 #include <common/ac/shared_ptr.h>
00028
00029 #include <libaegis/functor/stack.h>
00030
00031 struct string_ty;
00032
00033
00039 class output
00040 {
00041 public:
00046 typedef aegis_shared_ptr<output> pointer;
00047
00048 typedef void (*delete_callback_ty)(output *, void *);
00049
00053 virtual ~output();
00054
00055 protected:
00060 output();
00061
00062 public:
00066 virtual nstring filename() const = 0;
00067
00072 long ftell() const;
00073
00077 void write(const void *data, size_t nbytes);
00078
00083 void flush();
00084
00089 virtual int page_width() const;
00090
00095 virtual int page_length() const;
00096
00101 void end_of_line();
00102
00107 virtual const char *type_name() const = 0;
00108
00113 void
00114 fputc(char c)
00115 {
00116 if (buffer_position < buffer_end)
00117 *buffer_position++ = c;
00118 else
00119 overflow(c);
00120 }
00121
00129 void fputs(const char *str);
00130
00142 void fputs_xml(const char *str, bool paragraphs = false);
00143
00150 void fputs(string_ty *str);
00151
00163 void fputs_xml(string_ty *str, bool paragraphs = false);
00164
00171 void fputs(const nstring &str);
00172
00184 void fputs_xml(const nstring &str, bool paragraphs = false);
00185
00196 void fprintf(const char *fmt, ...) ATTR_PRINTF(2, 3);
00197
00205 void vfprintf(const char *fmt, va_list) ATTR_PRINTF(2, 0);
00206
00211 void register_delete_callback(functor::pointer fp);
00212
00217 void unregister_delete_callback(functor::pointer fp);
00218
00219 private:
00224 virtual long ftell_inner() const = 0;
00225
00230 virtual void write_inner(const void *data, size_t length) = 0;
00231
00237 virtual void end_of_line_inner() = 0;
00238
00244 virtual void flush_inner();
00245
00251 void overflow(char c);
00252
00257 functor_stack callback;
00258
00264 unsigned char *buffer;
00265
00270 size_t buffer_size;
00271
00276 unsigned char *buffer_position;
00277
00282 unsigned char *buffer_end;
00283
00287 output(const output &);
00288
00292 output &operator=(const output &);
00293 };
00294
00295
00296 inline output::pointer &
00297 operator<<(output::pointer &os, char c)
00298 {
00299 os->fputc(c);
00300 return os;
00301 }
00302
00303
00304 inline output::pointer &
00305 operator<<(output::pointer &os, const char *s)
00306 {
00307 os->fputs(s);
00308 return os;
00309 }
00310
00311
00312 inline output::pointer &
00313 operator<<(output::pointer &os, const nstring &s)
00314 {
00315 os->fputs(s);
00316 return os;
00317 }
00318
00319
00320 class input;
00321
00322 output::pointer &operator<<(output::pointer &os, input &is);
00323
00324 #endif // LIBAEGIS_OUTPUT_H