itextstream.h

Go to the documentation of this file.
00001 
00005 /*
00006  Copyright (C) 2001-2006, William Joseph.
00007  All Rights Reserved.
00008 
00009  This file is part of GtkRadiant.
00010 
00011  GtkRadiant is free software; you can redistribute it and/or modify
00012  it under the terms of the GNU General Public License as published by
00013  the Free Software Foundation; either version 2 of the License, or
00014  (at your option) any later version.
00015 
00016  GtkRadiant is distributed in the hope that it will be useful,
00017  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  GNU General Public License for more details.
00020 
00021  You should have received a copy of the GNU General Public License
00022  along with GtkRadiant; if not, write to the Free Software
00023  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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

Generated by  doxygen 1.6.2