itextstream.h
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #if !defined(INCLUDED_ITEXTSTREAM_H)
00027 #define INCLUDED_ITEXTSTREAM_H
00028
00031
00032 #include <cstddef>
00033 #include "generic/static.h"
00034
00036 class TextInputStream
00037 {
00038 public:
00039 virtual ~TextInputStream ()
00040 {
00041 }
00042
00045 virtual std::size_t read (char* buffer, std::size_t length) = 0;
00046 };
00047
00049 class TextOutputStream
00050 {
00051 public:
00052 virtual ~TextOutputStream ()
00053 {
00054 }
00055
00058 virtual std::size_t write (const char* buffer, std::size_t length) = 0;
00059 };
00060
00062
00075 template<typename T>
00076 inline TextOutputStream& operator<< (TextOutputStream& ostream, const T& t)
00077 {
00078 return ostream_write(ostream, t);
00079 }
00080
00081 class NullOutputStream: public TextOutputStream
00082 {
00083 public:
00084 std::size_t write (const char*, std::size_t length)
00085 {
00086 return length;
00087 }
00088 };
00089
00094 class OutputStreamHolder
00095 {
00096 NullOutputStream m_nullOutputStream;
00097 TextOutputStream* m_outputStream;
00098 public:
00099 OutputStreamHolder () :
00100 m_outputStream(&m_nullOutputStream)
00101 {
00102 }
00103 void setOutputStream (TextOutputStream& outputStream)
00104 {
00105 m_outputStream = &outputStream;
00106 }
00107 TextOutputStream& getOutputStream ()
00108 {
00109 return *m_outputStream;
00110 }
00111 };
00112
00113 typedef Static<OutputStreamHolder> GlobalOutputStream;
00114
00116 inline TextOutputStream& globalOutputStream ()
00117 {
00118 return GlobalOutputStream::instance().getOutputStream();
00119 }
00120
00121 class ErrorStreamHolder: public OutputStreamHolder
00122 {
00123 };
00124 typedef Static<ErrorStreamHolder> GlobalErrorStream;
00125
00127 inline TextOutputStream& globalErrorStream ()
00128 {
00129 return GlobalErrorStream::instance().getOutputStream();
00130 }
00131
00132 class WarningStreamHolder: public OutputStreamHolder
00133 {
00134 };
00135 typedef Static<WarningStreamHolder> GlobalWarningStream;
00136
00138 inline TextOutputStream& globalWarningStream ()
00139 {
00140 return GlobalWarningStream::instance().getOutputStream();
00141 }
00142
00143 #endif