00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : TextOutputStream 00006 * Package : Zeus.ZeusBase.System 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef TextOutputStreamH 00033 #define TextOutputStreamH 00034 00035 #include <zeusbase/System/FilterOutputStream.h> 00036 00037 BEGIN_NAMESPACE_Zeus 00038 00039 #if defined(ENABLE_LINUX_BINDING) 00040 #define DEFAULT_USE_CARRIGERETURN false 00041 #else 00042 #define DEFAULT_USE_CARRIGERETURN true 00043 #endif 00044 00045 /*****************************************************************************/ 00053 /*****************************************************************************/ 00054 zeusbase_class TTextOutputStream : public TFilterOutputStream 00055 { 00056 public: 00057 /*************************************************************************/ 00060 /*************************************************************************/ 00061 enum EEncodingType 00062 { 00063 etISO_8859_1 = 1, 00064 etUTF_16 = 2, 00065 etUTF_16be = 3 00066 }; 00067 00068 TTextOutputStream(IOutputStream& rParentStream, 00069 EEncodingType eEncoding = etUTF_16, 00070 bool bUseCarrigeReturn = DEFAULT_USE_CARRIGERETURN); 00071 00072 TTextOutputStream(const IString& rFileName, bool bAppend, 00073 EEncodingType eEncoding = etUTF_16, 00074 bool bUseCarrigeReturn = DEFAULT_USE_CARRIGERETURN); 00075 00076 EEncodingType getEncodingType() const; 00077 Retval writeLine(const IString& rLine); 00078 Retval writeText(const IString& rText); 00079 00080 //Methods of IOutputStream 00081 virtual Retval MQUALIFIER write(const char* pBuffer, Int iBufferSize); 00082 virtual Retval MQUALIFIER writeInt8(Int8 cData); 00083 virtual void MQUALIFIER flush(); 00084 00085 protected: 00086 virtual ~TTextOutputStream(); 00087 00088 //Methods of IOutputStream 00089 inline virtual Retval MQUALIFIER writeInt16(Int16) { return RET_REQUEST_FAILED; } 00090 inline virtual Retval MQUALIFIER writeInt32(Int32) { return RET_REQUEST_FAILED; } 00091 inline virtual Retval MQUALIFIER writeInt64(const Int64&) { return RET_REQUEST_FAILED; } 00092 inline virtual Retval MQUALIFIER writeUint16(Uint16) { return RET_REQUEST_FAILED; } 00093 inline virtual Retval MQUALIFIER writeUint32(Uint32) { return RET_REQUEST_FAILED; } 00094 inline virtual Retval MQUALIFIER writeUint64(const Uint64&) { return RET_REQUEST_FAILED; } 00095 inline virtual Retval MQUALIFIER writeFloat32(Float32) { return RET_REQUEST_FAILED; } 00096 inline virtual Retval MQUALIFIER writeFloat64(const Float64&) { return RET_REQUEST_FAILED; } 00097 inline virtual Retval MQUALIFIER writeBool(bool) { return RET_REQUEST_FAILED; } 00098 inline virtual Retval MQUALIFIER writeArray(const IByteArray&) { return RET_REQUEST_FAILED; } 00099 inline virtual Retval MQUALIFIER writeString(const IString&) { return RET_REQUEST_FAILED; } 00100 00101 private: 00102 void writeHeader(); 00103 00104 //Encoding of a text file 00105 EEncodingType m_eEncoding; 00107 bool m_bUseCarrigeReturn; 00109 Uint m_uiCharCount; 00111 char m_cBufferedChar; 00112 00113 }; 00114 00115 //INLINE METHODS 00116 /*****************************************************************************/ 00119 /*****************************************************************************/ 00120 inline TTextOutputStream::EEncodingType TTextOutputStream::getEncodingType() const 00121 { 00122 return m_eEncoding; 00123 } 00124 00125 END_NAMESPACE_Zeus 00126 //--------------------------------------------------------------------------- 00127 #endif