use the new accessors internally

+ make the new accessors inline

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libebml@13 a6f86f6d-0131-4f8e-9e7b-e335508773d5
This commit is contained in:
Steve Lhomme 2010-03-15 16:03:51 +00:00
parent 289a1c2e86
commit 9122d30f15
21 changed files with 216 additions and 216 deletions

View File

@ -69,8 +69,8 @@ class EBML_DLL_API EbmlBinary : public EbmlElement {
void SetBuffer(const binary *Buffer, const uint32 BufferSize) {
Data = (binary *) Buffer;
Size = BufferSize;
bValueIsSet = true;
SetSize_(BufferSize);
SetValueIsSet();
}
binary *GetBuffer() const {return Data;}
@ -80,8 +80,8 @@ class EBML_DLL_API EbmlBinary : public EbmlElement {
free(Data);
Data = (binary *)malloc(BufferSize * sizeof(binary));
memcpy(Data, Buffer, BufferSize);
Size = BufferSize;
bValueIsSet = true;
SetSize_(BufferSize);
SetValueIsSet();
}
operator const binary &() const {return *Data;}

View File

@ -58,7 +58,7 @@ class EBML_DLL_API EbmlCrc32 : public EbmlBinary {
EbmlCrc32(const EbmlCrc32 & ElementToClone);
static EbmlElement & Create() {return *(new EbmlCrc32);}
const EbmlCallbacks & Generic() const {return ClassInfos;}
bool ValidateSize() const {return (Size == 4);}
bool ValidateSize() const {return (GetSize() == 4);}
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
// uint64 UpdateSize(bool bKeepIntact = false);
@ -102,7 +102,7 @@ class EBML_DLL_API EbmlCrc32 : public EbmlBinary {
return m_crc_final;
};
void ForceCrc32(uint32 NewValue) { m_crc_final = NewValue; bValueIsSet = true;}
void ForceCrc32(uint32 NewValue) { m_crc_final = NewValue; SetValueIsSet();}
EbmlElement * Clone() const;

View File

@ -52,7 +52,7 @@ class EBML_DLL_API EbmlDate : public EbmlElement {
\brief set the date with a UNIX/C/EPOCH form
\param NewDate UNIX/C date in UTC (no timezone)
*/
void SetEpochDate(int32 NewDate) {bValueIsSet = true; myDate = int64(NewDate - UnixEpochDelay) * 1000000000; bValueIsSet = true;}
void SetEpochDate(int32 NewDate) {myDate = int64(NewDate - UnixEpochDelay) * 1000000000; SetValueIsSet();}
/*!
\brief get the date with a UNIX/C/EPOCH form
@ -60,17 +60,17 @@ class EBML_DLL_API EbmlDate : public EbmlElement {
*/
int32 GetEpochDate() const {return int32(myDate/1000000000 + UnixEpochDelay);}
bool ValidateSize() const {return ((Size == 8) || (Size == 0));}
bool ValidateSize() const {return ((GetSize() == 8) || (GetSize() == 0));}
/*!
\note no Default date handled
*/
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false) {
if(!bValueIsSet)
Size = 0;
if(!ValueIsSet())
SetSize_(0);
else
Size = 8;
return Size;
SetSize_(8);
return GetSize();
}
bool operator<(const EbmlDate & EltCmp) const {return myDate < EltCmp.myDate;}

View File

@ -263,12 +263,12 @@ class EBML_DLL_API EbmlElement {
*/
EbmlElement(const EbmlElement & ElementToClone);
uint64 GetDefaultSize() const {return DefaultSize;}
inline uint64 GetDefaultSize() const {return DefaultSize;}
inline void SetSize_(uint64 aSize) {Size = aSize;}
inline void SetValueIsSet(bool Set = true) {bValueIsSet = Set;}
void SetDefaultIsSet(bool Set = true) {DefaultIsSet = Set;}
void SetSizeIsFinite(bool Set = true) {bSizeIsFinite = Set;}
uint64 GetSizePosition() const {return SizePosition;}
inline void SetDefaultIsSet(bool Set = true) {DefaultIsSet = Set;}
inline void SetSizeIsFinite(bool Set = true) {bSizeIsFinite = Set;}
inline uint64 GetSizePosition() const {return SizePosition;}
uint64 Size; ///< the size of the data to write
uint64 DefaultSize; ///< Minimum data size to fill on rendering (0 = optimal)

View File

@ -58,7 +58,7 @@ class EBML_DLL_API EbmlFloat : public EbmlElement {
bool ValidateSize() const
{
return (Size == 4 || Size == 8);
return (GetSize() == 4 || GetSize() == 8);
}
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
@ -68,23 +68,23 @@ class EBML_DLL_API EbmlFloat : public EbmlElement {
void SetPrecision(const EbmlFloat::Precision prec = FLOAT_32)
{
if (prec == FLOAT_64)
Size = 8;
SetSize_(8);
else
Size = 4; // default size
SetSize_(4); // default size
}
// EbmlFloat & operator=(const float NewValue) { Value = NewValue; return *this;}
EbmlFloat & operator=(const double NewValue) { Value = NewValue; bValueIsSet = true; return *this;}
EbmlFloat & operator=(const double NewValue) { Value = NewValue; SetValueIsSet(); return *this;}
bool operator<(const EbmlFloat & EltCmp) const {return Value < EltCmp.Value;}
operator const float() const {return float(Value);}
operator const double() const {return double(Value);}
void SetDefaultValue(double aValue) {assert(!DefaultIsSet); DefaultValue = aValue; DefaultIsSet = true;}
void SetDefaultValue(double aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();}
const double DefaultVal() const {assert(DefaultIsSet); return DefaultValue;}
const double DefaultVal() const {assert(DefaultISset()); return DefaultValue;}
bool IsDefaultValue() const {
return (DefaultISset() && Value == DefaultValue);

View File

@ -68,18 +68,18 @@ class EBML_DLL_API EbmlMaster : public EbmlElement {
/*!
\brief Set wether the size is finite (size is known in advance when writing, or infinite size is not known on writing)
*/
bool SetSizeInfinite(bool aIsInfinite = true) {bSizeIsFinite = !aIsInfinite; return true;}
bool SetSizeInfinite(bool aIsInfinite = true) {SetSizeIsFinite(!aIsInfinite); return true;}
bool PushElement(EbmlElement & element);
uint64 GetSize() const {
if (bSizeIsFinite)
return Size;
if (IsFiniteSize())
return GetSize();
else
return (0-1);
}
uint64 GetDataStart() const {
return ElementPosition + EbmlId(*this).Length + CodedSizeLength(Size, SizeLength, bSizeIsFinite);
return GetElementPosition() + EbmlId(*this).Length + CodedSizeLength(GetSize(), GetSizeLength(), IsFiniteSize());
}
/*!

View File

@ -55,14 +55,14 @@ class EBML_DLL_API EbmlSInteger : public EbmlElement {
EbmlSInteger(int64 DefaultValue);
EbmlSInteger(const EbmlSInteger & ElementToClone);
EbmlSInteger & operator=(int64 NewValue) {Value = NewValue; bValueIsSet = true; return *this;}
EbmlSInteger & operator = (int64 NewValue) {Value = NewValue; SetValueIsSet(); return *this;}
/*!
Set the default size of the integer (usually 1,2,4 or 8)
*/
void SetDefaultSize(int nDefaultSize = DEFAULT_INT_SIZE) {Size = nDefaultSize;}
void SetDefaultSize(int nDefaultSize = DEFAULT_INT_SIZE) {SetSize_(nDefaultSize);}
bool ValidateSize() const {return (Size <= 8);}
bool ValidateSize() const {return (GetSize() <= 8);}
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
@ -74,9 +74,9 @@ class EBML_DLL_API EbmlSInteger : public EbmlElement {
operator int32() {return int32(Value);}
operator int64() {return Value;}
void SetDefaultValue(int64 aValue) {assert(!DefaultIsSet); DefaultValue = aValue; DefaultIsSet = true;}
void SetDefaultValue(int64 aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();}
int64 DefaultVal() const {assert(DefaultIsSet); return DefaultValue;}
int64 DefaultVal() const {assert(DefaultISset()); return DefaultValue;}
bool IsDefaultValue() const {
return (DefaultISset() && Value == DefaultValue);

View File

@ -63,9 +63,9 @@ class EBML_DLL_API EbmlString : public EbmlElement {
EbmlString & operator=(const std::string);
operator const std::string &() const {return Value;}
void SetDefaultValue(std::string & aValue) {assert(!DefaultIsSet); DefaultValue = aValue; DefaultIsSet = true;}
void SetDefaultValue(std::string & aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();}
const std::string DefaultVal() const {assert(DefaultIsSet); return DefaultValue;}
const std::string DefaultVal() const {assert(DefaultISset()); return DefaultValue;}
bool IsDefaultValue() const {
return (DefaultISset() && Value == DefaultValue);

View File

@ -55,14 +55,14 @@ class EBML_DLL_API EbmlUInteger : public EbmlElement {
EbmlUInteger(uint64 DefaultValue);
EbmlUInteger(const EbmlUInteger & ElementToClone);
EbmlUInteger & operator=(uint64 NewValue) {Value = NewValue; bValueIsSet = true; return *this;}
EbmlUInteger & operator=(uint64 NewValue) {Value = NewValue; SetValueIsSet(); return *this;}
/*!
Set the default size of the integer (usually 1,2,4 or 8)
*/
void SetDefaultSize(int nDefaultSize = DEFAULT_UINT_SIZE) {Size = nDefaultSize;}
void SetDefaultSize(int nDefaultSize = DEFAULT_UINT_SIZE) {SetSize_(nDefaultSize);}
bool ValidateSize() const {return (Size <= 8);}
bool ValidateSize() const {return (GetSize() <= 8);}
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
@ -74,9 +74,9 @@ class EBML_DLL_API EbmlUInteger : public EbmlElement {
operator uint32() const {return uint32(Value);}
operator uint64() const {return Value;}
void SetDefaultValue(uint64 aValue) {assert(!DefaultIsSet); DefaultValue = aValue; DefaultIsSet = true;}
void SetDefaultValue(uint64 aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();}
const uint64 DefaultVal() const {assert(DefaultIsSet); return DefaultValue;}
const uint64 DefaultVal() const {assert(DefaultISset()); return DefaultValue;}
bool IsDefaultValue() const {
return (DefaultISset() && Value == DefaultValue);

View File

@ -108,9 +108,9 @@ class EBML_DLL_API EbmlUnicodeString : public EbmlElement {
EbmlUnicodeString & operator=(const UTFstring &); ///< platform dependant code
operator const UTFstring &() const {return Value;}
void SetDefaultValue(UTFstring & aValue) {assert(!DefaultIsSet); DefaultValue = aValue; DefaultIsSet = true;}
void SetDefaultValue(UTFstring & aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();}
UTFstring DefaultVal() const {assert(DefaultIsSet); return DefaultValue;}
UTFstring DefaultVal() const {assert(DefaultISset()); return DefaultValue;}
bool IsDefaultValue() const {
return (DefaultISset() && Value == DefaultValue);

View File

@ -56,7 +56,7 @@ class EBML_DLL_API EbmlVoid : public EbmlBinary {
/*!
\brief Set the size of the data (not the complete size of the element)
*/
void SetSize(uint64 aSize) {Size = aSize;}
void SetSize(uint64 aSize) {SetSize_(aSize);}
/*!
\note overwrite to write fake data

View File

@ -50,9 +50,9 @@ EbmlBinary::EbmlBinary(const EbmlBinary & ElementToClone)
if (ElementToClone.Data == NULL)
Data = NULL;
else {
Data = (binary *)malloc(Size * sizeof(binary));
Data = (binary *)malloc(GetSize() * sizeof(binary));
assert(Data != NULL);
memcpy(Data, ElementToClone.Data, Size);
memcpy(Data, ElementToClone.Data, GetSize());
}
}
@ -63,9 +63,9 @@ EbmlBinary::~EbmlBinary(void) {
uint32 EbmlBinary::RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact)
{
output.writeFully(Data,Size);
output.writeFully(Data,GetSize());
return Size;
return GetSize();
}
/*!
@ -73,7 +73,7 @@ uint32 EbmlBinary::RenderData(IOCallback & output, bool bForceRender, bool bKeep
*/
uint64 EbmlBinary::UpdateSize(bool bKeepIntact, bool bForceRender)
{
return Size;
return GetSize();
}
uint64 EbmlBinary::ReadData(IOCallback & input, ScopeMode ReadFully)
@ -84,18 +84,18 @@ uint64 EbmlBinary::ReadData(IOCallback & input, ScopeMode ReadFully)
if (ReadFully == SCOPE_NO_DATA)
{
Data = NULL;
return Size;
return GetSize();
}
Data = (binary *)malloc(Size * sizeof(binary));
Data = (binary *)malloc(GetSize() * sizeof(binary));
assert(Data != NULL);
bValueIsSet = true;
return input.read(Data, Size);
SetValueIsSet();
return input.read(Data, GetSize());
}
bool EbmlBinary::operator==(const EbmlBinary & ElementToCompare) const
{
return ((Size == ElementToCompare.Size) && !memcmp(Data, ElementToCompare.Data, Size));
return ((GetSize() == ElementToCompare.GetSize()) && !memcmp(Data, ElementToCompare.Data, GetSize()));
}
END_LIBEBML_NAMESPACE

View File

@ -156,11 +156,11 @@ const uint32 EbmlCrc32::m_tab[] = {
EbmlCrc32::EbmlCrc32()
{
ResetCRC();
DefaultSize = DIGESTSIZE;
SetDefaultSize(DIGESTSIZE);
m_crc_final = 0;
Size = 4;
SetSize_(4);
//This EbmlElement has been set
// bValueIsSet = true;
// SetValueIsSet();
}
EbmlCrc32::EbmlCrc32(const EbmlCrc32 & ElementToClone)
@ -201,14 +201,14 @@ uint32 EbmlCrc32::RenderData(IOCallback & output, bool bForceRender, bool bKeepI
output.writeFully(&m_crc_final, Result);
}
if (Result < DefaultSize) {
if (Result < GetDefaultSize()) {
// pad the rest with 0
binary *Pad = new binary[DefaultSize - Result];
binary *Pad = new binary[GetDefaultSize() - Result];
if (Pad != NULL) {
memset(Pad, 0x00, DefaultSize - Result);
output.writeFully(Pad, DefaultSize - Result);
memset(Pad, 0x00, GetDefaultSize() - Result);
output.writeFully(Pad, GetDefaultSize() - Result);
Result = DefaultSize;
Result = GetDefaultSize();
delete [] Pad;
}
}
@ -220,20 +220,20 @@ uint64 EbmlCrc32::ReadData(IOCallback & input, ScopeMode ReadFully)
{
if (ReadFully != SCOPE_NO_DATA)
{
binary *Buffer = new binary[Size];
binary *Buffer = new binary[GetSize()];
if (Buffer == NULL) {
// impossible to read, skip it
input.setFilePointer(Size, seek_current);
input.setFilePointer(GetSize(), seek_current);
} else {
input.readFully(Buffer, Size);
input.readFully(Buffer, GetSize());
memcpy((void *)&m_crc_final, Buffer, 4);
delete [] Buffer;
bValueIsSet = true;
SetValueIsSet();
}
}
return Size;
return GetSize();
}
bool EbmlCrc32::CheckCRC(uint32 inputCRC, const binary *input, uint32 length)
@ -333,7 +333,7 @@ void EbmlCrc32::Finalize()
//Reset the holding CRC member (m_crc)
ResetCRC();
//This EbmlElement has been set
bValueIsSet = true;
SetValueIsSet();
}
END_LIBEBML_NAMESPACE

View File

@ -49,32 +49,32 @@ uint64 EbmlDate::ReadData(IOCallback & input, ScopeMode ReadFully)
{
if (ReadFully != SCOPE_NO_DATA)
{
if (Size != 0) {
assert(Size == 8);
if (GetSize() != 0) {
assert(GetSize() == 8);
binary Buffer[8];
input.readFully(Buffer, Size);
input.readFully(Buffer, GetSize());
big_int64 b64;
b64.Eval(Buffer);
myDate = b64;
bValueIsSet = true;
SetValueIsSet();
}
}
return Size;
return GetSize();
}
uint32 EbmlDate::RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact)
{
if (Size != 0) {
assert(Size == 8);
if (GetSize() != 0) {
assert(GetSize() == 8);
big_int64 b64(myDate);
output.writeFully(&b64.endian(),Size);
output.writeFully(&b64.endian(),GetSize());
}
return Size;
return GetSize();
}
END_LIBEBML_NAMESPACE

View File

@ -49,7 +49,7 @@ EbmlFloat::EbmlFloat(const EbmlFloat::Precision prec)
EbmlFloat::EbmlFloat(const double aDefaultValue, const EbmlFloat::Precision prec)
:EbmlElement(0, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
{
DefaultIsSet = true;
SetDefaultIsSet();
SetPrecision(prec);
}
@ -66,30 +66,30 @@ EbmlFloat::EbmlFloat(const EbmlFloat & ElementToClone)
*/
uint32 EbmlFloat::RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact)
{
assert(Size == 4 || Size == 8);
assert(GetSize() == 4 || GetSize() == 8);
if (Size == 4) {
if (GetSize() == 4) {
float val = Value;
int Tmp;
memcpy(&Tmp, &val, 4);
big_int32 TmpToWrite(Tmp);
output.writeFully(&TmpToWrite.endian(), Size);
} else if (Size == 8) {
output.writeFully(&TmpToWrite.endian(), GetSize());
} else if (GetSize() == 8) {
double val = Value;
int64 Tmp;
memcpy(&Tmp, &val, 8);
big_int64 TmpToWrite(Tmp);
output.writeFully(&TmpToWrite.endian(), Size);
output.writeFully(&TmpToWrite.endian(), GetSize());
}
return Size;
return GetSize();
}
uint64 EbmlFloat::UpdateSize(bool bKeepIntact, bool bForceRender)
{
if (!bKeepIntact && IsDefaultValue())
return 0;
return Size;
return GetSize();
}
/*!
@ -100,29 +100,29 @@ uint64 EbmlFloat::ReadData(IOCallback & input, ScopeMode ReadFully)
if (ReadFully != SCOPE_NO_DATA)
{
binary Buffer[20];
assert(Size <= 20);
input.readFully(Buffer, Size);
assert(GetSize() <= 20);
input.readFully(Buffer, GetSize());
if (Size == 4) {
if (GetSize() == 4) {
big_int32 TmpRead;
TmpRead.Eval(Buffer);
int32 tmpp = int32(TmpRead);
float val;
memcpy(&val, &tmpp, 4);
Value = val;
bValueIsSet = true;
} else if (Size == 8) {
SetValueIsSet();
} else if (GetSize() == 8) {
big_int64 TmpRead;
TmpRead.Eval(Buffer);
int64 tmpp = int64(TmpRead);
double val;
memcpy(&val, &tmpp, 8);
Value = val;
bValueIsSet = true;
SetValueIsSet();
}
}
return Size;
return GetSize();
}
END_LIBEBML_NAMESPACE

View File

@ -47,8 +47,8 @@ START_LIBEBML_NAMESPACE
EbmlMaster::EbmlMaster(const EbmlSemanticContext & aContext, bool bSizeIsknown)
:EbmlElement(0), Context(aContext), bChecksumUsed(bChecksumUsedByDefault)
{
bSizeIsFinite = bSizeIsknown;
bValueIsSet = true;
SetSizeIsFinite(bSizeIsknown);
SetValueIsSet();
ProcessMandatory();
}
@ -72,7 +72,7 @@ EbmlMaster::EbmlMaster(const EbmlMaster & ElementToClone)
EbmlMaster::~EbmlMaster()
{
assert(!bLocked); // you're trying to delete a locked element !!!
assert(!IsLocked()); // you're trying to delete a locked element !!!
size_t Index;
@ -103,7 +103,7 @@ uint32 EbmlMaster::RenderData(IOCallback & output, bool bForceRender, bool bKeep
Result += (ElementList[Index])->Render(output, bKeepIntact, false ,bForceRender);
}
} else { // new school
MemIOCallback TmpBuf(Size - 6);
MemIOCallback TmpBuf(GetSize() - 6);
for (Index = 0; Index < ElementList.size(); Index++) {
if (!bKeepIntact && (ElementList[Index])->IsDefaultValue())
continue;
@ -129,9 +129,9 @@ bool EbmlMaster::PushElement(EbmlElement & element)
uint64 EbmlMaster::UpdateSize(bool bKeepIntact, bool bForceRender)
{
Size = 0;
SetSize_(0);
if (!bSizeIsFinite)
if (!IsFiniteSize())
return (0-1);
if (!bForceRender) {
@ -149,13 +149,13 @@ uint64 EbmlMaster::UpdateSize(bool bKeepIntact, bool bForceRender)
if (SizeToAdd == (0-1))
return (0-1);
#endif // DEBUG
Size += SizeToAdd;
SetSize_(GetSize() + SizeToAdd);
}
if (bChecksumUsed) {
Size += Checksum.ElementSize();
SetSize_(GetSize() + Checksum.ElementSize());
}
return Size;
return GetSize();
}
uint32 EbmlMaster::WriteHead(IOCallback & output, int nSizeLength, bool bKeepIntact)
@ -169,8 +169,8 @@ uint32 EbmlMaster::WriteHead(IOCallback & output, int nSizeLength, bool bKeepInt
*/
uint64 EbmlMaster::ReadData(IOCallback & input, ScopeMode ReadFully)
{
input.setFilePointer(Size, seek_current);
return Size;
input.setFilePointer(GetSize(), seek_current);
return GetSize();
}
/*!
@ -409,11 +409,11 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo
}
}
ElementList.clear();
uint64 MaxSizeToRead = Size;
uint64 MaxSizeToRead = GetSize();
// read blocks and discard the ones we don't care about
if (MaxSizeToRead > 0) {
inDataStream.I_O().setFilePointer(SizePosition + SizeLength, seek_beginning);
inDataStream.I_O().setFilePointer(GetSizePosition() + GetSizeLength(), seek_beginning);
ElementLevelA = inDataStream.FindNextElement(sContext, UpperEltFound, MaxSizeToRead, AllowDummyElt);
while (ElementLevelA != NULL && MaxSizeToRead > 0 && UpperEltFound <= 0) {
MaxSizeToRead = GetEndPosition() - ElementLevelA->GetEndPosition(); // even if it's the default value
@ -464,7 +464,7 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo
Remove(Index--);
}
}
bValueIsSet = true;
SetValueIsSet();
}
}
@ -488,7 +488,7 @@ bool EbmlMaster::VerifyChecksum() const
EbmlCrc32 aChecksum;
/// \todo remove the Checksum if it's in the list
/// \todo find another way when not all default values are saved or (unknown from the reader !!!)
MemIOCallback TmpBuf(Size - 6);
MemIOCallback TmpBuf(GetSize() - 6);
for (size_t Index = 0; Index < ElementList.size(); Index++) {
(ElementList[Index])->Render(TmpBuf, true, false, true);
}

View File

@ -45,7 +45,7 @@ EbmlSInteger::EbmlSInteger()
EbmlSInteger::EbmlSInteger(int64 aDefaultValue)
:EbmlElement(DEFAULT_INT_SIZE, true), Value(aDefaultValue)
{
DefaultIsSet = true;
SetDefaultIsSet();
}
EbmlSInteger::EbmlSInteger(const EbmlSInteger & ElementToClone)
@ -63,18 +63,18 @@ uint32 EbmlSInteger::RenderData(IOCallback & output, bool bForceRender, bool bKe
binary FinalData[8]; // we don't handle more than 64 bits integers
unsigned int i;
if (SizeLength > 8)
if (GetSizeLength() > 8)
return 0; // integer bigger coded on more than 64 bits are not supported
int64 TempValue = Value;
for (i=0; i<Size;i++) {
FinalData[Size-i-1] = binary(TempValue & 0xFF);
for (i=0; i<GetSize();i++) {
FinalData[GetSize()-i-1] = binary(TempValue & 0xFF);
TempValue >>= 8;
}
output.writeFully(FinalData,Size);
output.writeFully(FinalData,GetSize());
return Size;
return GetSize();
}
uint64 EbmlSInteger::UpdateSize(bool bKeepIntact, bool bForceRender)
@ -83,31 +83,31 @@ uint64 EbmlSInteger::UpdateSize(bool bKeepIntact, bool bForceRender)
return 0;
if (Value <= 0x7F && Value >= (-0x80)) {
Size = 1;
SetSize_(1);
} else if (Value <= 0x7FFF && Value >= (-0x8000)) {
Size = 2;
SetSize_(2);
} else if (Value <= 0x7FFFFF && Value >= (-0x800000)) {
Size = 3;
SetSize_(3);
} else if (Value <= 0x7FFFFFFF && Value >= (-0x80000000)) {
Size = 4;
SetSize_(4);
} else if (Value <= EBML_PRETTYLONGINT(0x7FFFFFFFFF) &&
Value >= EBML_PRETTYLONGINT(-0x8000000000)) {
Size = 5;
SetSize_(5);
} else if (Value <= EBML_PRETTYLONGINT(0x7FFFFFFFFFFF) &&
Value >= EBML_PRETTYLONGINT(-0x800000000000)) {
Size = 6;
SetSize_(6);
} else if (Value <= EBML_PRETTYLONGINT(0x7FFFFFFFFFFFFF) &&
Value >= EBML_PRETTYLONGINT(-0x80000000000000)) {
Size = 7;
SetSize_(7);
} else {
Size = 8;
SetSize_(8);
}
if (DefaultSize > Size) {
Size = DefaultSize;
if (GetDefaultSize() > GetSize()) {
SetSize_(GetDefaultSize());
}
return Size;
return GetSize();
}
uint64 EbmlSInteger::ReadData(IOCallback & input, ScopeMode ReadFully)
@ -115,22 +115,22 @@ uint64 EbmlSInteger::ReadData(IOCallback & input, ScopeMode ReadFully)
if (ReadFully != SCOPE_NO_DATA)
{
binary Buffer[8];
input.readFully(Buffer, Size);
input.readFully(Buffer, GetSize());
if (Buffer[0] & 0x80)
Value = -1; // this is a negative value
else
Value = 0; // this is a positive value
for (unsigned int i=0; i<Size; i++)
for (unsigned int i=0; i<GetSize(); i++)
{
Value <<= 8;
Value |= Buffer[i];
}
bValueIsSet = true;
SetValueIsSet();
}
return Size;
return GetSize();
}
END_LIBEBML_NAMESPACE

View File

@ -42,22 +42,22 @@ START_LIBEBML_NAMESPACE
EbmlString::EbmlString()
:EbmlElement(0, false)
{
DefaultSize = 0;
SetDefaultSize(0);
/* done automatically
Size = Value.length();
if (DefaultSize > Size)
Size = DefaultSize;*/
SetSize_(Value.length());
if (GetDefaultSize() > GetSize())
SetSize_(GetDefaultSize());*/
}
EbmlString::EbmlString(const std::string & aDefaultValue)
:EbmlElement(0, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
{
DefaultSize = 0;
DefaultIsSet = true;
SetDefaultSize(0);
SetDefaultIsSet();
/* done automatically
Size = Value.length();
if (DefaultSize > Size)
Size = DefaultSize;*/
SetSize_(Value.length());
if (GetDefaultSize() > GetSize())
SetSize_(GetDefaultSize());*/
}
/*!
@ -79,16 +79,16 @@ uint32 EbmlString::RenderData(IOCallback & output, bool bForceRender, bool bKeep
output.writeFully(Value.c_str(), Value.length());
Result = Value.length();
if (Result < DefaultSize) {
if (Result < GetDefaultSize()) {
// pad the rest with 0
binary *Pad = new binary[DefaultSize - Result];
binary *Pad = new binary[GetDefaultSize() - Result];
if (Pad == NULL)
{
return Result;
}
memset(Pad, 0x00, DefaultSize - Result);
output.writeFully(Pad, DefaultSize - Result);
Result = DefaultSize;
memset(Pad, 0x00, GetDefaultSize() - Result);
output.writeFully(Pad, GetDefaultSize() - Result);
Result = GetDefaultSize();
delete [] Pad;
}
@ -98,11 +98,11 @@ uint32 EbmlString::RenderData(IOCallback & output, bool bForceRender, bool bKeep
EbmlString & EbmlString::operator=(const std::string NewString)
{
Value = NewString;
bValueIsSet = true;
SetValueIsSet();
/* done automatically
Size = Value.length();
if (DefaultSize > Size)
Size = DefaultSize;*/
SetSize_(Value.length());
if (GetDefaultSize() > GetSize())
SetSize_(GetDefaultSize());*/
return *this;
}
@ -111,39 +111,39 @@ uint64 EbmlString::UpdateSize(bool bKeepIntact, bool bForceRender)
if (!bKeepIntact && IsDefaultValue())
return 0;
if (Value.length() < DefaultSize) {
Size = DefaultSize;
if (Value.length() < GetDefaultSize()) {
SetSize_(GetDefaultSize());
} else {
Size = Value.length();
SetSize_(Value.length());
}
return Size;
return GetSize();
}
uint64 EbmlString::ReadData(IOCallback & input, ScopeMode ReadFully)
{
if (ReadFully != SCOPE_NO_DATA)
{
if (Size == 0) {
if (GetSize() == 0) {
Value = "";
bValueIsSet = true;
SetValueIsSet();
} else {
char *Buffer = new char[Size + 1];
char *Buffer = new char[GetSize() + 1];
if (Buffer == NULL) {
// unable to store the data, skip it
input.setFilePointer(Size, seek_current);
input.setFilePointer(GetSize(), seek_current);
} else {
input.readFully(Buffer, Size);
if (Buffer[Size-1] != '\0') {
Buffer[Size] = '\0';
input.readFully(Buffer, GetSize());
if (Buffer[GetSize()-1] != '\0') {
Buffer[GetSize()] = '\0';
}
Value = Buffer;
delete [] Buffer;
bValueIsSet = true;
SetValueIsSet();
}
}
}
return Size;
return GetSize();
}
END_LIBEBML_NAMESPACE

View File

@ -47,7 +47,7 @@ EbmlUInteger::EbmlUInteger()
EbmlUInteger::EbmlUInteger(uint64 aDefaultValue)
:EbmlElement(DEFAULT_UINT_SIZE, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
{
DefaultIsSet = true;
SetDefaultIsSet();
}
EbmlUInteger::EbmlUInteger(const EbmlUInteger & ElementToClone)
@ -64,18 +64,18 @@ uint32 EbmlUInteger::RenderData(IOCallback & output, bool bForceRender, bool bKe
{
binary FinalData[8]; // we don't handle more than 64 bits integers
if (SizeLength > 8)
if (GetSizeLength() > 8)
return 0; // integer bigger coded on more than 64 bits are not supported
uint64 TempValue = Value;
for (unsigned int i=0; i<Size;i++) {
FinalData[Size-i-1] = TempValue & 0xFF;
for (unsigned int i=0; i<GetSize();i++) {
FinalData[GetSize()-i-1] = TempValue & 0xFF;
TempValue >>= 8;
}
output.writeFully(FinalData,Size);
output.writeFully(FinalData,GetSize());
return Size;
return GetSize();
}
uint64 EbmlUInteger::UpdateSize(bool bKeepIntact, bool bForceRender)
@ -84,28 +84,28 @@ uint64 EbmlUInteger::UpdateSize(bool bKeepIntact, bool bForceRender)
return 0;
if (Value <= 0xFF) {
Size = 1;
SetSize_(1);
} else if (Value <= 0xFFFF) {
Size = 2;
SetSize_(2);
} else if (Value <= 0xFFFFFF) {
Size = 3;
SetSize_(3);
} else if (Value <= 0xFFFFFFFF) {
Size = 4;
SetSize_(4);
} else if (Value <= EBML_PRETTYLONGINT(0xFFFFFFFFFF)) {
Size = 5;
SetSize_(5);
} else if (Value <= EBML_PRETTYLONGINT(0xFFFFFFFFFFFF)) {
Size = 6;
SetSize_(6);
} else if (Value <= EBML_PRETTYLONGINT(0xFFFFFFFFFFFFFF)) {
Size = 7;
SetSize_(7);
} else {
Size = 8;
SetSize_(8);
}
if (DefaultSize > Size) {
Size = DefaultSize;
if (GetDefaultSize() > GetSize()) {
SetSize_(GetDefaultSize());
}
return Size;
return GetSize();
}
uint64 EbmlUInteger::ReadData(IOCallback & input, ScopeMode ReadFully)
@ -113,18 +113,18 @@ uint64 EbmlUInteger::ReadData(IOCallback & input, ScopeMode ReadFully)
if (ReadFully != SCOPE_NO_DATA)
{
binary Buffer[8];
input.readFully(Buffer, Size);
input.readFully(Buffer, GetSize());
Value = 0;
for (unsigned int i=0; i<Size; i++)
for (unsigned int i=0; i<GetSize(); i++)
{
Value <<= 8;
Value |= Buffer[i];
}
bValueIsSet = true;
SetValueIsSet();
}
return Size;
return GetSize();
}
END_LIBEBML_NAMESPACE

View File

@ -207,14 +207,14 @@ bool UTFstring::wcscmp_internal(const wchar_t *str1, const wchar_t *str2)
EbmlUnicodeString::EbmlUnicodeString()
:EbmlElement(0, false)
{
DefaultSize = 0;
SetDefaultSize(0);
}
EbmlUnicodeString::EbmlUnicodeString(const UTFstring & aDefaultValue)
:EbmlElement(0, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
{
DefaultSize = 0;
DefaultIsSet = true;
SetDefaultSize(0);
SetDefaultIsSet();
}
EbmlUnicodeString::EbmlUnicodeString(const EbmlUnicodeString & ElementToClone)
@ -236,14 +236,14 @@ uint32 EbmlUnicodeString::RenderData(IOCallback & output, bool bForceRender, boo
output.writeFully(Value.GetUTF8().c_str(), Result);
}
if (Result < DefaultSize) {
if (Result < GetDefaultSize()) {
// pad the rest with 0
binary *Pad = new binary[DefaultSize - Result];
binary *Pad = new binary[GetDefaultSize() - Result];
if (Pad != NULL) {
memset(Pad, 0x00, DefaultSize - Result);
output.writeFully(Pad, DefaultSize - Result);
memset(Pad, 0x00, GetDefaultSize() - Result);
output.writeFully(Pad, GetDefaultSize() - Result);
Result = DefaultSize;
Result = GetDefaultSize();
delete [] Pad;
}
}
@ -254,7 +254,7 @@ uint32 EbmlUnicodeString::RenderData(IOCallback & output, bool bForceRender, boo
EbmlUnicodeString & EbmlUnicodeString::operator=(const UTFstring & NewString)
{
Value = NewString;
bValueIsSet = true;
SetValueIsSet();
return *this;
}
@ -266,11 +266,11 @@ uint64 EbmlUnicodeString::UpdateSize(bool bKeepIntact, bool bForceRender)
if (!bKeepIntact && IsDefaultValue())
return 0;
Size = Value.GetUTF8().length();
if (Size < DefaultSize)
Size = DefaultSize;
SetSize_(Value.GetUTF8().length());
if (GetSize() < GetDefaultSize())
SetSize_(GetDefaultSize());
return Size;
return GetSize();
}
/*!
@ -280,28 +280,28 @@ uint64 EbmlUnicodeString::ReadData(IOCallback & input, ScopeMode ReadFully)
{
if (ReadFully != SCOPE_NO_DATA)
{
if (Size == 0) {
if (GetSize() == 0) {
Value = UTFstring::value_type(0);
bValueIsSet = true;
SetValueIsSet();
} else {
char *Buffer = new char[Size+1];
char *Buffer = new char[GetSize()+1];
if (Buffer == NULL) {
// impossible to read, skip it
input.setFilePointer(Size, seek_current);
input.setFilePointer(GetSize(), seek_current);
} else {
input.readFully(Buffer, Size);
if (Buffer[Size-1] != 0) {
Buffer[Size] = 0;
input.readFully(Buffer, GetSize());
if (Buffer[GetSize()-1] != 0) {
Buffer[GetSize()] = 0;
}
Value.SetUTF8(Buffer); // implicit conversion to std::string
delete [] Buffer;
bValueIsSet = true;
SetValueIsSet();
}
}
}
return Size;
return GetSize();
}
END_LIBEBML_NAMESPACE

View File

@ -43,7 +43,7 @@ const EbmlCallbacks EbmlVoid::ClassInfos(EbmlVoid::Create, EbmlVoid_TheId, "EBML
EbmlVoid::EbmlVoid()
{
bValueIsSet = true;
SetValueIsSet();
}
uint32 EbmlVoid::RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact)
@ -51,24 +51,24 @@ uint32 EbmlVoid::RenderData(IOCallback & output, bool bForceRender, bool bKeepIn
// write dummy data by 4KB chunks
static binary DummyBuf[4*1024];
uint64 SizeToWrite = Size;
uint64 SizeToWrite = GetSize();
while (SizeToWrite > 4*1024)
{
output.writeFully(DummyBuf, 4*1024);
SizeToWrite -= 4*1024;
}
output.writeFully(DummyBuf, SizeToWrite);
return Size;
return GetSize();
}
uint64 EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output, bool ComeBackAfterward, bool bKeepIntact)
{
EltToReplaceWith.UpdateSize(bKeepIntact);
if (HeadSize() + Size < EltToReplaceWith.GetSize() + EltToReplaceWith.HeadSize()) {
if (HeadSize() + GetSize() < EltToReplaceWith.GetSize() + EltToReplaceWith.HeadSize()) {
// the element can't be written here !
return 0;
}
if (HeadSize() + Size - EltToReplaceWith.GetSize() - EltToReplaceWith.HeadSize() == 1) {
if (HeadSize() + GetSize() - EltToReplaceWith.GetSize() - EltToReplaceWith.HeadSize() == 1) {
// there is not enough space to put a filling element
return 0;
}
@ -78,15 +78,15 @@ uint64 EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output
output.setFilePointer(GetElementPosition());
EltToReplaceWith.Render(output, bKeepIntact);
if (HeadSize() + Size - EltToReplaceWith.GetSize() - EltToReplaceWith.HeadSize() > 1) {
if (HeadSize() + GetSize() - EltToReplaceWith.GetSize() - EltToReplaceWith.HeadSize() > 1) {
// fill the rest with another void element
EbmlVoid aTmp;
aTmp.SetSize(HeadSize() + Size - EltToReplaceWith.GetSize() - EltToReplaceWith.HeadSize() - 1); // 1 is the length of the Void ID
aTmp.SetSize_(HeadSize() + GetSize() - EltToReplaceWith.GetSize() - EltToReplaceWith.HeadSize() - 1); // 1 is the length of the Void ID
int HeadBefore = aTmp.HeadSize();
aTmp.SetSize(aTmp.GetSize() - CodedSizeLength(aTmp.Size, aTmp.SizeLength, aTmp.bSizeIsFinite));
aTmp.SetSize_(aTmp.GetSize() - CodedSizeLength(aTmp.GetSize(), aTmp.GetSizeLength(), aTmp.IsFiniteSize()));
int HeadAfter = aTmp.HeadSize();
if (HeadBefore != HeadAfter) {
aTmp.SetSizeLength(CodedSizeLength(aTmp.Size, aTmp.SizeLength, aTmp.bSizeIsFinite) - (HeadAfter - HeadBefore));
aTmp.SetSizeLength(CodedSizeLength(aTmp.GetSize(), aTmp.GetSizeLength(), aTmp.IsFiniteSize()) - (HeadAfter - HeadBefore));
}
aTmp.RenderHead(output, false, bKeepIntact); // the rest of the data is not rewritten
}
@ -95,7 +95,7 @@ uint64 EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output
output.setFilePointer(CurrentPosition);
}
return Size + HeadSize();
return GetSize() + HeadSize();
}
uint64 EbmlVoid::Overwrite(const EbmlElement & EltToVoid, IOCallback & output, bool ComeBackAfterward, bool bKeepIntact)
@ -115,17 +115,17 @@ uint64 EbmlVoid::Overwrite(const EbmlElement & EltToVoid, IOCallback & output, b
output.setFilePointer(EltToVoid.GetElementPosition());
// compute the size of the voided data based on the original one
Size = EltToVoid.GetSize() + EltToVoid.HeadSize() - 1; // 1 for the ID
Size -= CodedSizeLength(Size, SizeLength, bSizeIsFinite);
SetSize(EltToVoid.GetSize() + EltToVoid.HeadSize() - 1); // 1 for the ID
SetSize(GetSize() - CodedSizeLength(GetSize(), GetSizeLength(), IsFiniteSize()));
// make sure we handle even the strange cases
//uint32 A1 = Size + HeadSize();
//uint32 A1 = GetSize() + HeadSize();
//uint32 A2 = EltToVoid.GetSize() + EltToVoid.HeadSize();
if (Size + HeadSize() != EltToVoid.GetSize() + EltToVoid.HeadSize()) {
Size--;
SetSizeLength(CodedSizeLength(Size, SizeLength, bSizeIsFinite) + 1);
if (GetSize() + HeadSize() != EltToVoid.GetSize() + EltToVoid.HeadSize()) {
SetSize(GetSize()-1);
SetSizeLength(CodedSizeLength(GetSize(), GetSizeLength(), IsFiniteSize()) + 1);
}
if (Size != 0) {
if (GetSize() != 0) {
RenderHead(output, false, bKeepIntact); // the rest of the data is not rewritten
}