00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _textstream_h
00018 #define _textstream_h
00019
00020 #include <spl/types.h>
00021 #include <spl/Debug.h>
00022 #include <spl/collection/Array.h>
00023 #include <spl/io/IStream.h>
00024 #include <spl/Memory.h>
00025 #include <spl/RefCountPtr.h>
00026 #include <spl/String.h>
00027 #include <spl/text/StringBuffer.h>
00028
00035 class TextWriter;
00036 typedef RefCountPtr<TextWriter> TextWriterPtr;
00037 typedef WeakReference<TextWriter, TextWriterPtr> TextWriterRef;
00038
00039 REGISTER_TYPEOF(137, TextWriterPtr);
00040 REGISTER_TYPEOF( 468, TextWriterRef );
00041
00045 class TextWriter : public IMemoryValidate
00046 {
00047 private:
00048
00049 inline TextWriter(const TextWriter& tw) {}
00050 inline void operator =(const TextWriter& tw) {}
00051
00052 protected:
00053 spl::IStreamPtr m_strm;
00054
00055 public:
00056 TextWriter(spl::IStreamPtr strm);
00057 virtual ~TextWriter();
00058
00059 void Close();
00060 void Flush();
00061 void Write(byte b);
00062 void Write(int8 i);
00063 void Write(int16 i);
00064 void Write(int32 i);
00065 void Write(int64 i);
00066 void Write(uint16 i);
00067 void Write(uint32 i);
00068 void Write(float32 f);
00069 void Write(float64 f);
00070 void Write(Array<char>& buf);
00071 void Write(const String& str);
00072 void WriteFormat(const String fmt, ...);
00073 void WriteLine(const String& str);
00074
00075 #ifdef DEBUG
00076 virtual void ValidateMem() const;
00077 virtual void CheckMem() const;
00078 #endif
00079 };
00080
00081 REGISTER_TYPEOF(138, TextWriter);
00082
00083 class TextReader;
00084 typedef RefCountPtr<TextReader> TextReaderPtr;
00085 typedef WeakReference<TextReader, TextReaderPtr> TextReaderRef;
00086
00087 REGISTER_TYPEOF(140, TextReaderPtr);
00088 REGISTER_TYPEOF( 469, TextReaderRef );
00089
00090 class TextReader : public IMemoryValidate
00091 {
00092 private:
00093
00094 inline TextReader(const TextReader& pmp) {}
00095 inline void operator =(const TextReader& pmp) {}
00096
00097 private:
00098 inline int _Read()
00099 {
00100 if ( m_peekch > -1 )
00101 {
00102 int ch = m_peekch;
00103 m_peekch = -1;
00104 return ch;
00105 }
00106 return m_strm->ReadByte();
00107 }
00108
00109 protected:
00110 spl::IStreamPtr m_strm;
00111 int m_peekch;
00112
00113 public:
00114 TextReader(spl::IStreamPtr strm);
00115 virtual ~TextReader();
00116
00117 void Close();
00118 int Peek();
00119 int Read();
00120 int ReadBlock(Array<byte>& buf, int offset, int count);
00121 bool ReadLine(StringBuffer& sb);
00122 StringPtr ReadLine();
00123 bool ReadLine(Array<byte>& buf, int& lineLen);
00124 StringPtr ReadToEnd();
00125
00126 inline bool CanRead() const { return m_strm->CanRead(); }
00127 inline int Length() const { return m_strm->Length(); }
00128
00129 #ifdef DEBUG
00130 virtual void ValidateMem() const;
00131 virtual void CheckMem() const;
00132 #endif
00133 };
00134
00135 REGISTER_TYPEOF(142, TextReader);
00136
00139 #endif