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"
36 #if defined(linux) || defined(CSRG_BASED)
44 namespace SP_NAMESPACE {
47 class SP_API OutputCharStream {
49 enum Newline { newline };
50 typedef void (*Escaper)(OutputCharStream &, Char);
52 virtual ~OutputCharStream();
53 OutputCharStream &put(Char);
54 OutputCharStream &write(const Char *, size_t);
55 virtual void flush() = 0;
56 void setEscaper(Escaper);
58 OutputCharStream &operator<<(char);
59 OutputCharStream &operator<<(const char *);
60 OutputCharStream &operator<<(const StringC &);
61 OutputCharStream &operator<<(unsigned long);
62 OutputCharStream &operator<<(int);
63 OutputCharStream &operator<<(Newline);
65 OutputCharStream(const OutputCharStream &); // undefined
66 void operator=(const OutputCharStream &); // undefined
68 virtual void flushBuf(Char) = 0;
71 void escape(OutputCharStream &, Char c);
76 class SP_API IosOutputCharStream : public OutputCharStream,
77 private Encoder::Handler {
79 IosOutputCharStream();
80 // the streambuf will not be deleted
81 IosOutputCharStream(streambuf *, const OutputCodingSystem *);
82 ~IosOutputCharStream();
83 void open(streambuf *, const OutputCodingSystem *);
86 IosOutputCharStream(const IosOutputCharStream &); // undefined
87 void operator=(const IosOutputCharStream &); // undefined
88 IosOutputCharStream(streambuf *, Encoder *);
89 void allocBuf(int bytesPerChar);
91 void handleUnencodable(Char c, streambuf *);
93 streambuf *byteStream_;
95 Owner<Encoder> ownedEncoder_;
98 class SP_API StrOutputCharStream : public OutputCharStream {
100 StrOutputCharStream();
101 ~StrOutputCharStream();
102 void extractString(StringC &);
107 StrOutputCharStream(const StrOutputCharStream &); // undefined
108 void operator=(const StrOutputCharStream &); // undefined
113 class SP_API RecordOutputCharStream : public OutputCharStream {
115 RecordOutputCharStream(OutputCharStream *);
116 ~RecordOutputCharStream();
119 RecordOutputCharStream(const RecordOutputCharStream &); // undefined
120 void operator=(const RecordOutputCharStream &); // undefined
124 OutputCharStream *os_;
125 enum { bufSize_ = 1024 };
130 OutputCharStream &OutputCharStream::put(Char c)
140 OutputCharStream &OutputCharStream::operator<<(char c)
146 OutputCharStream &OutputCharStream::operator<<(Newline)
148 #ifdef SP_HAVE_SETMODE
151 return put(Char('\n'));
155 OutputCharStream &OutputCharStream::operator<<(const StringC &str)
157 return write(str.data(), str.size());
161 void OutputCharStream::setEscaper(Escaper f)
167 void OutputCharStream::escape(OutputCharStream &s, Char c)
177 #endif /* not OutputCharStream_INCLUDED */