Visualization Library 2.0.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
VirtualFile.cpp
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 #include <vlCore/VirtualFile.hpp>
33 #include <vlCore/FileSystem.hpp>
34 #include <vlCore/Log.hpp>
35 #include <vlCore/Say.hpp>
36 #include <vlCore/CRC32CheckSum.hpp>
37 
38 using namespace vl;
39 
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
43 unsigned int VirtualFile::crc32()
44 {
45  unsigned int sum = 0;
46 
47  if ( open(OM_ReadOnly) )
48  {
49  CRC32CheckSum check_sum;
50  sum = check_sum.compute(this);
51  close();
52  }
53 
54  return sum;
55 }
56 //-----------------------------------------------------------------------------
58 {
59  MD5CheckSum check_sum;
60  if ( open(OM_ReadOnly) )
61  {
62  check_sum.compute(this);
63  close();
64  }
65  return check_sum;
66 }
67 //-----------------------------------------------------------------------------
68 long long VirtualFile::peek(void* buffer, long long byte_count)
69 {
70  if ( !isOpen() )
71  {
72  Log::error("VirtualFile::peek(): the file is closed.\n");
73  return 0;
74  }
75  long long pos = position();
76  long long read_bytes = read(buffer, byte_count);
77  if ( !seekSet( pos ) )
78  Log::error("VirtualFile::peek() called on a non seek-able VirtualFile.\n");
79  return read_bytes;
80 }
81 //-----------------------------------------------------------------------------
82 long long VirtualFile::read(void* buffer, long long byte_count)
83 {
84  if (byte_count > 0)
85  return read_Implementation(buffer, byte_count);
86  else
87  return 0;
88 }
89 //-----------------------------------------------------------------------------
90 long long VirtualFile::write(const void* buffer, long long byte_count)
91 {
92  if (byte_count > 0)
93  return write_Implementation(buffer, byte_count);
94  else
95  return 0;
96 }
97 //-----------------------------------------------------------------------------
98 long long VirtualFile::position() const
99 {
100  return position_Implementation();
101 }
102 //-----------------------------------------------------------------------------
103 bool VirtualFile::seekSet(long long offset)
104 {
105  if (offset < 0)
106  {
107  Log::error( Say("VirtualFile::seekSet(%n): invalid offset.\n") << offset);
109  return false;
110  }
111  if (offset > size() )
112  {
113  Log::error( Say("VirtualFile::seekSet(%n): invalid offset past end of stream.\n") << offset);
115  return false;
116  }
117 
118  return seekSet_Implementation(offset);
119 }
120 //-----------------------------------------------------------------------------
121 bool VirtualFile::seekCur(long long offset)
122 {
123  return seekSet( position() + offset );
124 }
125 //-----------------------------------------------------------------------------
126 bool VirtualFile::seekEnd(long long offset)
127 {
128  return seekSet( size() + offset );
129 }
130 //-----------------------------------------------------------------------------
131 long long VirtualFile::load(std::vector<char>& data)
132 {
133  data.resize( (size_t)size() );
134  if (data.size())
135  return load(&data[0], data.size());
136  else
137  return 0;
138 }
139 //-----------------------------------------------------------------------------
140 long long VirtualFile::load(void* buffer, long long max)
141 {
142  if (max<0)
143  max = size();
144  if ( open(OM_ReadOnly) )
145  {
146  long long bytes = read(buffer,max);
147  close();
148  return bytes;
149  }
150  else
151  {
152  Log::error( Say("Cannot load file '%s'.\n") << path() );
153  return 0;
154  }
155 }
156 //-----------------------------------------------------------------------------
157 // UTIITY FUNCTIONS - READ SINGLE VALUE
158 //-----------------------------------------------------------------------------
159 double VirtualFile::readDouble(bool little_endian_data)
160 {
161  double data = 0;
162  read64(&data, little_endian_data);
163  return data;
164 }
165 //-----------------------------------------------------------------------------
166 float VirtualFile::readFloat(bool little_endian_data)
167 {
168  float data = 0;
169  read32(&data, little_endian_data);
170  return data;
171 }
172 //-----------------------------------------------------------------------------
173 unsigned long long VirtualFile::readUInt64(bool little_endian_data)
174 {
175  unsigned long long data = 0;
176  read64(&data, little_endian_data);
177  return data;
178 }
179 //-----------------------------------------------------------------------------
180 long long VirtualFile::readSInt64(bool little_endian_data)
181 {
182  long long data = 0;
183  read64(&data, little_endian_data);
184  return data;
185 }
186 //-----------------------------------------------------------------------------
187 unsigned int VirtualFile::readUInt32(bool little_endian_data)
188 {
189  unsigned long data = 0;
190  read32(&data, little_endian_data);
191  return data;
192 }
193 //-----------------------------------------------------------------------------
194 int VirtualFile::readSInt32(bool little_endian_data)
195 {
196  int data = 0;
197  read32(&data, little_endian_data);
198  return data;
199 }
200 //-----------------------------------------------------------------------------
201 unsigned short VirtualFile::readUInt16(bool little_endian_data)
202 {
203  unsigned short data = 0;
204  read16(&data, little_endian_data);
205  return data;
206 }
207 //-----------------------------------------------------------------------------
208 short VirtualFile::readSInt16(bool little_endian_data)
209 {
210  short data = 0;
211  read16(&data, little_endian_data);
212  return data;
213 }
214 //-----------------------------------------------------------------------------
215 unsigned char VirtualFile::readUInt8()
216 {
217  unsigned char data = 0;
218  read(&data, 1);
219  return data;
220 }
221 //-----------------------------------------------------------------------------
223 {
224  char data = 0;
225  read(&data, 1);
226  return data;
227 }
228 //-----------------------------------------------------------------------------
229 // UTIITY FUNCTIONS - READ MULTIPLE VALUES
230 //-----------------------------------------------------------------------------
231 long long VirtualFile::readDouble(double* buffer, long long count, bool little_endian_data)
232 {
233  return read64(buffer, count, little_endian_data);
234 }
235 //-----------------------------------------------------------------------------
236 long long VirtualFile::readFloat(float* buffer, long long count, bool little_endian_data)
237 {
238  return read32(buffer, count, little_endian_data);
239 }
240 //-----------------------------------------------------------------------------
241 long long VirtualFile::readUInt64(unsigned long long* buffer, long long count, bool little_endian_data)
242 {
243  return read64(buffer, count, little_endian_data);
244 }
245 //-----------------------------------------------------------------------------
246 long long VirtualFile::readSInt64(long long* buffer, long long count, bool little_endian_data)
247 {
248  return read64(buffer, count, little_endian_data);
249 }
250 //-----------------------------------------------------------------------------
251 long long VirtualFile::readUInt32(unsigned int* buffer, long long count, bool little_endian_data)
252 {
253  return read32(buffer, count, little_endian_data);
254 }
255 //-----------------------------------------------------------------------------
256 long long VirtualFile::readSInt32(int* buffer, long long count, bool little_endian_data)
257 {
258  return read32(buffer, count, little_endian_data);
259 }
260 //-----------------------------------------------------------------------------
261 long long VirtualFile::readUInt16(unsigned short* buffer, long long count, bool little_endian_data)
262 {
263  return read16(buffer, count, little_endian_data);
264 }
265 //-----------------------------------------------------------------------------
266 long long VirtualFile::readSInt16(short* buffer, long long count, bool little_endian_data)
267 {
268  return read16(buffer, count, little_endian_data);
269 }
270 //-----------------------------------------------------------------------------
271 long long VirtualFile::readUInt8(unsigned char* buffer, long long count)
272 {
273  return read(buffer, count);
274 }
275 //-----------------------------------------------------------------------------
276 long long VirtualFile::readSInt8(char* buffer, long long count)
277 {
278  return read(buffer, count);
279 }
280 //-----------------------------------------------------------------------------
281 // UTILITY FUNCTIONS - WRITE SINGLE VALUES
282 //-----------------------------------------------------------------------------
283 long long VirtualFile::writeDouble(double data, bool little_endian_data)
284 {
285  return write64(&data, little_endian_data);
286 }
287 //-----------------------------------------------------------------------------
288 long long VirtualFile::writeFloat(float data, bool little_endian_data)
289 {
290  return write32(&data, little_endian_data);
291 }
292 //-----------------------------------------------------------------------------
293 long long VirtualFile::writeUInt64(unsigned long long data, bool little_endian_data)
294 {
295  return write64(&data, little_endian_data);
296 }
297 //-----------------------------------------------------------------------------
298 long long VirtualFile::writeSInt64(long long data, bool little_endian_data)
299 {
300  return write64(&data, little_endian_data);
301 }
302 //-----------------------------------------------------------------------------
303 long long VirtualFile::writeUInt32(unsigned int data, bool little_endian_data)
304 {
305  return write32(&data, little_endian_data);
306 }
307 //-----------------------------------------------------------------------------
308 long long VirtualFile::writeSInt32(int data, bool little_endian_data)
309 {
310  return write32(&data, little_endian_data);
311 }
312 //-----------------------------------------------------------------------------
313 long long VirtualFile::writeUInt16(unsigned short data, bool little_endian_data)
314 {
315  return write16(&data, little_endian_data);
316 }
317 //-----------------------------------------------------------------------------
318 long long VirtualFile::writeSInt16(short data, bool little_endian_data)
319 {
320  return write16(&data, little_endian_data);
321 }
322 //-----------------------------------------------------------------------------
323 long long VirtualFile::writeUInt8(unsigned char data)
324 {
325  return write(&data, 1);
326 }
327 //-----------------------------------------------------------------------------
328 long long VirtualFile::writeSInt8(char data)
329 {
330  return write(&data, 1);
331 }
332 //-----------------------------------------------------------------------------
333 // UTILITY FUNCTIONS - WRITE MULTIPLE VALUES
334 //-----------------------------------------------------------------------------
335 long long VirtualFile::writeDouble(const double* buffer, long long count, bool little_endian_data)
336 {
337  return write64(buffer, count, little_endian_data);
338 }
339 //-----------------------------------------------------------------------------
340 long long VirtualFile::writeFloat(const float* buffer, long long count, bool little_endian_data)
341 {
342  return write32(buffer, count, little_endian_data);
343 }
344 //-----------------------------------------------------------------------------
345 long long VirtualFile::writeUInt64(const unsigned long long* buffer, long long count, bool little_endian_data)
346 {
347  return write64(buffer, count, little_endian_data);
348 }
349 //-----------------------------------------------------------------------------
350 long long VirtualFile::writeSInt64(const long long* buffer, long long count, bool little_endian_data)
351 {
352  return write64(buffer, count, little_endian_data);
353 }
354 //-----------------------------------------------------------------------------
355 long long VirtualFile::writeUInt32(const unsigned int* buffer, long long count, bool little_endian_data)
356 {
357  return write32(buffer, count, little_endian_data);
358 }
359 //-----------------------------------------------------------------------------
360 long long VirtualFile::writeSInt32(const int* buffer, long long count, bool little_endian_data)
361 {
362  return write32(buffer, count, little_endian_data);
363 }
364 //-----------------------------------------------------------------------------
365 long long VirtualFile::writeUInt16(const unsigned short* buffer, long long count, bool little_endian_data)
366 {
367  return write16(buffer, count, little_endian_data);
368 }
369 //-----------------------------------------------------------------------------
370 long long VirtualFile::writeSInt16(const short* buffer, long long count, bool little_endian_data)
371 {
372  return write16(buffer, count, little_endian_data);
373 }
374 //-----------------------------------------------------------------------------
375 long long VirtualFile::writeUInt8(const unsigned char* buffer, long long count)
376 {
377  return write(buffer, count);
378 }
379 //-----------------------------------------------------------------------------
380 long long VirtualFile::writeSInt8(const char* buffer, long long count)
381 {
382  return write(buffer, count);
383 }
384 //-----------------------------------------------------------------------------
385 // GENERIC IO FUNCTIONS
386 //-----------------------------------------------------------------------------
387 long long VirtualFile::write64(const void* buffer, long long count, bool little_endian_data)
388 {
389  unsigned short bet = 0x00FF;
390  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
391  if (little_endian_cpu != little_endian_data)
392  {
393  long long ret = 0;
394  for(long long i=0; i<count; ++i)
395  ret += write64( (char*)buffer+i*8, little_endian_data );
396  return ret;
397  }
398  else
399  return write(buffer, 8*count);
400 }
401 //-----------------------------------------------------------------------------
402 long long VirtualFile::write32(const void* buffer, long long count, bool little_endian_data)
403 {
404  unsigned short bet = 0x00FF;
405  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
406  if (little_endian_cpu != little_endian_data)
407  {
408  long long ret = 0;
409  for(long long i=0; i<count; ++i)
410  ret += write32( (char*)buffer+i*4, little_endian_data );
411  return ret;
412  }
413  else
414  return write(buffer, 4*count);
415 }
416 //-----------------------------------------------------------------------------
417 long long VirtualFile::write16(const void* buffer, long long count, bool little_endian_data)
418 {
419  unsigned short bet = 0x00FF;
420  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
421  if (little_endian_cpu != little_endian_data)
422  {
423  long long ret = 0;
424  for(long long i=0; i<count; ++i)
425  ret += write16( (char*)buffer+i*2, little_endian_data );
426  return ret;
427  }
428  else
429  return write(buffer, 2*count);
430 }
431 //-----------------------------------------------------------------------------
432 long long VirtualFile::read64(void* buffer, long long count, bool little_endian_data)
433 {
434  long long ret = read(buffer, 8*count);
435  unsigned short bet = 0x00FF;
436  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
437  if ( little_endian_cpu != little_endian_data )
438  {
439  char* bytes = (char*)buffer;
440  for(int i=0; i<count; ++i, bytes+=8)
441  {
442  char tmp;
443  tmp = bytes[0]; bytes[0] = bytes[7]; bytes[7] = tmp;
444  tmp = bytes[1]; bytes[1] = bytes[6]; bytes[6] = tmp;
445  tmp = bytes[2]; bytes[2] = bytes[5]; bytes[5] = tmp;
446  tmp = bytes[3]; bytes[3] = bytes[4]; bytes[4] = tmp;
447  }
448  }
449  return ret;
450 }
451 //-----------------------------------------------------------------------------
452 long long VirtualFile::read32(void* buffer, long long count, bool little_endian_data)
453 {
454  long long ret = read(buffer, 4*count);
455  unsigned short bet = 0x00FF;
456  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
457  if ( little_endian_cpu != little_endian_data )
458  {
459  char* bytes = (char*)buffer;
460  for(int i=0; i<count; ++i, bytes+=4)
461  {
462  char tmp;
463  tmp = bytes[0]; bytes[0] = bytes[3]; bytes[3] = tmp;
464  tmp = bytes[1]; bytes[1] = bytes[2]; bytes[2] = tmp;
465  }
466  }
467  return ret;
468 }
469 //-----------------------------------------------------------------------------
470 long long VirtualFile::read16(void* buffer, long long count, bool little_endian_data)
471 {
472  long long ret = read(buffer, 2*count);
473  unsigned short bet = 0x00FF;
474  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
475  if ( little_endian_cpu != little_endian_data )
476  {
477  char* bytes = (char*)buffer;
478  for(int i=0; i<count; ++i, bytes+=2)
479  {
480  char tmp = bytes[0]; bytes[0] = bytes[1]; bytes[1] = tmp;
481  }
482  }
483  return ret;
484 }
485 //-----------------------------------------------------------------------------
486 long long VirtualFile::write64(const void* buffer, bool little_endian_data)
487 {
488  unsigned short bet = 0x00FF;
489  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
490  long long dummy = *(long long*)buffer;
491  char* byte = (char*)&dummy;
492  if (little_endian_cpu != little_endian_data)
493  {
494  char tmp;
495  tmp = byte[0]; byte[0] = byte[7]; byte[7] = tmp;
496  tmp = byte[1]; byte[1] = byte[6]; byte[6] = tmp;
497  tmp = byte[2]; byte[2] = byte[5]; byte[5] = tmp;
498  tmp = byte[3]; byte[3] = byte[4]; byte[4] = tmp;
499  }
500  return write(byte, 8);
501 }
502 //-----------------------------------------------------------------------------
503 long long VirtualFile::write32(const void* buffer, bool little_endian_data)
504 {
505  unsigned short bet = 0x00FF;
506  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
507  int dummy = *(int*)buffer;
508  char* byte = (char*)&dummy;
509  if (little_endian_cpu != little_endian_data)
510  {
511  char tmp;
512  tmp = byte[0]; byte[0] = byte[3]; byte[3] = tmp;
513  tmp = byte[1]; byte[1] = byte[2]; byte[2] = tmp;
514  }
515  return write(byte, 4);
516 }
517 //-----------------------------------------------------------------------------
518 long long VirtualFile::write16(const void* buffer, bool little_endian_data)
519 {
520  unsigned short bet = 0x00FF;
521  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
522  short dummy = *(short*)buffer;
523  char* byte = (char*)&dummy;
524  if (little_endian_cpu != little_endian_data)
525  {
526  char tmp = byte[0]; byte[0] = byte[1]; byte[1] = tmp;
527  }
528  return write(byte, 2);
529 }
530 //-----------------------------------------------------------------------------
531 long long VirtualFile::read64(void* buffer, bool little_endian_data)
532 {
533  char* bytes = (char*)buffer;
534  long long ret = read(bytes, 8);
535  unsigned short bet = 0x00FF;
536  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
537  if ( little_endian_cpu != little_endian_data )
538  {
539  char tmp;
540  tmp = bytes[0]; bytes[0] = bytes[7]; bytes[7] = tmp;
541  tmp = bytes[1]; bytes[1] = bytes[6]; bytes[6] = tmp;
542  tmp = bytes[2]; bytes[2] = bytes[5]; bytes[5] = tmp;
543  tmp = bytes[3]; bytes[3] = bytes[4]; bytes[4] = tmp;
544  }
545  return ret;
546 }
547 //-----------------------------------------------------------------------------
548 long long VirtualFile::read32(void* buffer, bool little_endian_data)
549 {
550  char* bytes = (char*)buffer;
551  long long ret = read(bytes, 4);
552  unsigned short bet = 0x00FF;
553  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
554  if ( little_endian_cpu != little_endian_data )
555  {
556  char tmp;
557  tmp = bytes[0]; bytes[0] = bytes[3]; bytes[3] = tmp;
558  tmp = bytes[1]; bytes[1] = bytes[2]; bytes[2] = tmp;
559  }
560  return ret;
561 }
562 //-----------------------------------------------------------------------------
563 long long VirtualFile::read16(void* buffer, bool little_endian_data)
564 {
565  char* bytes = (char*)buffer;
566  long long ret = read(bytes, 2);
567  unsigned short bet = 0x00FF;
568  bool little_endian_cpu = ((unsigned char*)&bet)[0] == 0xFF;
569  if ( little_endian_cpu != little_endian_data )
570  {
571  char tmp = bytes[0]; bytes[0] = bytes[1]; bytes[1] = tmp;
572  }
573  return ret;
574 }
575 //-----------------------------------------------------------------------------
long long read(void *buffer, long long byte_count)
Reads byte_count bytes from a file. Returns the number of bytes actually read.
Definition: VirtualFile.cpp:82
VLCORE_EXPORT FileSystem * defFileSystem()
Returns the default FileSystem used by VisualizationLibrary.
Definition: pimpl.cpp:97
unsigned int compute(const void *buf, int length)
MD5CheckSum md5()
Computes the md5 of the entire file.
Definition: VirtualFile.cpp:57
Computes the a CRC32 checksum of a given buffer or VirtualFile.
long long writeDouble(double data, bool little_endian_data=true)
Writes a single entry. Returns the number of bytes written.
long long writeUInt16(unsigned short data, bool little_endian_data=true)
Writes a single entry. Returns the number of bytes written.
A simple String formatting class.
Definition: Say.hpp:124
void compute(void *buffer, int len)
Definition: MD5CheckSum.cpp:50
long long read32(void *buffer, long long count, bool little_endian_data=true)
long long write16(const void *buffer, long long count, bool little_endian_data=true)
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
long long read16(void *buffer, long long count, bool little_endian_data=true)
int readSInt32(bool little_endian_data=true)
Reads single entry.
virtual bool isOpen() const =0
Returns true if the file has been opened.
virtual long long write_Implementation(const void *buffer, long long byte_count)=0
bool seekCur(long long offset)
Changes the current read/write position of a file.
long long writeSInt16(short data, bool little_endian_data=true)
Writes a single entry. Returns the number of bytes written.
long long writeUInt8(unsigned char data)
Writes a single entry. Returns the number of bytes written.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
Definition: Log.cpp:165
virtual long long position_Implementation() const =0
virtual ref< VirtualFile > locateFile(const String &full_path, const String &alternate_path=String()) const
Looks for a VirtualFile on the disk and in the currently active FileSystem.
Definition: FileSystem.cpp:61
long long writeUInt64(unsigned long long data, bool little_endian_data=true)
Writes a single entry. Returns the number of bytes written.
short readSInt16(bool little_endian_data=true)
Reads single entry.
long long writeSInt64(long long data, bool little_endian_data=true)
Writes a single entry. Returns the number of bytes written.
long long writeFloat(float data, bool little_endian_data=true)
Writes a single entry. Returns the number of bytes written.
long long readSInt64(bool little_endian_data=true)
Reads single entry.
unsigned long long readUInt64(bool little_endian_data=true)
Reads single entry.
float readFloat(bool little_endian_data=true)
Reads single entry.
virtual void close()=0
Closes the file.
long long writeSInt8(char data)
Writes a single entry. Returns the number of bytes written.
long long writeUInt32(unsigned int data, bool little_endian_data=true)
Writes a single entry. Returns the number of bytes written.
const String & path() const
Returns the path of the file.
Definition: VirtualFile.hpp:98
Visualization Library main namespace.
long long writeSInt32(int data, bool little_endian_data=true)
Writes a single entry. Returns the number of bytes written.
long long read64(void *buffer, long long count, bool little_endian_data=true)
long long write64(const void *buffer, long long count, bool little_endian_data=true)
unsigned int crc32()
Computes the crc32 of the entire file.
Definition: VirtualFile.cpp:43
float max(float a, float b)
Definition: Vector2.hpp:311
unsigned char readUInt8()
Reads single entry.
long long write(const void *buffer, long long byte_count)
Writes byte_count bytes to a file. Returns the number of bytes actually written.
Definition: VirtualFile.cpp:90
virtual bool open(EOpenMode mode)=0
Opens the file in the specified mode.
virtual bool seekSet_Implementation(long long offset)=0
bool seekSet(long long offset)
Changes the current read/write position of a file.
virtual long long size() const =0
Returns the size of the file in bytes.
Computes the MD5 of a given buffer or VirtualFile.
Definition: MD5CheckSum.hpp:46
VLCORE_EXPORT ref< VirtualFile > locateFile(const String &path)
Utility function, equivalent to vl::defFileSystem()->locateFile(path)
Definition: VirtualFile.cpp:41
unsigned short readUInt16(bool little_endian_data=true)
Reads single entry.
virtual long long read_Implementation(void *buffer, long long byte_count)=0
long long peek(void *buffer, long long byte_count)
Reads byte_count bytes and returns to the original position.
Definition: VirtualFile.cpp:68
char readSInt8()
Reads single entry.
unsigned int readUInt32(bool little_endian_data=true)
Reads single entry.
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
bool seekEnd(long long offset)
Changes the current read/write position of a file.
long long load(std::vector< char > &data)
Loads the entire file in the specified vector.
long long position() const
Returns the current position in the file.
Definition: VirtualFile.cpp:98
long long write32(const void *buffer, long long count, bool little_endian_data=true)
double readDouble(bool little_endian_data=true)
Reads single entry.