Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
VirtualFile.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef File_INCLUDE_ONCE
33 #define File_INCLUDE_ONCE
34 
35 #include <vlCore/Object.hpp>
36 #include <vlCore/vlnamespace.hpp>
37 #include <vlCore/String.hpp>
38 #include <vlCore/MD5CheckSum.hpp>
39 #include <map>
40 
41 namespace vl
42 {
43 
44 //---------------------------------------------------------------------------
45 // VirtualFile
46 //---------------------------------------------------------------------------
61  {
63 
64  protected:
65  VirtualFile(const VirtualFile& other): Object(other) {}
66 
67  public:
70 
72  unsigned int crc32();
73 
75  MD5CheckSum md5();
76 
78  virtual bool open(EOpenMode mode) = 0;
79 
81  virtual bool isOpen() const = 0;
82 
84  virtual bool exists() const = 0;
85 
87  virtual void close() = 0;
88 
90  virtual long long size() const = 0;
91 
93  virtual ref<VirtualFile> clone() const = 0;
94 
95  VirtualFile& operator=(const VirtualFile& other) { super::operator=(other); mPath = other.mPath; return *this; }
96 
98  const String& path() const { return mPath; }
99 
101  void setPath(const String& name) { mPath = name; mPath.normalizeSlashes(); }
102 
105  long long peek(void* buffer, long long byte_count);
106 
108  long long read(void* buffer, long long byte_count);
109 
111  long long write(const void* buffer, long long byte_count);
112 
114  long long position() const;
115 
117  bool seekSet(long long offset);
118 
120  bool seekCur(long long offset);
121 
123  bool seekEnd(long long offset);
124 
126  bool endOfFile() const { return position() >= size(); }
127 
131  long long load(std::vector<char>& data);
132 
136  long long load(void* buffer, long long max=-1);
137 
139  double readDouble(bool little_endian_data=true);
141  float readFloat (bool little_endian_data=true);
143  unsigned long long readUInt64(bool little_endian_data=true);
145  long long readSInt64(bool little_endian_data=true);
147  unsigned int readUInt32(bool little_endian_data=true);
149  int readSInt32(bool little_endian_data=true);
151  unsigned short readUInt16(bool little_endian_data=true);
153  short readSInt16(bool little_endian_data=true);
155  unsigned char readUInt8();
157  char readSInt8();
158 
160  long long readDouble(double* buffer, long long count, bool little_endian_data=true);
162  long long readFloat (float* buffer, long long count, bool little_endian_data=true);
164  long long readUInt64(unsigned long long* buffer, long long count, bool little_endian_data=true);
166  long long readSInt64(long long* buffer, long long count, bool little_endian_data=true);
168  long long readUInt32(unsigned int* buffer, long long count, bool little_endian_data=true);
170  long long readSInt32(int* buffer, long long count, bool little_endian_data=true);
172  long long readUInt16(unsigned short* buffer, long long count, bool little_endian_data=true);
174  long long readSInt16(short* buffer, long long count, bool little_endian_data=true);
176  long long readUInt8 (unsigned char* buffer, long long count);
178  long long readSInt8 (char* buffer, long long count);
179 
181  long long writeDouble(double data, bool little_endian_data=true);
183  long long writeFloat (float data, bool little_endian_data=true);
185  long long writeUInt64(unsigned long long data, bool little_endian_data=true);
187  long long writeSInt64(long long data, bool little_endian_data=true);
189  long long writeUInt32(unsigned int data, bool little_endian_data=true);
191  long long writeSInt32(int data, bool little_endian_data=true);
193  long long writeUInt16(unsigned short data, bool little_endian_data=true);
195  long long writeSInt16(short data, bool little_endian_data=true);
197  long long writeUInt8 (unsigned char data);
199  long long writeSInt8 (char data);
200 
202  long long writeDouble(const double* buffer, long long count, bool little_endian_data=true);
204  long long writeFloat (const float* buffer, long long count, bool little_endian_data=true);
206  long long writeUInt64(const unsigned long long* buffer, long long count, bool little_endian_data=true);
208  long long writeSInt64(const long long* buffer, long long count, bool little_endian_data=true);
210  long long writeUInt32(const unsigned int* buffer, long long count, bool little_endian_data=true);
212  long long writeSInt32(const int* buffer, long long count, bool little_endian_data=true);
214  long long writeUInt16(const unsigned short* buffer, long long count, bool little_endian_data=true);
216  long long writeSInt16(const short* buffer, long long count, bool little_endian_data=true);
218  long long writeUInt8 (const unsigned char* buffer, long long count);
220  long long writeSInt8 (const char* buffer, long long count);
221 
222  protected:
223  virtual long long read_Implementation(void* buffer, long long byte_count) = 0;
224  virtual long long write_Implementation(const void* buffer, long long byte_count) = 0;
225  virtual long long position_Implementation() const = 0;
226  virtual bool seekSet_Implementation(long long offset) = 0;
227 
228  protected:
229  long long write64(const void* buffer, long long count, bool little_endian_data=true);
230  long long write32(const void* buffer, long long count, bool little_endian_data=true);
231  long long write16(const void* buffer, long long count, bool little_endian_data=true);
232 
233  long long read64(void* buffer, long long count, bool little_endian_data=true);
234  long long read32(void* buffer, long long count, bool little_endian_data=true);
235  long long read16(void* buffer, long long count, bool little_endian_data=true);
236 
237  long long write64(const void* buffer, bool little_endian_data=true);
238  long long write32(const void* buffer, bool little_endian_data=true);
239  long long write16(const void* buffer, bool little_endian_data=true);
240 
241  long long read64(void* buffer, bool little_endian_data=true);
242  long long read32(void* buffer, bool little_endian_data=true);
243  long long read16(void* buffer, bool little_endian_data=true);
244 
245  protected:
247  };
248 //-----------------------------------------------------------------------------
251 //-----------------------------------------------------------------------------
252 }
253 
254 #endif
VirtualFile & operator=(const VirtualFile &other)
Definition: VirtualFile.hpp:95
An abstract class representing a file.
Definition: VirtualFile.hpp:60
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
bool endOfFile() const
Returns true if position() >= size()
String & normalizeSlashes()
Transform \ slashes in / slashes and removes duplicates.
Definition: String.cpp:534
const String & path() const
Returns the path of the file.
Definition: VirtualFile.hpp:98
Visualization Library main namespace.
VirtualFile(const VirtualFile &other)
Definition: VirtualFile.hpp:65
VirtualFile()
Constructor.
Definition: VirtualFile.hpp:69
The base class for all the reference counted objects.
Definition: Object.hpp:158
float max(float a, float b)
Definition: Vector2.hpp:312
Computes the MD5 of a given buffer or VirtualFile.
Definition: MD5CheckSum.hpp:46
#define VL_INSTRUMENT_ABSTRACT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:145
VLCORE_EXPORT ref< VirtualFile > locateFile(const String &path)
Utility function, equivalent to vl::defFileSystem()->locateFile(path)
Definition: VirtualFile.cpp:41
void setPath(const String &name)
Changes the path bound to a VirtualFile. Use carefully this function, you shouldn&#39;t rename a VirtualF...
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
Visualization Library&#39;s enums in the &#39;vl&#39; namespace.