Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

# OgreDataStream.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __DataStream_H__
    00030 #define __DataStream_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreString.h"
    00034 #include "OgreSharedPtr.h"
    00035 #include <istream>
    00036
    00037 namespace Ogre {
    00038
    00058     class _OgreExport DataStream
    00059     {
    00060     protected:
    00062         String mName;
    00064         size_t mSize;
    00065         #define OGRE_STREAM_TEMP_SIZE 128
    00066     public:
    00068         DataStream() : mSize(0) {}
    00070         DataStream(const String& name) : mName(name), mSize(0) {}
    00072         const String& getName(void) { return mName; }
    00073         virtual ~DataStream() {}
    00074         // Streaming operators
    00075         template<typename T> DataStream& operator>>(T& val);
    00082         virtual size_t read(void* buf, size_t count) = 0;
    00097         virtual size_t readLine(char* buf, size_t maxCount, const String& delim = "\n");
    00098
    00113         virtual String getLine( bool trimAfter = true );
    00114
    00120         virtual String getAsString(void);
    00121
    00129         virtual size_t skipLine(const String& delim = "\n");
    00130
    00133         virtual void skip(long count) = 0;
    00134
    00137         virtual void seek( size_t pos ) = 0;
    00138
    00140         virtual size_t tell(void) const = 0;
    00141
    00144         virtual bool eof(void) const = 0;
    00145
    00149         size_t size(void) const { return mSize; }
    00150
    00152         virtual void close(void) = 0;
    00153
    00154
    00155     };
    00156
    00160     typedef SharedPtr<DataStream> DataStreamPtr;
    00161
    00163     typedef std::list<DataStreamPtr> DataStreamList;
    00165     typedef SharedPtr<DataStreamList> DataStreamListPtr;
    00166
    00169     class _OgreExport MemoryDataStream : public DataStream
    00170     {
    00171     protected:
    00173         uchar* mData;
    00175         uchar* mPos;
    00177         uchar* mEnd;
    00179         bool mFreeOnClose;
    00180     public:
    00181
    00188         MemoryDataStream(void* pMem, size_t size, bool freeOnClose = false);
    00189
    00197         MemoryDataStream(const String& name, void* pMem, size_t size,
    00198                 bool freeOnClose = false);
    00199
    00210         MemoryDataStream(DataStream& sourceStream,
    00211                 bool freeOnClose = true);
    00212
    00223         MemoryDataStream(DataStreamPtr& sourceStream,
    00224                 bool freeOnClose = true);
    00225
    00238         MemoryDataStream(const String& name, DataStream& sourceStream,
    00239                 bool freeOnClose = true);
    00240
    00253         MemoryDataStream(const String& name, const DataStreamPtr& sourceStream,
    00254             bool freeOnClose = true);
    00255
    00261         MemoryDataStream(size_t size, bool freeOnClose = true);
    00268         MemoryDataStream(const String& name, size_t size,
    00269                 bool freeOnClose = true);
    00270
    00271         ~MemoryDataStream();
    00272
    00274         uchar* getPtr(void) { return mData; }
    00275
    00277         uchar* getCurrentPtr(void) { return mPos; }
    00278
    00281         size_t read(void* buf, size_t count);
    00284         size_t readLine(char* buf, size_t maxCount, const String& delim = "\n");
    00285
    00288         size_t skipLine(const String& delim = "\n");
    00289
    00292         void skip(long count);
    00293
    00296         void seek( size_t pos );
    00297
    00300         size_t tell(void) const;
    00301
    00304         bool eof(void) const;
    00305
    00308         void close(void);
    00309
    00311         void setFreeOnClose(bool free) { mFreeOnClose = free; }
    00312     };
    00313
    00317     typedef SharedPtr<MemoryDataStream> MemoryDataStreamPtr;
    00318
    00322     class _OgreExport FileStreamDataStream : public DataStream
    00323     {
    00324     protected:
    00326         std::ifstream* mpStream;
    00327         bool mFreeOnClose;
    00328     public:
    00334         FileStreamDataStream(std::ifstream* s,
    00335             bool freeOnClose = true);
    00342         FileStreamDataStream(const String& name,
    00343             std::ifstream* s,
    00344             bool freeOnClose = true);
    00345
    00358         FileStreamDataStream(const String& name,
    00359             std::ifstream* s,
    00360             size_t size,
    00361             bool freeOnClose = true);
    00362
    00363         ~FileStreamDataStream();
    00364
    00367         size_t read(void* buf, size_t count);
    00370         size_t readLine(char* buf, size_t maxCount, const String& delim = "\n");
    00371
    00374         void skip(long count);
    00375
    00378         void seek( size_t pos );
    00379
    00382         size_t tell(void) const;
    00383
    00386         bool eof(void) const;
    00387
    00390         void close(void);
    00391
    00392
    00393     };
    00394
    00404     class _OgreExport FileHandleDataStream : public DataStream
    00405     {
    00406     protected:
    00407         FILE* mFileHandle;
    00408     public:
    00410         FileHandleDataStream(FILE* handle);
    00412         FileHandleDataStream(const String& name, FILE* handle);
    00413         ~FileHandleDataStream();
    00414
    00417         size_t read(void* buf, size_t count);
    00418
    00421         void skip(long count);
    00422
    00425         void seek( size_t pos );
    00426
    00429         size_t tell(void) const;
    00430
    00433         bool eof(void) const;
    00434
    00437         void close(void);
    00438
    00439     };
    00440 }
    00441 #endif
    00442

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 30 10:50:56 2007