Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://visualizationlibrary.org */ 00005 /* */ 00006 /* Copyright (c) 2005-2010, Michele Bosi */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without modification, */ 00010 /* are permitted provided that the following conditions are met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, this */ 00013 /* list of conditions and the following disclaimer. */ 00014 /* */ 00015 /* - Redistributions in binary form must reproduce the above copyright notice, this */ 00016 /* list of conditions and the following disclaimer in the documentation and/or */ 00017 /* other materials provided with the distribution. */ 00018 /* */ 00019 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 00020 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 00021 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 00022 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */ 00023 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 00024 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 00025 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ 00026 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00027 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 00028 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00029 /* */ 00030 /**************************************************************************************/ 00031 00032 #ifndef File_INCLUDE_ONCE 00033 #define File_INCLUDE_ONCE 00034 00035 #include <vlCore/Object.hpp> 00036 #include <vlCore/vlnamespace.hpp> 00037 #include <vlCore/String.hpp> 00038 #include <vlCore/MD5CheckSum.hpp> 00039 #include <map> 00040 00041 namespace vl 00042 { 00043 00044 //--------------------------------------------------------------------------- 00045 // VirtualFile 00046 //--------------------------------------------------------------------------- 00060 class VLCORE_EXPORT VirtualFile: public Object 00061 { 00062 VL_INSTRUMENT_ABSTRACT_CLASS(vl::VirtualFile, Object) 00063 00064 protected: 00065 VirtualFile(const VirtualFile& other): Object(other) {} 00066 00067 public: 00069 VirtualFile() {} 00070 00072 unsigned int crc32(); 00073 00075 MD5CheckSum md5(); 00076 00078 virtual bool open(EOpenMode mode) = 0; 00079 00081 virtual bool isOpen() const = 0; 00082 00084 virtual bool exists() const = 0; 00085 00087 virtual void close() = 0; 00088 00090 virtual long long size() const = 0; 00091 00093 virtual ref<VirtualFile> clone() const = 0; 00094 00095 VirtualFile& operator=(const VirtualFile& other) { super::operator=(other); mPath = other.mPath; return *this; } 00096 00098 const String& path() const { return mPath; } 00099 00101 void setPath(const String& name) { mPath = name; mPath.normalizeSlashes(); } 00102 00105 long long peek(void* buffer, long long byte_count); 00106 00108 long long read(void* buffer, long long byte_count); 00109 00111 long long write(const void* buffer, long long byte_count); 00112 00114 long long position() const; 00115 00117 bool seekSet(long long offset); 00118 00120 bool seekCur(long long offset); 00121 00123 bool seekEnd(long long offset); 00124 00126 bool endOfFile() const { return position() >= size(); } 00127 00131 long long load(std::vector<char>& data); 00132 00136 long long load(void* buffer, long long max=-1); 00137 00139 double readDouble(bool little_endian_data=true); 00141 float readFloat (bool little_endian_data=true); 00143 unsigned long long readUInt64(bool little_endian_data=true); 00145 long long readSInt64(bool little_endian_data=true); 00147 unsigned int readUInt32(bool little_endian_data=true); 00149 int readSInt32(bool little_endian_data=true); 00151 unsigned short readUInt16(bool little_endian_data=true); 00153 short readSInt16(bool little_endian_data=true); 00155 unsigned char readUInt8(); 00157 char readSInt8(); 00158 00160 long long readDouble(double* buffer, long long count, bool little_endian_data=true); 00162 long long readFloat (float* buffer, long long count, bool little_endian_data=true); 00164 long long readUInt64(unsigned long long* buffer, long long count, bool little_endian_data=true); 00166 long long readSInt64(long long* buffer, long long count, bool little_endian_data=true); 00168 long long readUInt32(unsigned int* buffer, long long count, bool little_endian_data=true); 00170 long long readSInt32(int* buffer, long long count, bool little_endian_data=true); 00172 long long readUInt16(unsigned short* buffer, long long count, bool little_endian_data=true); 00174 long long readSInt16(short* buffer, long long count, bool little_endian_data=true); 00176 long long readUInt8 (unsigned char* buffer, long long count); 00178 long long readSInt8 (char* buffer, long long count); 00179 00181 long long writeDouble(double data, bool little_endian_data=true); 00183 long long writeFloat (float data, bool little_endian_data=true); 00185 long long writeUInt64(unsigned long long data, bool little_endian_data=true); 00187 long long writeSInt64(long long data, bool little_endian_data=true); 00189 long long writeUInt32(unsigned int data, bool little_endian_data=true); 00191 long long writeSInt32(int data, bool little_endian_data=true); 00193 long long writeUInt16(unsigned short data, bool little_endian_data=true); 00195 long long writeSInt16(short data, bool little_endian_data=true); 00197 long long writeUInt8 (unsigned char data); 00199 long long writeSInt8 (char data); 00200 00202 long long writeDouble(const double* buffer, long long count, bool little_endian_data=true); 00204 long long writeFloat (const float* buffer, long long count, bool little_endian_data=true); 00206 long long writeUInt64(const unsigned long long* buffer, long long count, bool little_endian_data=true); 00208 long long writeSInt64(const long long* buffer, long long count, bool little_endian_data=true); 00210 long long writeUInt32(const unsigned int* buffer, long long count, bool little_endian_data=true); 00212 long long writeSInt32(const int* buffer, long long count, bool little_endian_data=true); 00214 long long writeUInt16(const unsigned short* buffer, long long count, bool little_endian_data=true); 00216 long long writeSInt16(const short* buffer, long long count, bool little_endian_data=true); 00218 long long writeUInt8 (const unsigned char* buffer, long long count); 00220 long long writeSInt8 (const char* buffer, long long count); 00221 00222 protected: 00223 virtual long long read_Implementation(void* buffer, long long byte_count) = 0; 00224 virtual long long write_Implementation(const void* buffer, long long byte_count) = 0; 00225 virtual long long position_Implementation() const = 0; 00226 virtual bool seekSet_Implementation(long long offset) = 0; 00227 00228 protected: 00229 long long write64(const void* buffer, long long count, bool little_endian_data=true); 00230 long long write32(const void* buffer, long long count, bool little_endian_data=true); 00231 long long write16(const void* buffer, long long count, bool little_endian_data=true); 00232 00233 long long read64(void* buffer, long long count, bool little_endian_data=true); 00234 long long read32(void* buffer, long long count, bool little_endian_data=true); 00235 long long read16(void* buffer, long long count, bool little_endian_data=true); 00236 00237 long long write64(const void* buffer, bool little_endian_data=true); 00238 long long write32(const void* buffer, bool little_endian_data=true); 00239 long long write16(const void* buffer, bool little_endian_data=true); 00240 00241 long long read64(void* buffer, bool little_endian_data=true); 00242 long long read32(void* buffer, bool little_endian_data=true); 00243 long long read16(void* buffer, bool little_endian_data=true); 00244 00245 protected: 00246 String mPath; 00247 }; 00248 //----------------------------------------------------------------------------- 00250 VLCORE_EXPORT ref<VirtualFile> locateFile(const String& path); 00251 //----------------------------------------------------------------------------- 00252 } 00253 00254 #endif