2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: OutputCharStream.h /main/1 1996/07/29 16:59:39 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
27 #ifndef OutputCharStream_INCLUDED
28 #define OutputCharStream_INCLUDED 1
34 #include "CodingSystem.h"
39 namespace SP_NAMESPACE {
42 class SP_API OutputCharStream {
44 enum Newline { newline };
45 typedef void (*Escaper)(OutputCharStream &, Char);
47 virtual ~OutputCharStream();
48 OutputCharStream &put(Char);
49 OutputCharStream &write(const Char *, size_t);
50 virtual void flush() = 0;
51 void setEscaper(Escaper);
53 OutputCharStream &operator<<(char);
54 OutputCharStream &operator<<(const char *);
55 OutputCharStream &operator<<(const StringC &);
56 OutputCharStream &operator<<(unsigned long);
57 OutputCharStream &operator<<(int);
58 OutputCharStream &operator<<(Newline);
60 OutputCharStream(const OutputCharStream &); // undefined
61 void operator=(const OutputCharStream &); // undefined
63 virtual void flushBuf(Char) = 0;
66 void escape(OutputCharStream &, Char c);
71 class SP_API IosOutputCharStream : public OutputCharStream,
72 private Encoder::Handler {
74 IosOutputCharStream();
75 // the streambuf will not be deleted
76 IosOutputCharStream(streambuf *, const OutputCodingSystem *);
77 ~IosOutputCharStream();
78 void open(streambuf *, const OutputCodingSystem *);
81 IosOutputCharStream(const IosOutputCharStream &); // undefined
82 void operator=(const IosOutputCharStream &); // undefined
83 IosOutputCharStream(streambuf *, Encoder *);
84 void allocBuf(int bytesPerChar);
86 void handleUnencodable(Char c, streambuf *);
88 streambuf *byteStream_;
90 Owner<Encoder> ownedEncoder_;
93 class SP_API StrOutputCharStream : public OutputCharStream {
95 StrOutputCharStream();
96 ~StrOutputCharStream();
97 void extractString(StringC &);
102 StrOutputCharStream(const StrOutputCharStream &); // undefined
103 void operator=(const StrOutputCharStream &); // undefined
108 class SP_API RecordOutputCharStream : public OutputCharStream {
110 RecordOutputCharStream(OutputCharStream *);
111 ~RecordOutputCharStream();
114 RecordOutputCharStream(const RecordOutputCharStream &); // undefined
115 void operator=(const RecordOutputCharStream &); // undefined
119 OutputCharStream *os_;
120 enum { bufSize_ = 1024 };
125 OutputCharStream &OutputCharStream::put(Char c)
135 OutputCharStream &OutputCharStream::operator<<(char c)
141 OutputCharStream &OutputCharStream::operator<<(Newline)
143 #ifdef SP_HAVE_SETMODE
146 return put(Char('\n'));
150 OutputCharStream &OutputCharStream::operator<<(const StringC &str)
152 return write(str.data(), str.size());
156 void OutputCharStream::setEscaper(Escaper f)
162 void OutputCharStream::escape(OutputCharStream &s, Char c)
172 #endif /* not OutputCharStream_INCLUDED */