00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _dgChannelBuf_h_
00027 #define _dgChannelBuf_h_
00028
00035 #include <iostream>
00036 #include <list>
00037 #include <string>
00038
00039 namespace DGD {
00040
00072 class channelbuf: public std::streambuf {
00073 public:
00074 enum Assoc_type {
00075 Assoc_Append = 0,
00076 Assoc_Assign,
00077 Assoc_Prepend,
00078 };
00079
00080 typedef std::streambuf Parent;
00081 typedef std::pair<unsigned,unsigned> position_type;
00082 #if defined(__STDC__) && !defined(_STLPORT)
00083 typedef char char_type;
00084 typedef int int_type;
00085 class traits_type {
00086 public:
00087 static int_type eof() { return -1; }
00088 static void move( char_type* dst,
00089 const char_type* src,
00090 const int_type len ) {
00091 memmove( dst, src, len );
00092 }
00093 static const char_type* find( const char_type* src,
00094 const int_type len,
00095 const char_type ch ) {
00096 return (const char_type*)memchr( src, ch, len );
00097 }
00098 };
00099 #endif
00100
00101 protected:
00102 typedef std::list< std::ostream* > Assoc_list;
00103
00104 protected:
00110 virtual Parent* setbuf(char_type*, std::streamsize);
00111
00112 virtual int sync();
00113
00114 virtual int_type overflow(int_type = traits_type::eof());
00117 virtual void propagate( const char_type* begin,
00118 const char_type* end );
00119 virtual void propagate( const char_type ch,
00120 std::streamsize size );
00121
00122 virtual void post_process();
00123
00124 public:
00125 enum DefaultValues {
00126 DefaultBufferSize = 100,
00127 DefaultMaxWidth = 79,
00128 DefaultMinWidth = 20,
00129 DefaultIndentStep = 8
00130 };
00131
00132 public:
00133 channelbuf();
00134 ~channelbuf();
00135
00136 void assoc( std::ostream*,
00137 const Assoc_type action = Assoc_Append );
00138 bool dassoc( std::ostream* );
00139 void dassoc( );
00140
00141 unsigned int line() const;
00142 unsigned int column() const;
00143
00144 void indent_step( unsigned int step );
00145 unsigned int indent_step() const;
00146 void incr_indent();
00147 void decr_indent();
00148 void indent(const unsigned int);
00149 unsigned int indent() const;
00150
00151 void min_width( unsigned int width );
00152 unsigned int min_width() const;
00153 void max_width( unsigned int width );
00154 unsigned int max_width() const;
00155
00156 void wrap( bool allow );
00157 bool wrap() const;
00158 void word_wrap( bool allow );
00159 bool word_wrap() const;
00160
00161 void space_chars(const char* spc = " \t");
00162 std::string space_chars() const;
00163
00164 position_type position() const;
00165 unsigned long bytes_written() const;
00166
00167 #if defined(_CYGWIN) && !defined(_STLPORT)
00168 Parent* pubsetbuf(char_type* b, std::streamsize s) {
00169 return setbuf(b, s);
00170 }
00171 #endif
00172
00173 protected:
00174 char_type* find_one_of( const char_type* s, const unsigned int n,
00175 const char_type* c_set ) const;
00176 bool is_dos_eol( const char_type* p ) const;
00177
00178 private:
00179 Assoc_list m_assoc;
00180 unsigned int m_line;
00181 unsigned int m_column;
00182 unsigned int m_indent;
00183 unsigned int m_indent_step;
00184 unsigned int m_min_width;
00185 unsigned int m_max_width;
00186 bool m_wrap;
00187 bool m_word_wrap;
00188 const char_type* m_word_pos;
00189 std::string m_spaces;
00190 unsigned long m_bytes;
00191 };
00192
00193 };
00194
00195 #endif
00196
00197
00198
00199
00200
00201
00202
00203
00204