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:
Steve Lhomme 2010-07-05 11:38:15 +00:00
parent 775c5aecf3
commit 2be628cfe9
2 changed files with 28 additions and 9 deletions

View File

@ -3,6 +3,7 @@ New 1.1.0 version:
- give access to the SetParent to KaxSimpleBlock as well
- change the placement of a MATROSKA_DLL_API so that it actually works
- 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
New 1.0.0 version:

View File

@ -58,24 +58,42 @@ class MATROSKA_DLL_API DataBuffer {
uint32 mySize;
bool bValidValue;
bool (*myFreeBuffer)(const DataBuffer & aBuffer); // method to free the internal buffer
bool bInternalBuffer;
public:
DataBuffer(binary * aBuffer, uint32 aSize, bool (*aFreeBuffer)(const DataBuffer & aBuffer) = NULL)
:myBuffer(aBuffer)
DataBuffer(binary * aBuffer, uint32 aSize, bool (*aFreeBuffer)(const DataBuffer & aBuffer) = NULL, bool _bInternalBuffer = false)
:myBuffer(NULL)
,mySize(aSize)
,bValidValue(true)
,myFreeBuffer(aFreeBuffer)
{}
,bValidValue(true)
,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 binary * Buffer() {return myBuffer;}
virtual binary * Buffer() {assert(bValidValue); return myBuffer;}
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;};
bool FreeBuffer(const DataBuffer & aBuffer) {
bool bResult = true;
if (myBuffer != NULL && myFreeBuffer != NULL && bValidValue) {
bResult = myFreeBuffer(aBuffer);
if (myBuffer != NULL && bValidValue) {
if (myFreeBuffer != NULL)
bResult = myFreeBuffer(aBuffer);
if (bInternalBuffer)
delete [] myBuffer;
myBuffer = NULL;
mySize = 0;
bValidValue = false;
}
return bResult;