From: Christian P. <cp...@us...> - 2005-07-04 23:36:23
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1650/include/pclasses/IO Modified Files: Makefile.am Added Files: StreamBase.h DataStream.h IODeviceStreamBuffer.h StreamBuffer.h TextStream.h Log Message: - Added StreamBuffer, StreamBase - std::streams are not suitable for our needs - Added IODeviceStreamBuffer - buffers Streams and writes them to an IODevice - Added DataStream - portable data streaming - Added TextStream - unicode text streaming with on the fly codepage conversion Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Makefile.am 29 May 2005 17:48:31 -0000 1.9 +++ Makefile.am 4 Jul 2005 23:36:13 -0000 1.10 @@ -4,4 +4,5 @@ METASOURCES = AUTO pclasses_io_include_HEADERS = IOError.h IODevice.h IOStream.h IOFilter.h \ URL.h ZLib.h ZLibIOFilter.h BZip2.h BZip2IOFilter.h IORequest.h \ - IOHandler.h IOManager.h IOListener.h + IOHandler.h IOManager.h IOListener.h StreamBuffer.h IODeviceStreamBuffer.h \ + StreamBase.h DataStream.h TextStream.h --- NEW FILE: IODeviceStreamBuffer.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_IODeviceStreamBuffer_h #define P_IO_IODeviceStreamBuffer_h #include <pclasses/Export.h> #include <pclasses/CircularQueue.h> #include <pclasses/IO/IODevice.h> #include <pclasses/IO/IOError.h> #include <pclasses/IO/StreamBuffer.h> namespace P { namespace IO { class PIO_EXPORT IODeviceStreamBuffer: public StreamBuffer { public: IODeviceStreamBuffer(IODevice& dev, size_t outBufferSize = 1024, size_t inBufferSize = 1024); ~IODeviceStreamBuffer() throw(); IODevice& device() const throw(); bool eof() const throw(); void sync() throw(IOError); void write(const char* buffer, size_t count) throw(IOError); size_t read(char* buffer, size_t count) throw(IOError); private: IODevice& _device; CircularQueue<char> _outBuffer; CircularQueue<char> _inBuffer; }; } // !namespace IO } // !namespace P #endif --- NEW FILE: StreamBase.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_StreamBase_h #define P_IO_StreamBase_h #include <pclasses/Export.h> #include <pclasses/IO/IOError.h> #include <pclasses/IO/IODevice.h> #include <pclasses/IO/StreamBuffer.h> namespace P { namespace IO { class PIO_EXPORT StreamBase { public: StreamBase(IODevice& dev, size_t outBufferSize = 1024, size_t inBufferSize = 1024); StreamBase(StreamBuffer& buffer) throw(); ~StreamBase() throw(); StreamBuffer& buffer() const throw(); bool eof() const throw(); void sync() throw(IOError); void writeRaw(const char* buffer, size_t count) throw(IOError); size_t readRaw(char* buffer, size_t count) throw(IOError); private: bool _ownBuffer; StreamBuffer* _buffer; }; } // !namespace IO } // !namespace P #endif --- NEW FILE: DataStream.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_DataStream_h #define P_IO_DataStream_h #include <pclasses/Export.h> #include <pclasses/IntTypes.h> #include <pclasses/IO/IODevice.h> #include <pclasses/IO/StreamBase.h> #include <pclasses/IO/StreamBuffer.h> #include <string> namespace P { namespace IO { class PIO_EXPORT DataStream: public StreamBase { public: DataStream(IODevice& dev, size_t outBufferSize = 1024, size_t inBufferSize = 1024); DataStream(StreamBuffer& buffer) throw(); ~DataStream() throw(); enum ByteOrder { BigEndian, LittleEndian, Native }; void setByteOrder(ByteOrder b) throw(); ByteOrder byteOrder() const throw(); DataStream& operator<<(Int8 val); DataStream& operator<<(UInt8 val); DataStream& operator<<(Int16 val); DataStream& operator<<(UInt16 val); DataStream& operator<<(Int32 val); DataStream& operator<<(UInt32 val); #ifdef PCLASSES_HAVE_64BIT_INT DataStream& operator<<(Int64 val); DataStream& operator<<(UInt64 val); #endif DataStream& operator<<(float val); DataStream& operator<<(double val); #ifdef PCLASSES_HAVE_LONG_DOUBLE DataStream& operator<<(long double val); #endif DataStream& operator<<(const char* str); DataStream& operator<<(const std::string& str); DataStream& operator>>(Int8& val); DataStream& operator>>(UInt8& val); DataStream& operator>>(Int16& val); DataStream& operator>>(UInt16& val); DataStream& operator>>(Int32& val); DataStream& operator>>(UInt32& val); #ifdef PCLASSES_HAVE_64BIT_INT DataStream& operator>>(Int64& val); DataStream& operator>>(UInt64& val); #endif DataStream& operator>>(float& val); DataStream& operator>>(double& val); #ifdef PCLASSES_HAVE_LONG_DOUBLE DataStream& operator>>(long double& val); #endif DataStream& operator>>(std::string& str); DataStream& write(const char* str, size_t count) throw(IOError); DataStream& read(char*& str, size_t& count) throw(IOError); private: ByteOrder _byteOrder; }; } // !namespace IO } // !namespace P #endif --- NEW FILE: StreamBuffer.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_StreamBuffer_h #define P_IO_StreamBuffer_h #include <pclasses/Export.h> #include <pclasses/IO/IOError.h> namespace P { namespace IO { class PIO_EXPORT StreamBuffer { public: StreamBuffer(); virtual ~StreamBuffer() throw(); virtual bool eof() const throw() = 0; virtual void sync() throw(IOError) = 0; virtual void write(const char* buffer, size_t count) throw(IOError) = 0; virtual size_t read(char* buffer, size_t count) throw(IOError) = 0; }; } // !namespace IO } // !namespace P #endif --- NEW FILE: TextStream.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_TextStream_h #define P_IO_TextStream_h #include <pclasses/Export.h> #include <pclasses/IntTypes.h> #include <pclasses/IO/IODevice.h> #include <pclasses/IO/StreamBase.h> #include <pclasses/IO/StreamBuffer.h> #include <pclasses/Unicode/String.h> #include <pclasses/Unicode/Converter.h> namespace P { namespace IO { class PIO_EXPORT TextStream: public StreamBase { public: TextStream(IODevice& dev, size_t outBufferSize = 1024, size_t inBufferSize = 1024); TextStream(StreamBuffer& buffer) throw(); ~TextStream() throw(); //! Number format enum Format { Hex, /*!< Print numbers in hexadecimal format */ Dec, /*!< Print numbers in decimal format */ Oct /*!< Print numbers in octal fomat */ }; //! Set number-format void setFormat(Format fmt) throw(); //! Set width of numbers void setWidth(unsigned int width) throw(); //! Set floating-point precision void setPrecision(unsigned int prec) throw(); //! Set fill-character void setFill(Unicode::Char ch) throw(); void setCodepage(const char* cp); TextStream& operator<<(Int8 val); TextStream& operator<<(UInt8 val); TextStream& operator<<(Int16 val); TextStream& operator<<(UInt16 val); TextStream& operator<<(Int32 val); TextStream& operator<<(UInt32 val); #ifdef PCLASSES_HAVE_64BIT_INT TextStream& operator<<(Int64 val); TextStream& operator<<(UInt64 val); #endif TextStream& operator<<(float val); TextStream& operator<<(double val); #ifdef PCLASSES_HAVE_LONG_DOUBLE TextStream& operator<<(long double val); #endif TextStream& operator<<(TextStream& (*pfn)(TextStream& strm)); TextStream& operator<<(const Unicode::Char& ch); TextStream& operator<<(const Unicode::String& str); TextStream& operator<<(const char* str); TextStream& operator<<(const std::string& str); TextStream& operator>>(Int8& val); TextStream& operator>>(UInt8& val); TextStream& operator>>(Int16& val); TextStream& operator>>(UInt16& val); TextStream& operator>>(Int32& val); TextStream& operator>>(UInt32& val); #ifdef PCLASSES_HAVE_64BIT_INT TextStream& operator>>(Int64& val); TextStream& operator>>(UInt64& val); #endif TextStream& operator>>(float& val); TextStream& operator>>(double& val); #ifdef PCLASSES_HAVE_LONG_DOUBLE TextStream& operator>>(long double& val); #endif TextStream& operator>>(Unicode::Char& ch); TextStream& operator>>(Unicode::String& str); TextStream& operator>>(std::string& str); private: Format _fmt; unsigned int _width, _prec; Unicode::Char _fillCh; Unicode::Converter* _converter; }; PUNICODE_EXPORT TextStream& endl(TextStream& strm); PUNICODE_EXPORT TextStream& dec(TextStream& strm); PUNICODE_EXPORT TextStream& hex(TextStream& strm); PUNICODE_EXPORT TextStream& oct(TextStream& strm); } // !namespace IO } // !namespace P #endif |