libmatroska: add the possibility for a DataBuffer class to use its own internal memory
git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libmatroska@394 a6f86f6d-0131-4f8e-9e7b-e335508773d5
This commit is contained in:
parent
775c5aecf3
commit
2be628cfe9
@ -3,6 +3,7 @@ New 1.1.0 version:
|
|||||||
- give access to the SetParent to KaxSimpleBlock as well
|
- give access to the SetParent to KaxSimpleBlock as well
|
||||||
- change the placement of a MATROSKA_DLL_API so that it actually works
|
- change the placement of a MATROSKA_DLL_API so that it actually works
|
||||||
- remove all references to the old/outdated/previous tag system
|
- remove all references to the old/outdated/previous tag system
|
||||||
|
- add the possibility for a DataBuffer class to use its own internal memory
|
||||||
|
|
||||||
2010-06-04 robux4/mosu
|
2010-06-04 robux4/mosu
|
||||||
New 1.0.0 version:
|
New 1.0.0 version:
|
||||||
|
@ -58,24 +58,42 @@ class MATROSKA_DLL_API DataBuffer {
|
|||||||
uint32 mySize;
|
uint32 mySize;
|
||||||
bool bValidValue;
|
bool bValidValue;
|
||||||
bool (*myFreeBuffer)(const DataBuffer & aBuffer); // method to free the internal buffer
|
bool (*myFreeBuffer)(const DataBuffer & aBuffer); // method to free the internal buffer
|
||||||
|
bool bInternalBuffer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DataBuffer(binary * aBuffer, uint32 aSize, bool (*aFreeBuffer)(const DataBuffer & aBuffer) = NULL)
|
DataBuffer(binary * aBuffer, uint32 aSize, bool (*aFreeBuffer)(const DataBuffer & aBuffer) = NULL, bool _bInternalBuffer = false)
|
||||||
:myBuffer(aBuffer)
|
:myBuffer(NULL)
|
||||||
,mySize(aSize)
|
,mySize(aSize)
|
||||||
,bValidValue(true)
|
,bValidValue(true)
|
||||||
,myFreeBuffer(aFreeBuffer)
|
,myFreeBuffer(aFreeBuffer)
|
||||||
{}
|
,bInternalBuffer(_bInternalBuffer)
|
||||||
|
{
|
||||||
|
if (bInternalBuffer)
|
||||||
|
{
|
||||||
|
myBuffer = new binary[mySize];
|
||||||
|
if (myBuffer == NULL)
|
||||||
|
bValidValue = false;
|
||||||
|
else
|
||||||
|
memcpy(myBuffer, aBuffer, mySize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
myBuffer = aBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~DataBuffer() {}
|
virtual ~DataBuffer() {}
|
||||||
virtual binary * Buffer() {return myBuffer;}
|
virtual binary * Buffer() {assert(bValidValue); return myBuffer;}
|
||||||
virtual uint32 & Size() {return mySize;};
|
virtual uint32 & Size() {return mySize;};
|
||||||
virtual const binary * Buffer() const {return myBuffer;}
|
virtual const binary * Buffer() const {assert(bValidValue); return myBuffer;}
|
||||||
virtual const uint32 Size() const {return mySize;};
|
virtual const uint32 Size() const {return mySize;};
|
||||||
bool FreeBuffer(const DataBuffer & aBuffer) {
|
bool FreeBuffer(const DataBuffer & aBuffer) {
|
||||||
bool bResult = true;
|
bool bResult = true;
|
||||||
if (myBuffer != NULL && myFreeBuffer != NULL && bValidValue) {
|
if (myBuffer != NULL && bValidValue) {
|
||||||
bResult = myFreeBuffer(aBuffer);
|
if (myFreeBuffer != NULL)
|
||||||
|
bResult = myFreeBuffer(aBuffer);
|
||||||
|
if (bInternalBuffer)
|
||||||
|
delete [] myBuffer;
|
||||||
myBuffer = NULL;
|
myBuffer = NULL;
|
||||||
|
mySize = 0;
|
||||||
bValidValue = false;
|
bValidValue = false;
|
||||||
}
|
}
|
||||||
return bResult;
|
return bResult;
|
||||||
|
Loading…
Reference in New Issue
Block a user