support buffers already in RAM
git-svn-id: svn://anubis/misc/FileLoader@255 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
parent
ab0b8157f4
commit
8abf3ff02b
27
FileLoader.h
27
FileLoader.h
@ -39,13 +39,24 @@ class FileLoader
|
||||
data = new char[size];
|
||||
_refcnt = new int;
|
||||
*_refcnt = 1;
|
||||
m_alloced = true;
|
||||
}
|
||||
Buffer(char * data, int sz)
|
||||
{
|
||||
size = sz;
|
||||
this->data = data;
|
||||
m_alloced = false;
|
||||
}
|
||||
void copy(const Buffer & other)
|
||||
{
|
||||
data = other.data;
|
||||
size = other.size;
|
||||
_refcnt = other._refcnt;
|
||||
(*_refcnt)++;
|
||||
m_alloced = other.m_alloced;
|
||||
if (m_alloced)
|
||||
{
|
||||
_refcnt = other._refcnt;
|
||||
(*_refcnt)++;
|
||||
}
|
||||
}
|
||||
Buffer(const Buffer & other) { copy(other); }
|
||||
Buffer & operator=(const Buffer & other)
|
||||
@ -55,15 +66,19 @@ class FileLoader
|
||||
}
|
||||
~Buffer()
|
||||
{
|
||||
(*_refcnt)--;
|
||||
if (*_refcnt < 1)
|
||||
if (m_alloced)
|
||||
{
|
||||
delete _refcnt;
|
||||
delete data;
|
||||
(*_refcnt)--;
|
||||
if (*_refcnt < 1)
|
||||
{
|
||||
delete _refcnt;
|
||||
delete data;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected:
|
||||
int * _refcnt;
|
||||
bool m_alloced;
|
||||
};
|
||||
|
||||
virtual int getSize(const Path & path) = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user