00001 /*****************************************************************************
00002 * Author: Valient Gough <vgough@pobox.com>
00003 *
00004 *****************************************************************************
00005 * Copyright (c) 2001, Valient Gough
00006 *
00007 * This library is free software; you can distribute it and/or modify it under
00008 * the terms of the GNU Lesser General Public License (LGPL), as published by
00009 * the Free Software Foundation; either version 2.1 of the License, or (at your
00010 * option) any later version.
00011 *
00012 * This library is distributed in the hope that it will be useful, but WITHOUT
00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 * FITNESS FOR A PARTICULAR PURPOSE. See the LGPL in the file COPYING for more
00015 * details.
00016 *
00017 */
00018
00019 #ifndef _StringIODevice_incl_
00020 #define _StringIODevice_incl_
00021
00022 #include <rel/IODevice.h>
00023 #include <string>
00024
00025 namespace rel
00026 {
00027
00028 class TypeStream;
00029
00030 /*
00031 StringIODevice implements the IODevice interface to store data in
00032 memory in a string. Writes append to the end of the string, and reads
00033 happen at the current location ( at() ).
00034 */
00035 class StringIODevice : public IODevice
00036 {
00037 public:
00038 StringIODevice();
00039 StringIODevice(const StringIODevice &src);
00040 ~StringIODevice();
00041
00042 StringIODevice &operator = (const StringIODevice &src);
00043
00047 virtual size_type writeBytes(const char *data, size_type len);
00048
00053 virtual size_type readBytes(char *data, size_type maxLen);
00054
00055 // return true if at end of stream
00056 virtual bool atEnd() const;
00057
00058
00059 // return current location in stream
00060 virtual size_type at() const;
00061
00062 // change location in stream
00063 virtual bool at(size_type offset);
00064
00065 // display output in human readable form..
00066 virtual SmartPtr<char*> print();
00067
00068 // remove anything in the stream
00069 void clear();
00070
00071 bool writeToStream(TypeStream &output) const;
00072 bool readFromStream(const TypeStream &input);
00073
00074 private:
00075 std::string fData;
00076 size_type fOffset;
00077 size_type fSize;
00078 };
00079
00080 } // namespace rel
00081
00082
00083 rel::TypeStream &operator << (rel::TypeStream &output,
00084 const rel::StringIODevice &src);
00085 const rel::TypeStream &operator >> (const rel::TypeStream &input,
00086 rel::StringIODevice &src);
00087
00088 #endif
1.2.10 written by Dimitri van Heesch,
© 1997-2001