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]
MemoryFile.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 MemoryFile_INCLUDE_ONCE
33 #define MemoryFile_INCLUDE_ONCE
34 
35 #include <vlCore/VirtualFile.hpp>
36 #include <vlCore/Buffer.hpp>
37 
38 namespace vl
39 {
40 //---------------------------------------------------------------------------
41 // MemoryFile
42 //---------------------------------------------------------------------------
57  {
59 
60  public:
61  MemoryFile();
62 
63  const Buffer* buffer() const { return mBuffer.get(); }
64 
65  Buffer* buffer() { return mBuffer.get(); }
66 
68  void setBuffer(Buffer* buffer) { mBuffer = buffer; }
69 
70  unsigned char* ptr() { return mBuffer->ptr(); }
71 
73  virtual bool exists() const { return true; }
74 
75  virtual bool open(EOpenMode mode);
76 
77  virtual bool isOpen() const { return mIsOpen; }
78 
79  virtual void close() { mPtr = 0; mIsOpen = false; }
80 
81  void allocateBuffer(long long byte_count) { mBuffer->resize((int)byte_count); }
82 
83  virtual long long size() const { return mBuffer->bytesUsed(); }
84 
86  void copy(VirtualFile* file);
87 
88  MemoryFile& operator=(const MemoryFile& other) { close(); super::operator=(other); mBuffer = other.mBuffer; return *this; }
89 
90  ref<VirtualFile> clone() const;
91 
92  protected:
93  virtual long long position_Implementation() const;
94 
95  virtual long long read_Implementation(void* buffer, long long byte_count);
96 
97  virtual long long write_Implementation(const void* /*buffer*/, long long /*byte_count*/) { return 0; } // not supported yet
98 
99  virtual bool seekSet_Implementation(long long offset);
100 
101  protected:
103  long long mPtr;
104  bool mIsOpen;
105  };
106 }
107 
108 #endif
virtual bool isOpen() const
Returns true if the file has been opened.
Definition: MemoryFile.hpp:77
An abstract class representing a file.
Definition: VirtualFile.hpp:60
unsigned char * ptr()
Definition: MemoryFile.hpp:70
ref< Buffer > mBuffer
Definition: MemoryFile.hpp:102
Implements a buffer whose storage is in local memory.
Definition: Buffer.hpp:46
virtual bool exists() const
A MemoryFile always exists.
Definition: MemoryFile.hpp:73
virtual long long size() const
Returns the size of the file in bytes.
Definition: MemoryFile.hpp:83
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
Visualization Library main namespace.
MemoryFile & operator=(const MemoryFile &other)
Definition: MemoryFile.hpp:88
A VirtualFile to manipulate files stored in memory.
Definition: MemoryFile.hpp:56
long long mPtr
Definition: MemoryFile.hpp:103
const Buffer * buffer() const
Definition: MemoryFile.hpp:63
void allocateBuffer(long long byte_count)
Definition: MemoryFile.hpp:81
Buffer * buffer()
Definition: MemoryFile.hpp:65
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
virtual long long write_Implementation(const void *, long long)
Definition: MemoryFile.hpp:97
void setBuffer(Buffer *buffer)
This is useful when you want to point more MemoryFiles to the same Buffer object. ...
Definition: MemoryFile.hpp:68
virtual void close()
Closes the file.
Definition: MemoryFile.hpp:79