00001 // 00002 // aegis - project change supervisor 00003 // Copyright (C) 1999-2006, 2008 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program. If not, see 00017 // <http://www.gnu.org/licenses/>. 00018 // 00019 00020 #ifndef LIBAEGIS_WIDE_OUTPUT_H 00021 #define LIBAEGIS_WIDE_OUTPUT_H 00022 00023 #include <common/ac/shared_ptr.h> 00024 #include <common/ac/stddef.h> 00025 #include <common/ac/wchar.h> 00026 00027 #include <common/nstring.h> 00028 #include <libaegis/functor/stack.h> 00029 00030 struct string_ty; // existence 00031 struct wstring_ty; // existence 00032 class wstring; // forward 00033 00039 class wide_output 00040 { 00041 public: 00042 typedef aegis_shared_ptr<wide_output> pointer; 00043 00047 virtual ~wide_output(); 00048 00049 protected: 00053 wide_output(); 00054 00055 public: 00063 void put_cstr(const char *text); 00064 00072 void put_ws(const wchar_t *wsp); 00073 00081 inline void 00082 put_wc(wchar_t wc) 00083 { 00084 if (buffer_position < buffer_end) 00085 *buffer_position++ = wc; 00086 else 00087 overflow(wc); 00088 } 00089 00097 void put_wstr(wstring_ty *wsp); 00098 00106 void write(const wstring &s); 00107 00115 void fputs(string_ty *s); 00116 00124 virtual nstring filename() = 0; 00125 00135 void write(const wchar_t *data, size_t len); 00136 00142 void flush(); 00143 00148 virtual int page_width() = 0; 00149 00154 virtual int page_length() = 0; 00155 00161 void end_of_line(); 00162 00167 virtual const char *type_name() const = 0; 00168 00177 void register_delete_callback(functor::pointer func); 00178 00186 void unregister_delete_callback(functor::pointer func); 00187 00188 protected: 00198 virtual void write_inner(const wchar_t *data, size_t len) = 0; 00199 00204 virtual void flush_inner() = 0; 00205 00213 virtual void end_of_line_inner() = 0; 00214 00215 private: 00222 wchar_t *buffer; 00223 00229 size_t buffer_size; 00230 00239 wchar_t *buffer_position; 00240 00249 wchar_t *buffer_end; 00250 00255 functor_stack callback; 00256 00266 void overflow(wchar_t wc); 00267 }; 00268 00269 #endif // LIBAEGIS_WIDE_OUTPUT_H