1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
5 #ifndef OutputCharStream_INCLUDED
6 #define OutputCharStream_INCLUDED 1
12 #include "CodingSystem.h"
13 #include "OutputByteStream.h"
16 namespace SP_NAMESPACE
{
19 class SP_API OutputCharStream
{
21 enum Newline
{ newline
};
22 typedef void (*Escaper
)(OutputCharStream
&, Char
);
24 virtual ~OutputCharStream();
25 OutputCharStream
&put(Char
);
26 OutputCharStream
&write(const Char
*, size_t);
27 virtual void flush() = 0;
28 virtual void setEscaper(Escaper
);
30 OutputCharStream
&operator<<(char);
31 OutputCharStream
&operator<<(const char *);
32 OutputCharStream
&operator<<(const StringC
&);
33 OutputCharStream
&operator<<(unsigned long);
34 OutputCharStream
&operator<<(int);
35 OutputCharStream
&operator<<(Newline
);
37 OutputCharStream(const OutputCharStream
&); // undefined
38 void operator=(const OutputCharStream
&); // undefined
40 virtual void flushBuf(Char
) = 0;
46 class SP_API EncodeOutputCharStream
: public OutputCharStream
,
47 private Encoder::Handler
{
49 EncodeOutputCharStream();
50 // the OutputByteStream will not be deleted
51 EncodeOutputCharStream(OutputByteStream
*, const OutputCodingSystem
*);
52 ~EncodeOutputCharStream();
53 void open(OutputByteStream
*, const OutputCodingSystem
*);
55 void setEscaper(Escaper
);
57 EncodeOutputCharStream(const EncodeOutputCharStream
&); // undefined
58 void operator=(const EncodeOutputCharStream
&); // undefined
59 EncodeOutputCharStream(OutputByteStream
*, Encoder
*);
60 void allocBuf(int bytesPerChar
);
62 void handleUnencodable(Char c
, OutputByteStream
*);
64 OutputByteStream
*byteStream_
;
66 Owner
<Encoder
> ownedEncoder_
;
70 class SP_API StrOutputCharStream
: public OutputCharStream
{
72 StrOutputCharStream();
73 ~StrOutputCharStream();
74 void extractString(StringC
&);
79 StrOutputCharStream(const StrOutputCharStream
&); // undefined
80 void operator=(const StrOutputCharStream
&); // undefined
85 class SP_API RecordOutputCharStream
: public OutputCharStream
{
87 RecordOutputCharStream(OutputCharStream
*);
88 ~RecordOutputCharStream();
90 void setEscaper(Escaper
);
92 RecordOutputCharStream(const RecordOutputCharStream
&); // undefined
93 void operator=(const RecordOutputCharStream
&); // undefined
97 OutputCharStream
*os_
;
98 enum { bufSize_
= 1024 };
103 OutputCharStream
&OutputCharStream::put(Char c
)
113 OutputCharStream
&OutputCharStream::operator<<(char c
)
119 OutputCharStream
&OutputCharStream::operator<<(Newline
)
121 put(Char(SP_LINE_TERM1
));
123 put(Char(SP_LINE_TERM2
));
129 OutputCharStream
&OutputCharStream::operator<<(const StringC
&str
)
131 return write(str
.data(), str
.size());
138 #endif /* not OutputCharStream_INCLUDED */