Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members
E:/Programming/MyProject/K_Game_hg/GameEngine/include/resource/DataStream.h
Go to the documentation of this file.
00001 // Copyright 2006-2011 by Kat'Oun
00002 
00003 #ifndef _DATA_STREAM_H_
00004 #define _DATA_STREAM_H_
00005 
00006 #include <EngineConfig.h>
00007 #include <core/Types.h>
00008 
00009 #include <string>
00010 
00011 namespace platform
00012 {
00013 class File;
00014 }
00015 
00016 namespace resource
00017 {
00018 
00019 #define GAME_STREAM_TEMP_SIZE 128
00020 
00026 class ENGINE_PUBLIC_EXPORT DataStream
00027 {
00028 public:
00029 
00030         DataStream();
00031         virtual ~DataStream();
00032 
00037         virtual u32 read(void* buffer, u32 size) = 0;
00038         virtual u32 read(void* buffer, u32 size, u32 count) = 0;
00039 
00045         virtual u32 readLine(char* buffer, u32 size, const std::string& delim = "\n");
00046 
00051         virtual std::string getLine(bool trimAfter = true);
00052 
00054         virtual u32 skipLine(const std::string& delim = "\n");
00055 
00057         virtual void seek(u32 pos) = 0;
00058 
00061         virtual void skip(s32 offset) = 0;
00062 
00064         virtual u32 tell() const = 0;
00065 
00067         virtual bool eof() = 0;
00068 
00070         u32 size() const;
00071 
00072 protected:
00073         
00074         u32 mSize;
00075 };
00076 
00078 class ENGINE_PUBLIC_EXPORT MemoryDataStream: public DataStream
00079 {
00080 public:
00081 
00086         MemoryDataStream(void* mem, u32 size, bool freeOnClose = false);
00093         MemoryDataStream(DataStream& sourceStream, bool freeOnClose = true);
00097         MemoryDataStream(u32 size, bool freeOnClose = true);
00098         ~MemoryDataStream();
00099 
00101         u8* getPtr();
00102 
00104         u8* getCurrentPtr();
00105 
00106         u32 read(void* buffer, u32 size);
00107         u32 read(void* buffer, u32 size, u32 count);
00108 
00109         u32 readLine(c8* buffer, u32 size, const std::string& delim = "\n");
00110 
00111         u32 skipLine(const std::string& delim = "\n");
00112 
00113         void seek(u32 pos);
00114 
00115         void skip(s32 offset);
00116 
00117         u32 tell() const;
00118 
00119         bool eof();
00120 
00121         void close();
00122 
00123 protected:
00124 
00125         u8* mData;                      // Pointer to the start of the data area
00126         u8* mPos;                       // Pointer to the current position in the memory
00127         u8* mEnd;                       // Pointer to the end of the memory
00128         bool mFreeOnClose;      // Do we delete the memory on close
00129 };
00130 
00132 class ENGINE_PUBLIC_EXPORT FileDataStream: public DataStream
00133 {
00134 public:
00135 
00137         FileDataStream(const std::string& fileName);
00138         ~FileDataStream();
00139 
00140         u32 read(void* buffer, u32 size);
00141         u32 read(void* buffer, u32 size, u32 count);
00142 
00143         void seek(u32 pos);
00144 
00145         void skip(s32 offset);
00146 
00147         u32 tell() const;
00148 
00149         bool eof();
00150 
00151 protected:
00152 
00153         platform::File* mFile;  // Pointer to the file
00154 };
00155 
00156 }// end namespace resource
00157 
00158 #endif

The KG Game Engine
The KG Game Engine Documentation © 2006-2011 by Kat'Oun. Generated on Sat Jul 2 2011 00:50:05 by Doxygen (1.7.4)