1 // Common/StdOutStream.h
2 
3 #ifndef __COMMON_STD_OUT_STREAM_H
4 #define __COMMON_STD_OUT_STREAM_H
5 
6 #include <stdio.h>
7 
8 #include "MyString.h"
9 #include "MyTypes.h"
10 
11 class CStdOutStream
12 {
13   FILE *_stream;
14   bool _streamIsOpen;
15 public:
16   bool IsTerminalMode;
17   int CodePage;
18 
19   CStdOutStream(FILE *stream = 0):
_stream(stream)20       _stream(stream),
21       _streamIsOpen(false),
22       IsTerminalMode(false),
23       CodePage(-1)
24       {};
25 
~CStdOutStream()26   ~CStdOutStream() { Close(); }
27 
28   // void AttachStdStream(FILE *stream) { _stream  = stream; _streamIsOpen = false; }
29   // bool IsDefined() const { return _stream  != NULL; }
30 
31   operator FILE *() { return _stream; }
32   bool Open(const char *fileName) throw();
33   bool Close() throw();
34   bool Flush() throw();
35 
36   CStdOutStream & operator<<(CStdOutStream & (* func)(CStdOutStream  &))
37   {
38     (*func)(*this);
39     return *this;
40   }
41 
42   CStdOutStream & operator<<(const char *s) throw()
43   {
44     fputs(s, _stream);
45     return *this;
46   }
47 
48   CStdOutStream & operator<<(char c) throw()
49   {
50     fputc((unsigned char)c, _stream);
51     return *this;
52   }
53 
54   CStdOutStream & operator<<(Int32 number) throw();
55   CStdOutStream & operator<<(Int64 number) throw();
56   CStdOutStream & operator<<(UInt32 number) throw();
57   CStdOutStream & operator<<(UInt64 number) throw();
58 
59   CStdOutStream & operator<<(const wchar_t *s);
60   void PrintUString(const UString &s, AString &temp);
61   void Convert_UString_to_AString(const UString &src, AString &dest);
62 
63   void Normalize_UString__LF_Allowed(UString &s);
64   void Normalize_UString(UString &s);
65 
66   void NormalizePrint_UString(const UString &s, UString &tempU, AString &tempA);
67   void NormalizePrint_UString(const UString &s);
68   void NormalizePrint_wstr(const wchar_t *s);
69 };
70 
71 CStdOutStream & endl(CStdOutStream & outStream) throw();
72 
73 extern CStdOutStream g_StdOut;
74 extern CStdOutStream g_StdErr;
75 
76 #endif
77