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-2005 The OGRE Team 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 */ 00025 #ifndef __DataStream_H__ 00026 #define __DataStream_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 #include "OgreString.h" 00030 #include "OgreSharedPtr.h" 00031 #include <istream> 00032 00033 namespace Ogre { 00034 00054 class _OgreExport DataStream 00055 { 00056 protected: 00058 String mName; 00060 size_t mSize; 00061 #define OGRE_STREAM_TEMP_SIZE 128 00062 public: 00064 DataStream() : mSize(0) {} 00066 DataStream(const String& name) : mName(name), mSize(0) {} 00068 const String& getName(void) { return mName; } 00069 virtual ~DataStream() {} 00070 // Streaming operators 00071 template<typename T> DataStream& operator>>(T& val); 00078 virtual size_t read(void* buf, size_t count) = 0; 00093 virtual size_t readLine(char* buf, size_t maxCount, const String& delim = "\n"); 00094 00109 virtual String getLine( bool trimAfter = true ); 00110 00116 virtual String getAsString(void); 00117 00125 virtual size_t skipLine(const String& delim = "\n"); 00126 00129 virtual void skip(long count) = 0; 00130 00133 virtual void seek( size_t pos ) = 0; 00134 00136 virtual size_t tell(void) const = 0; 00137 00140 virtual bool eof(void) const = 0; 00141 00145 size_t size(void) const { return mSize; } 00146 00148 virtual void close(void) = 0; 00149 00150 00151 }; 00152 00156 typedef SharedPtr<DataStream> DataStreamPtr; 00157 00159 typedef std::list<DataStreamPtr> DataStreamList; 00161 typedef SharedPtr<DataStreamList> DataStreamListPtr; 00162 00165 class _OgreExport MemoryDataStream : public DataStream 00166 { 00167 protected: 00169 uchar* mData; 00171 uchar* mPos; 00173 uchar* mEnd; 00175 bool mFreeOnClose; 00176 public: 00177 00184 MemoryDataStream(void* pMem, size_t size, bool freeOnClose = false); 00185 00193 MemoryDataStream(const String& name, void* pMem, size_t size, 00194 bool freeOnClose = false); 00195 00206 MemoryDataStream(DataStream& sourceStream, 00207 bool freeOnClose = true); 00208 00219 MemoryDataStream(DataStreamPtr& sourceStream, 00220 bool freeOnClose = true); 00221 00234 MemoryDataStream(const String& name, DataStream& sourceStream, 00235 bool freeOnClose = true); 00236 00249 MemoryDataStream(const String& name, const DataStreamPtr& sourceStream, 00250 bool freeOnClose = true); 00251 00257 MemoryDataStream(size_t size, bool freeOnClose = true); 00264 MemoryDataStream(const String& name, size_t size, 00265 bool freeOnClose = true); 00266 00267 ~MemoryDataStream(); 00268 00270 uchar* getPtr(void) { return mData; } 00271 00273 uchar* getCurrentPtr(void) { return mPos; } 00274 00277 size_t read(void* buf, size_t count); 00280 size_t readLine(char* buf, size_t maxCount, const String& delim = "\n"); 00281 00284 size_t skipLine(const String& delim = "\n"); 00285 00288 void skip(long count); 00289 00292 void seek( size_t pos ); 00293 00296 size_t tell(void) const; 00297 00300 bool eof(void) const; 00301 00304 void close(void); 00305 00307 void setFreeOnClose(bool free) { mFreeOnClose = free; } 00308 }; 00309 00313 typedef SharedPtr<MemoryDataStream> MemoryDataStreamPtr; 00314 00318 class _OgreExport FileStreamDataStream : public DataStream 00319 { 00320 protected: 00322 std::ifstream* mpStream; 00323 bool mFreeOnClose; 00324 public: 00330 FileStreamDataStream(std::ifstream* s, 00331 bool freeOnClose = true); 00338 FileStreamDataStream(const String& name, 00339 std::ifstream* s, 00340 bool freeOnClose = true); 00341 00354 FileStreamDataStream(const String& name, 00355 std::ifstream* s, 00356 size_t size, 00357 bool freeOnClose = true); 00358 00359 ~FileStreamDataStream(); 00360 00363 size_t read(void* buf, size_t count); 00366 size_t readLine(char* buf, size_t maxCount, const String& delim = "\n"); 00367 00370 void skip(long count); 00371 00374 void seek( size_t pos ); 00375 00378 size_t tell(void) const; 00379 00382 bool eof(void) const; 00383 00386 void close(void); 00387 00388 00389 }; 00390 00400 class _OgreExport FileHandleDataStream : public DataStream 00401 { 00402 protected: 00403 FILE* mFileHandle; 00404 public: 00406 FileHandleDataStream(FILE* handle); 00408 FileHandleDataStream(const String& name, FILE* handle); 00409 ~FileHandleDataStream(); 00410 00413 size_t read(void* buf, size_t count); 00414 00417 void skip(long count); 00418 00421 void seek( size_t pos ); 00422 00425 size_t tell(void) const; 00426 00429 bool eof(void) const; 00430 00433 void close(void); 00434 00435 }; 00436 } 00437 #endif 00438
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 23 10:05:37 2006