cosmetics: unify indentation

This commit is contained in:
Moritz Bunkus 2014-12-19 14:40:44 +01:00
parent 34554928aa
commit ce72b9266a
18 changed files with 289 additions and 326 deletions

View File

@ -56,11 +56,11 @@ class ADbg globalDebug;
//////////////////////////////////////////////////////////////////////
ADbg::ADbg(int level)
:my_level(level)
,my_time_included(false)
,my_use_file(false)
,my_debug_output(true)
,hFile(NULL)
:my_level(level)
,my_time_included(false)
,my_use_file(false)
,my_debug_output(true)
,hFile(NULL)
{
prefix[0] = '\0';
OutPut(-1,"ADbg Creation at debug level = %d (0x%08X)",my_level,this);
@ -85,25 +85,25 @@ inline int ADbg::_OutPut(const char * format,va_list params) const
GetSystemTime(&time);
if (prefix[0] == '\0')
wsprintfA(myformat,"%04d/%02d/%02d %02d:%02d:%02d.%03d UTC : %s\r\n",
time.wYear,
time.wMonth,
time.wDay,
time.wHour,
time.wMinute,
time.wSecond,
time.wMilliseconds,
format);
time.wYear,
time.wMonth,
time.wDay,
time.wHour,
time.wMinute,
time.wSecond,
time.wMilliseconds,
format);
else
wsprintfA(myformat,"%04d/%02d/%02d %02d:%02d:%02d.%03d UTC : %s - %s\r\n",
time.wYear,
time.wMonth,
time.wDay,
time.wHour,
time.wMinute,
time.wSecond,
time.wMilliseconds,
prefix,
format);
time.wYear,
time.wMonth,
time.wDay,
time.wHour,
time.wMinute,
time.wSecond,
time.wMilliseconds,
prefix,
format);
} else {
if (prefix[0] == '\0')
wsprintfA( myformat, "%s\r\n", format);
@ -131,14 +131,14 @@ inline int ADbg::_OutPut(const char * format,va_list params) const
now = gmtime(&nowSecs);
if (prefix[0] == '\0')
sprintf(myformat,"%04d/%02d/%02d %02d:%02d:%02ld.%03ld UTC : %s\r\n",
now->tm_year, now->tm_mon, now->tm_mday,
now->tm_hour, now->tm_min, tv.tv_sec,
(long)tv.tv_usec / 1000, format);
now->tm_year, now->tm_mon, now->tm_mday,
now->tm_hour, now->tm_min, tv.tv_sec,
(long)tv.tv_usec / 1000, format);
else
sprintf(myformat,"%04d/%02d/%02d %02d:%02d:%02ld.%03ld UTC : %s - %s\r\n",
now->tm_year, now->tm_mon, now->tm_mday,
now->tm_hour, now->tm_min, tv.tv_sec,
(long)tv.tv_usec / 1000, prefix, format);
now->tm_year, now->tm_mon, now->tm_mday,
now->tm_hour, now->tm_min, tv.tv_sec,
(long)tv.tv_usec / 1000, prefix, format);
} else {
if (prefix[0] == '\0')
@ -188,46 +188,49 @@ bool ADbg::setDebugFile(const char * NewFilename) {
bool result;
result = unsetDebugFile();
if (result) {
result = false;
if (!result)
return false;
result = false;
#ifdef WIN32
hFile = CreateFileA(NewFilename, GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
hFile = CreateFileA(NewFilename, GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if (hFile != INVALID_HANDLE_VALUE) {
SetFilePointer( hFile, 0, 0, FILE_END );
if (hFile != INVALID_HANDLE_VALUE) {
SetFilePointer( hFile, 0, 0, FILE_END );
result = true;
#else
hFile = fopen(NewFilename, "w+");
if (hFile != NULL) {
fseek(hFile, 0, SEEK_END);
#endif
OutPut(-1,"Debug hFile Opening succeeded");
}
else
OutPut(-1,"Debug hFile %s Opening failed",NewFilename);
result = true;
}
#else
hFile = fopen(NewFilename, "w+");
if (hFile != NULL) {
fseek(hFile, 0, SEEK_END);
result = true;
}
#endif
if (result)
OutPut(-1,"Debug hFile Opening succeeded");
else
OutPut(-1,"Debug hFile %s Opening failed",NewFilename);
return result;
}
bool ADbg::unsetDebugFile() {
bool result = (hFile == NULL);
if (result)
return true;
#ifdef WIN32
if (hFile != NULL) {
result = (CloseHandle(hFile) != 0);
result = (CloseHandle(hFile) != 0);
#else
if (hFile != NULL) {
result = (fclose(hFile) == 0);
result = (fclose(hFile) == 0);
#endif
if (result) {
OutPut(-1,"Debug hFile Closing succeeded");
hFile = NULL;
}
if (result) {
OutPut(-1,"Debug hFile Closing succeeded");
hFile = NULL;
}
return result;
}

View File

@ -43,11 +43,11 @@
START_LIBEBML_NAMESPACE
EbmlBinary::EbmlBinary()
:EbmlElement(0, false), Data(NULL)
:EbmlElement(0, false), Data(NULL)
{}
EbmlBinary::EbmlBinary(const EbmlBinary & ElementToClone)
:EbmlElement(ElementToClone)
:EbmlElement(ElementToClone)
{
if (ElementToClone.Data == NULL)
Data = NULL;
@ -86,14 +86,13 @@ filepos_t EbmlBinary::ReadData(IOCallback & input, ScopeMode ReadFully)
if (Data != NULL)
free(Data);
if (ReadFully == SCOPE_NO_DATA || !GetSize())
{
if (ReadFully == SCOPE_NO_DATA || !GetSize()) {
Data = NULL;
return GetSize();
}
Data = (binary *)malloc(GetSize());
if (Data == NULL)
if (Data == NULL)
throw CRTError(std::string("Error allocating data"));
SetValueIsSet();
return input.read(Data, GetSize());

View File

@ -169,11 +169,11 @@ EbmlCrc32::EbmlCrc32()
m_crc_final = 0;
SetSize_(4);
//This EbmlElement has been set
// SetValueIsSet();
// SetValueIsSet();
}
EbmlCrc32::EbmlCrc32(const EbmlCrc32 & ElementToClone)
:EbmlBinary(ElementToClone)
:EbmlBinary(ElementToClone)
{
m_crc = ElementToClone.m_crc;
m_crc_final = ElementToClone.m_crc_final;
@ -181,12 +181,12 @@ EbmlCrc32::EbmlCrc32(const EbmlCrc32 & ElementToClone)
void EbmlCrc32::ResetCRC()
{
m_crc = CRC32_NEGL;
m_crc = CRC32_NEGL;
}
void EbmlCrc32::UpdateByte(binary b)
{
m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);
m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);
}
void EbmlCrc32::AddElementCRC32(EbmlElement &ElementToCRC)
@ -196,7 +196,7 @@ void EbmlCrc32::AddElementCRC32(EbmlElement &ElementToCRC)
ElementToCRC.Render(memoryBuffer, true, true);
Update(memoryBuffer.GetDataBuffer(), memoryBuffer.GetDataBufferSize());
// Finalize();
// Finalize();
};
bool EbmlCrc32::CheckElementCRC32(EbmlElement &ElementToCRC)
@ -212,7 +212,7 @@ filepos_t EbmlCrc32::RenderData(IOCallback & output, bool /* bForceRender */, bo
filepos_t Result = 4;
if (Result != 0) {
output.writeFully(&m_crc_final, Result);
output.writeFully(&m_crc_final, Result);
}
if (Result < GetDefaultSize()) {
@ -232,8 +232,7 @@ filepos_t EbmlCrc32::RenderData(IOCallback & output, bool /* bForceRender */, bo
filepos_t EbmlCrc32::ReadData(IOCallback & input, ScopeMode ReadFully)
{
if (ReadFully != SCOPE_NO_DATA)
{
if (ReadFully != SCOPE_NO_DATA) {
binary *Buffer = new (std::nothrow) binary[GetSize()];
if (Buffer == NULL) {
// impossible to read, skip it
@ -257,8 +256,7 @@ bool EbmlCrc32::CheckCRC(uint32 inputCRC, const binary *input, uint32 length)
for(; !IsAligned<uint32>(input) && length > 0; length--)
crc = m_tab[CRC32_INDEX(crc) ^ *input++] ^ CRC32_SHIFTED(crc);
while (length >= 4)
{
while (length >= 4) {
crc ^= *(const uint32 *)input;
crc = m_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);
crc = m_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);
@ -321,8 +319,7 @@ void EbmlCrc32::Update(const binary *input, uint32 length)
for(; !IsAligned<uint32>(input) && length > 0; length--)
crc = m_tab[CRC32_INDEX(crc) ^ *input++] ^ CRC32_SHIFTED(crc);
while (length >= 4)
{
while (length >= 4) {
crc ^= *(const uint32 *)input;
crc = m_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);
crc = m_tab[CRC32_INDEX(crc)] ^ CRC32_SHIFTED(crc);

View File

@ -47,20 +47,18 @@ EbmlDate::EbmlDate(const EbmlDate & ElementToClone)
filepos_t EbmlDate::ReadData(IOCallback & input, ScopeMode ReadFully)
{
if (ReadFully != SCOPE_NO_DATA)
{
if (GetSize() != 0) {
assert(GetSize() == 8);
binary Buffer[8];
input.readFully(Buffer, GetSize());
if ((ReadFully == SCOPE_NO_DATA) || (GetSize() == 0))
return GetSize();
big_int64 b64;
b64.Eval(Buffer);
assert(GetSize() == 8);
binary Buffer[8];
input.readFully(Buffer, GetSize());
myDate = b64;
SetValueIsSet();
}
}
big_int64 b64;
b64.Eval(Buffer);
myDate = b64;
SetValueIsSet();
return GetSize();
}

View File

@ -44,7 +44,7 @@ const EbmlId EbmlDummy::DummyRawId = Id_EbmlDummy;
EbmlDummy::operator const EbmlId &()
{
return DummyId;
return DummyId;
}
END_LIBEBML_NAMESPACE

View File

@ -181,22 +181,20 @@ int64 ReadCodedSizeSignedValue(const binary * InBuffer, uint32 & BufferSize, uin
{
int64 Result = ReadCodedSizeValue(InBuffer, BufferSize, SizeUnknown);
if (BufferSize != 0)
{
switch (BufferSize)
{
case 1:
Result -= 63;
break;
case 2:
Result -= 8191;
break;
case 3:
Result -= 1048575L;
break;
case 4:
Result -= 134217727L;
break;
if (BufferSize != 0) {
switch (BufferSize) {
case 1:
Result -= 63;
break;
case 2:
Result -= 8191;
break;
case 3:
Result -= 1048575L;
break;
case 4:
Result -= 134217727L;
break;
}
}
@ -215,43 +213,43 @@ EbmlCallbacks::EbmlCallbacks(EbmlElement & (*Creator)(), const EbmlId & aGlobalI
const EbmlSemantic & EbmlSemanticContext::GetSemantic(size_t i) const
{
assert(i<Size);
if (i<Size)
return MyTable[i];
else
return *(EbmlSemantic*)NULL;
assert(i<Size);
if (i<Size)
return MyTable[i];
else
return *(EbmlSemantic*)NULL;
}
EbmlElement::EbmlElement(uint64 aDefaultSize, bool bValueSet)
:DefaultSize(aDefaultSize)
,SizeLength(0) ///< write optimal size by default
,bSizeIsFinite(true)
,ElementPosition(0)
,SizePosition(0)
,bValueIsSet(bValueSet)
,DefaultIsSet(false)
,bLocked(false)
:DefaultSize(aDefaultSize)
,SizeLength(0) ///< write optimal size by default
,bSizeIsFinite(true)
,ElementPosition(0)
,SizePosition(0)
,bValueIsSet(bValueSet)
,DefaultIsSet(false)
,bLocked(false)
{
Size = DefaultSize;
}
EbmlElement::EbmlElement(const EbmlElement & ElementToClone)
:Size(ElementToClone.Size)
,DefaultSize(ElementToClone.DefaultSize)
,SizeLength(ElementToClone.SizeLength)
,bSizeIsFinite(ElementToClone.bSizeIsFinite)
,ElementPosition(ElementToClone.ElementPosition)
,SizePosition(ElementToClone.SizePosition)
,bValueIsSet(ElementToClone.bValueIsSet)
,DefaultIsSet(ElementToClone.DefaultIsSet)
,bLocked(ElementToClone.bLocked)
:Size(ElementToClone.Size)
,DefaultSize(ElementToClone.DefaultSize)
,SizeLength(ElementToClone.SizeLength)
,bSizeIsFinite(ElementToClone.bSizeIsFinite)
,ElementPosition(ElementToClone.ElementPosition)
,SizePosition(ElementToClone.SizePosition)
,bValueIsSet(ElementToClone.bValueIsSet)
,DefaultIsSet(ElementToClone.DefaultIsSet)
,bLocked(ElementToClone.bLocked)
{
}
EbmlElement::~EbmlElement()
{
assert(!bLocked);
assert(!bLocked);
}
/*!
@ -319,8 +317,8 @@ EbmlElement * EbmlElement::FindNextID(IOCallback & DataStream, const EbmlCallbac
} else {
/// \todo find the element in the context
Result = new (std::nothrow) EbmlDummy(PossibleID);
if(Result == NULL)
return NULL;
if(Result == NULL)
return NULL;
}
Result->SetSizeLength(PossibleSizeLength);
@ -328,8 +326,8 @@ EbmlElement * EbmlElement::FindNextID(IOCallback & DataStream, const EbmlCallbac
Result->Size = SizeFound;
if (!Result->ValidateSize() || (SizeFound != SizeUnknown && MaxDataSize < Result->Size)) {
delete Result;
return NULL;
delete Result;
return NULL;
}
// check if the size is not all 1s
@ -356,7 +354,7 @@ EbmlElement * EbmlElement::FindNextID(IOCallback & DataStream, const EbmlCallbac
\param LowLevel Will be returned with the level of the element found compared to the context given
*/
EbmlElement * EbmlElement::FindNextElement(IOCallback & DataStream, const EbmlSemanticContext & Context, int & UpperLevel,
uint64 MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel)
uint64 MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel)
{
int PossibleID_Length = 0;
binary PossibleIdNSize[16];
@ -408,8 +406,7 @@ EbmlElement * EbmlElement::FindNextElement(IOCallback & DataStream, const EbmlSe
// read the data size
uint32 _SizeLength;
PossibleSizeLength = ReadIndex;
while (1)
{
while (1) {
_SizeLength = PossibleSizeLength;
SizeFound = ReadCodedSizeValue(&PossibleIdNSize[PossibleID_Length], _SizeLength, SizeUnknown);
if (_SizeLength != 0) {
@ -474,7 +471,7 @@ EbmlElement * EbmlElement::SkipData(EbmlStream & DataStream, const EbmlSemanticC
assert(TestReadElt == NULL);
assert(ElementPosition < SizePosition);
DataStream.I_O().setFilePointer(SizePosition + CodedSizeLength(Size, SizeLength, bSizeIsFinite) + Size, seek_beginning);
// DataStream.I_O().setFilePointer(Size, seek_current);
// DataStream.I_O().setFilePointer(Size, seek_current);
} else {
/////////////////////////////////////////////////
// read elements until an upper element is found
@ -483,13 +480,13 @@ EbmlElement * EbmlElement::SkipData(EbmlStream & DataStream, const EbmlSemanticC
while (!bEndFound && Result == NULL) {
// read an element
/// \todo 0xFF... and true should be configurable
// EbmlElement * NewElt;
// EbmlElement * NewElt;
if (TestReadElt == NULL) {
int bUpperElement = 0; // trick to call FindNextID correctly
Result = DataStream.FindNextElement(Context, bUpperElement, 0xFFFFFFFFL, AllowDummyElt);
} else {
Result = TestReadElt;
TestReadElt = NULL;
TestReadElt = NULL;
}
if (Result != NULL) {
@ -524,7 +521,7 @@ EbmlElement * EbmlElement::SkipData(EbmlStream & DataStream, const EbmlSemanticC
}
EbmlElement *EbmlElement::CreateElementUsingContext(const EbmlId & aID, const EbmlSemanticContext & Context,
int & LowLevel, bool IsGlobalContext, bool bAllowDummy, unsigned int MaxLowerLevel)
int & LowLevel, bool IsGlobalContext, bool bAllowDummy, unsigned int MaxLowerLevel)
{
unsigned int ContextIndex;
EbmlElement *Result = NULL;
@ -532,7 +529,7 @@ EbmlElement *EbmlElement::CreateElementUsingContext(const EbmlId & aID, const Eb
// elements at the current level
for (ContextIndex = 0; ContextIndex < EBML_CTX_SIZE(Context); ContextIndex++) {
if (aID == EBML_CTX_IDX_ID(Context,ContextIndex)) {
return &EBML_SEM_CREATE(EBML_CTX_IDX(Context,ContextIndex));
return &EBML_SEM_CREATE(EBML_CTX_IDX(Context,ContextIndex));
}
}
@ -580,7 +577,7 @@ EbmlElement *EbmlElement::CreateElementUsingContext(const EbmlId & aID, const Eb
filepos_t EbmlElement::Render(IOCallback & output, bool bWithDefault, bool bKeepPosition, bool bForceRender)
{
assert(bValueIsSet || (bWithDefault && DefaultISset())); // an element is been rendered without a value set !!!
// it may be a mandatory element without a default value
// it may be a mandatory element without a default value
try {
if (!bWithDefault && IsDefaultValue()) {
return 0;
@ -591,12 +588,13 @@ filepos_t EbmlElement::Render(IOCallback & output, bool bWithDefault, bool bKeep
filepos_t result = RenderHead(output, bForceRender, bWithDefault, bKeepPosition);
uint64 WrittenSize = RenderData(output, bForceRender, bWithDefault);
#if defined(LIBEBML_DEBUG)
if (static_cast<int64>(SupposedSize) != (0-1)) assert(WrittenSize == SupposedSize);
if (static_cast<int64>(SupposedSize) != (0-1))
assert(WrittenSize == SupposedSize);
#endif // LIBEBML_DEBUG
result += WrittenSize;
return result;
} catch (std::exception & ex) {
// const char * What = ex.what();
// const char * What = ex.what();
assert(false); // we should never be here !
return 0;
}

View File

@ -41,36 +41,36 @@
START_LIBEBML_NAMESPACE
EbmlFloat::EbmlFloat(const EbmlFloat::Precision prec)
:EbmlElement(0, false)
:EbmlElement(0, false)
{
SetPrecision(prec);
}
EbmlFloat::EbmlFloat(const double aDefaultValue, const EbmlFloat::Precision prec)
:EbmlElement(0, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
:EbmlElement(0, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
{
SetDefaultIsSet();
SetPrecision(prec);
}
EbmlFloat::EbmlFloat(const EbmlFloat & ElementToClone)
:EbmlElement(ElementToClone)
,Value(ElementToClone.Value)
,DefaultValue(ElementToClone.DefaultValue)
:EbmlElement(ElementToClone)
,Value(ElementToClone.Value)
,DefaultValue(ElementToClone.DefaultValue)
{
}
void EbmlFloat::SetDefaultValue(double aValue)
{
assert(!DefaultISset());
DefaultValue = aValue;
SetDefaultIsSet();
assert(!DefaultISset());
DefaultValue = aValue;
SetDefaultIsSet();
}
double EbmlFloat::DefaultVal() const
{
assert(DefaultISset());
return DefaultValue;
assert(DefaultISset());
return DefaultValue;
}
EbmlFloat::operator float() const {return float(Value);}
@ -119,8 +119,7 @@ uint64 EbmlFloat::UpdateSize(bool bWithDefault, bool /* bForceRender */)
*/
filepos_t EbmlFloat::ReadData(IOCallback & input, ScopeMode ReadFully)
{
if (ReadFully != SCOPE_NO_DATA)
{
if (ReadFully != SCOPE_NO_DATA) {
binary Buffer[20];
assert(GetSize() <= 20);
input.readFully(Buffer, GetSize());

View File

@ -52,7 +52,7 @@ DEFINE_END_SEMANTIC(EbmlHead)
DEFINE_EBML_MASTER_ORPHAN(EbmlHead, 0x1A45DFA3, 4, "EBMLHead\0ratamapaga");
EbmlHead::EbmlHead()
:EbmlMaster(EbmlHead_Context)
:EbmlMaster(EbmlHead_Context)
{}
END_LIBEBML_NAMESPACE

View File

@ -39,19 +39,19 @@
START_LIBEBML_NAMESPACE
EbmlSInteger::EbmlSInteger()
:EbmlElement(DEFAULT_INT_SIZE, false)
:EbmlElement(DEFAULT_INT_SIZE, false)
{}
EbmlSInteger::EbmlSInteger(int64 aDefaultValue)
:EbmlElement(DEFAULT_INT_SIZE, true), Value(aDefaultValue)
:EbmlElement(DEFAULT_INT_SIZE, true), Value(aDefaultValue)
{
SetDefaultIsSet();
}
EbmlSInteger::EbmlSInteger(const EbmlSInteger & ElementToClone)
:EbmlElement(ElementToClone)
,Value(ElementToClone.Value)
,DefaultValue(ElementToClone.DefaultValue)
:EbmlElement(ElementToClone)
,Value(ElementToClone.Value)
,DefaultValue(ElementToClone.DefaultValue)
{
}
@ -102,13 +102,13 @@ uint64 EbmlSInteger::UpdateSize(bool bWithDefault, bool /* bForceRender */)
} else if (Value <= EBML_PRETTYLONGINT(0x7FFFFFFF) && Value >= (EBML_PRETTYLONGINT(-0x80000000))) {
SetSize_(4);
} else if (Value <= EBML_PRETTYLONGINT(0x7FFFFFFFFF) &&
Value >= EBML_PRETTYLONGINT(-0x8000000000)) {
Value >= EBML_PRETTYLONGINT(-0x8000000000)) {
SetSize_(5);
} else if (Value <= EBML_PRETTYLONGINT(0x7FFFFFFFFFFF) &&
Value >= EBML_PRETTYLONGINT(-0x800000000000)) {
Value >= EBML_PRETTYLONGINT(-0x800000000000)) {
SetSize_(6);
} else if (Value <= EBML_PRETTYLONGINT(0x7FFFFFFFFFFFFF) &&
Value >= EBML_PRETTYLONGINT(-0x80000000000000)) {
Value >= EBML_PRETTYLONGINT(-0x80000000000000)) {
SetSize_(7);
} else {
SetSize_(8);
@ -123,8 +123,7 @@ uint64 EbmlSInteger::UpdateSize(bool bWithDefault, bool /* bForceRender */)
filepos_t EbmlSInteger::ReadData(IOCallback & input, ScopeMode ReadFully)
{
if (ReadFully != SCOPE_NO_DATA)
{
if (ReadFully != SCOPE_NO_DATA) {
binary Buffer[8];
input.readFully(Buffer, GetSize());
@ -133,8 +132,7 @@ filepos_t EbmlSInteger::ReadData(IOCallback & input, ScopeMode ReadFully)
else
Value = 0; // this is a positive value
for (unsigned int i=0; i<GetSize(); i++)
{
for (unsigned int i=0; i<GetSize(); i++) {
Value <<= 8;
Value |= Buffer[i];
}

View File

@ -38,7 +38,7 @@
START_LIBEBML_NAMESPACE
EbmlStream::EbmlStream(IOCallback & DataStream)
:Stream(DataStream)
:Stream(DataStream)
{}
EbmlStream::~EbmlStream()

View File

@ -40,7 +40,7 @@
START_LIBEBML_NAMESPACE
EbmlString::EbmlString()
:EbmlElement(0, false)
:EbmlElement(0, false)
{
SetDefaultSize(0);
/* done automatically
@ -50,7 +50,7 @@ EbmlString::EbmlString()
}
EbmlString::EbmlString(const std::string & aDefaultValue)
:EbmlElement(0, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
:EbmlElement(0, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
{
SetDefaultSize(0);
SetDefaultIsSet();
@ -64,23 +64,23 @@ EbmlString::EbmlString(const std::string & aDefaultValue)
\todo Cloning should be on the same exact type !
*/
EbmlString::EbmlString(const EbmlString & ElementToClone)
:EbmlElement(ElementToClone)
,Value(ElementToClone.Value)
,DefaultValue(ElementToClone.DefaultValue)
:EbmlElement(ElementToClone)
,Value(ElementToClone.Value)
,DefaultValue(ElementToClone.DefaultValue)
{
}
void EbmlString::SetDefaultValue(std::string & aValue)
{
assert(!DefaultISset());
DefaultValue = aValue;
SetDefaultIsSet();
assert(!DefaultISset());
DefaultValue = aValue;
SetDefaultIsSet();
}
const std::string & EbmlString::DefaultVal() const
{
assert(DefaultISset());
return DefaultValue;
assert(DefaultISset());
return DefaultValue;
}
@ -96,8 +96,7 @@ filepos_t EbmlString::RenderData(IOCallback & output, bool /* bForceRender */, b
if (Result < GetDefaultSize()) {
// pad the rest with 0
binary *Pad = new (std::nothrow) binary[GetDefaultSize() - Result];
if (Pad == NULL)
{
if (Pad == NULL) {
return Result;
}
memset(Pad, 0x00, GetDefaultSize() - Result);
@ -145,8 +144,7 @@ uint64 EbmlString::UpdateSize(bool bWithDefault, bool /* bForceRender */)
filepos_t EbmlString::ReadData(IOCallback & input, ScopeMode ReadFully)
{
if (ReadFully != SCOPE_NO_DATA)
{
if (ReadFully != SCOPE_NO_DATA) {
if (GetSize() == 0) {
Value = "";
SetValueIsSet();

View File

@ -41,33 +41,33 @@
START_LIBEBML_NAMESPACE
EbmlUInteger::EbmlUInteger()
:EbmlElement(DEFAULT_UINT_SIZE, false)
:EbmlElement(DEFAULT_UINT_SIZE, false)
{}
EbmlUInteger::EbmlUInteger(uint64 aDefaultValue)
:EbmlElement(DEFAULT_UINT_SIZE, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
:EbmlElement(DEFAULT_UINT_SIZE, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
{
SetDefaultIsSet();
}
EbmlUInteger::EbmlUInteger(const EbmlUInteger & ElementToClone)
:EbmlElement(ElementToClone)
,Value(ElementToClone.Value)
,DefaultValue(ElementToClone.DefaultValue)
:EbmlElement(ElementToClone)
,Value(ElementToClone.Value)
,DefaultValue(ElementToClone.DefaultValue)
{
}
void EbmlUInteger::SetDefaultValue(uint64 aValue)
{
assert(!DefaultISset());
DefaultValue = aValue;
SetDefaultIsSet();
assert(!DefaultISset());
DefaultValue = aValue;
SetDefaultIsSet();
}
uint64 EbmlUInteger::DefaultVal() const
{
assert(DefaultISset());
return DefaultValue;
assert(DefaultISset());
return DefaultValue;
}
EbmlUInteger::operator uint8() const {return uint8(Value); }
@ -134,14 +134,12 @@ uint64 EbmlUInteger::UpdateSize(bool bWithDefault, bool /* bForceRender */)
filepos_t EbmlUInteger::ReadData(IOCallback & input, ScopeMode ReadFully)
{
if (ReadFully != SCOPE_NO_DATA)
{
if (ReadFully != SCOPE_NO_DATA) {
binary Buffer[8];
input.readFully(Buffer, GetSize());
Value = 0;
for (unsigned int i=0; i<GetSize(); i++)
{
for (unsigned int i=0; i<GetSize(); i++) {
Value <<= 8;
Value |= Buffer[i];
}

View File

@ -184,8 +184,7 @@ void UTFstring::UpdateFromUCS2()
{
// find the size of the final UTF-8 string
size_t i,Size=0;
for (i=0; i<_Length; i++)
{
for (i=0; i<_Length; i++) {
if (_Data[i] < 0x80) {
Size++;
} else if (_Data[i] < 0x800) {
@ -195,8 +194,7 @@ void UTFstring::UpdateFromUCS2()
}
}
std::string::value_type *tmpStr = new std::string::value_type[Size+1];
for (i=0, Size=0; i<_Length; i++)
{
for (i=0, Size=0; i<_Length; i++) {
if (_Data[i] < 0x80) {
tmpStr[Size++] = _Data[i];
} else if (_Data[i] < 0x800) {
@ -226,36 +224,36 @@ bool UTFstring::wcscmp_internal(const wchar_t *str1, const wchar_t *str2)
// ===================== EbmlUnicodeString class ===================
EbmlUnicodeString::EbmlUnicodeString()
:EbmlElement(0, false)
:EbmlElement(0, false)
{
SetDefaultSize(0);
}
EbmlUnicodeString::EbmlUnicodeString(const UTFstring & aDefaultValue)
:EbmlElement(0, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
:EbmlElement(0, true), Value(aDefaultValue), DefaultValue(aDefaultValue)
{
SetDefaultSize(0);
SetDefaultIsSet();
}
EbmlUnicodeString::EbmlUnicodeString(const EbmlUnicodeString & ElementToClone)
:EbmlElement(ElementToClone)
,Value(ElementToClone.Value)
,DefaultValue(ElementToClone.DefaultValue)
:EbmlElement(ElementToClone)
,Value(ElementToClone.Value)
,DefaultValue(ElementToClone.DefaultValue)
{
}
void EbmlUnicodeString::SetDefaultValue(UTFstring & aValue)
{
assert(!DefaultISset());
DefaultValue = aValue;
SetDefaultIsSet();
assert(!DefaultISset());
DefaultValue = aValue;
SetDefaultIsSet();
}
const UTFstring & EbmlUnicodeString::DefaultVal() const
{
assert(DefaultISset());
return DefaultValue;
assert(DefaultISset());
return DefaultValue;
}
@ -333,8 +331,7 @@ uint64 EbmlUnicodeString::UpdateSize(bool bWithDefault, bool /* bForceRender */)
*/
filepos_t EbmlUnicodeString::ReadData(IOCallback & input, ScopeMode ReadFully)
{
if (ReadFully != SCOPE_NO_DATA)
{
if (ReadFully != SCOPE_NO_DATA) {
if (GetSize() == 0) {
Value = UTFstring::value_type(0);
SetValueIsSet();

View File

@ -51,8 +51,7 @@ filepos_t EbmlVoid::RenderData(IOCallback & output, bool /* bForceRender */, boo
static binary DummyBuf[4*1024];
uint64 SizeToWrite = GetSize();
while (SizeToWrite > 4*1024)
{
while (SizeToWrite > 4*1024) {
output.writeFully(DummyBuf, 4*1024);
SizeToWrite -= 4*1024;
}
@ -99,7 +98,7 @@ uint64 EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output
uint64 EbmlVoid::Overwrite(const EbmlElement & EltToVoid, IOCallback & output, bool ComeBackAfterward, bool bWithDefault)
{
// EltToVoid.UpdateSize(bWithDefault);
// EltToVoid.UpdateSize(bWithDefault);
if (EltToVoid.GetElementPosition() == 0) {
// this element has never been written
return 0;

View File

@ -53,8 +53,7 @@ void IOCallback::writeFully(const void*Buffer,size_t Size)
if (Buffer == NULL)
throw;
if(write(Buffer,Size) != Size)
{
if(write(Buffer,Size) != Size) {
#if !defined(__GNUC__) || (__GNUC__ > 2)
stringstream Msg;
Msg<<"EOF in writeFully("<<Buffer<<","<<Size<<")";
@ -70,8 +69,7 @@ void IOCallback::readFully(void*Buffer,size_t Size)
if(Buffer == NULL)
throw;
if(read(Buffer,Size) != Size)
{
if(read(Buffer,Size) != Size) {
#if !defined(__GNUC__) || (__GNUC__ > 2)
stringstream Msg;
Msg<<"EOF in readFully("<<Buffer<<","<<Size<<")";

View File

@ -46,7 +46,7 @@ MemIOCallback::MemIOCallback(uint64 DefaultSize)
mOk = false;
std::stringstream Msg;
Msg << "Failed to alloc memory block of size ";
// not working with VC6 Msg << DefaultSize;
// not working with VC6 Msg << DefaultSize;
mLastErrorStr = Msg.str();
return;
}
@ -68,11 +68,10 @@ uint32 MemIOCallback::read(void *Buffer, size_t Size)
if (Buffer == NULL || Size < 1)
return 0;
//If the size is larger than than the amount left in the buffer
if (Size + dataBufferPos > dataBufferTotalSize)
{
if (Size + dataBufferPos > dataBufferTotalSize) {
//We will only return the remaining data
memcpy(Buffer, dataBuffer + dataBufferPos, dataBufferTotalSize - dataBufferPos);
uint64 oldDataPos = dataBufferPos;
uint64 oldDataPos = dataBufferPos;
dataBufferPos = dataBufferTotalSize;
return dataBufferTotalSize - oldDataPos;
}
@ -96,8 +95,7 @@ void MemIOCallback::setFilePointer(int64 Offset, seek_mode Mode)
size_t MemIOCallback::write(const void *Buffer, size_t Size)
{
if (dataBufferMemorySize < dataBufferPos + Size)
{
if (dataBufferMemorySize < dataBufferPos + Size) {
//We need more memory!
dataBuffer = (binary *)realloc((void *)dataBuffer, dataBufferPos + Size);
}
@ -111,8 +109,7 @@ size_t MemIOCallback::write(const void *Buffer, size_t Size)
uint32 MemIOCallback::write(IOCallback & IOToRead, size_t Size)
{
if (dataBufferMemorySize < dataBufferPos + Size)
{
if (dataBufferMemorySize < dataBufferPos + Size) {
//We need more memory!
dataBuffer = (binary *)realloc((void *)dataBuffer, dataBufferPos + Size);
}

View File

@ -65,27 +65,25 @@ StdIOCallback::StdIOCallback(const char*Path, const open_mode aMode)
assert(Path!=0);
const char *Mode;
switch (aMode)
{
case MODE_READ:
Mode = "rb";
break;
case MODE_SAFE:
Mode = "rb+";
break;
case MODE_WRITE:
Mode = "wb";
break;
case MODE_CREATE:
Mode = "wb+";
break;
default:
throw 0;
switch (aMode) {
case MODE_READ:
Mode = "rb";
break;
case MODE_SAFE:
Mode = "rb+";
break;
case MODE_WRITE:
Mode = "wb";
break;
case MODE_CREATE:
Mode = "wb+";
break;
default:
throw 0;
}
File=fopen(Path,Mode);
if(File==0)
{
if(File==0) {
#if !defined(__GNUC__) || (__GNUC__ > 2)
stringstream Msg;
Msg<<"Can't open stdio file \""<<Path<<"\" in mode \""<<Mode<<"\"";
@ -117,30 +115,26 @@ void StdIOCallback::setFilePointer(int64 Offset,seek_mode Mode)
assert(File!=0);
// There is a numeric cast in the boost library, which would be quite nice for this checking
/*
SL : replaced because unknown class in cygwin
assert(Offset <= numeric_limits<long>::max());
assert(Offset >= numeric_limits<long>::min());
*/
/*
SL : replaced because unknown class in cygwin
assert(Offset <= numeric_limits<long>::max());
assert(Offset >= numeric_limits<long>::min());
*/
assert(Offset <= LONG_MAX);
assert(Offset >= LONG_MIN);
assert(Mode==SEEK_CUR||Mode==SEEK_END||Mode==SEEK_SET);
if(fseek(File,Offset,Mode)!=0)
{
if(fseek(File,Offset,Mode)!=0) {
#if !defined(__GNUC__) || (__GNUC__ > 2)
ostringstream Msg;
Msg<<"Failed to seek file "<<File<<" to offset "<<(unsigned long)Offset<<" in mode "<<Mode;
throw CRTError(Msg.str());
#endif // GCC2
mCurrentPosition = ftell(File);
}
else
{
switch ( Mode )
{
} else {
switch ( Mode ) {
case SEEK_CUR:
mCurrentPosition += Offset;
break;
@ -168,8 +162,7 @@ uint64 StdIOCallback::getFilePointer()
#if 0
long Result=ftell(File);
if(Result<0)
{
if(Result<0) {
#if !defined(__GNUC__) || (__GNUC__ > 2)
stringstream Msg;
Msg<<"Can't tell the current file pointer position for "<<File;
@ -186,8 +179,7 @@ void StdIOCallback::close()
if(File==0)
return;
if(fclose(File)!=0)
{
if(fclose(File)!=0) {
#if !defined(__GNUC__) || (__GNUC__ > 2)
stringstream Msg;
Msg<<"Can't close file "<<File;

View File

@ -69,35 +69,33 @@ bool WinIOCallback::open(const char* Path, const open_mode aMode, DWORD dwFlags)
DWORD AccessMode, ShareMode, Disposition;
switch (aMode)
{
case MODE_READ:
AccessMode = GENERIC_READ;
ShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
Disposition = OPEN_EXISTING;
break;
case MODE_WRITE:
AccessMode = GENERIC_WRITE;
ShareMode = 0;
Disposition = OPEN_ALWAYS;
break;
case MODE_SAFE:
AccessMode = GENERIC_WRITE|GENERIC_READ;
ShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
Disposition = OPEN_ALWAYS;
break;
case MODE_CREATE:
AccessMode = GENERIC_WRITE;
ShareMode = 0;
Disposition = CREATE_ALWAYS;
break;
default:
assert(false);
switch (aMode) {
case MODE_READ:
AccessMode = GENERIC_READ;
ShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
Disposition = OPEN_EXISTING;
break;
case MODE_WRITE:
AccessMode = GENERIC_WRITE;
ShareMode = 0;
Disposition = OPEN_ALWAYS;
break;
case MODE_SAFE:
AccessMode = GENERIC_WRITE|GENERIC_READ;
ShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
Disposition = OPEN_ALWAYS;
break;
case MODE_CREATE:
AccessMode = GENERIC_WRITE;
ShareMode = 0;
Disposition = CREATE_ALWAYS;
break;
default:
assert(false);
}
mFile = CreateFileA(Path, AccessMode, ShareMode, NULL, Disposition, dwFlags, NULL);
if ((mFile == INVALID_HANDLE_VALUE) || ((long)mFile == 0xffffffff))
{
if ((mFile == INVALID_HANDLE_VALUE) || ((long)mFile == 0xffffffff)) {
//File was not opened
char err_msg[256];
DWORD error_code = GetLastError();
@ -123,30 +121,29 @@ bool WinIOCallback::open(const wchar_t* Path, const open_mode aMode, DWORD dwFla
DWORD AccessMode, ShareMode, Disposition;
switch (aMode)
{
case MODE_READ:
AccessMode = GENERIC_READ;
ShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
Disposition = OPEN_EXISTING;
break;
case MODE_WRITE:
AccessMode = GENERIC_WRITE;
ShareMode = 0;
Disposition = OPEN_ALWAYS;
break;
case MODE_SAFE:
AccessMode = GENERIC_WRITE|GENERIC_READ;
ShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
Disposition = OPEN_ALWAYS;
break;
case MODE_CREATE:
AccessMode = GENERIC_WRITE;
ShareMode = 0;
Disposition = CREATE_ALWAYS;
break;
default:
assert(false);
switch (aMode) {
case MODE_READ:
AccessMode = GENERIC_READ;
ShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
Disposition = OPEN_EXISTING;
break;
case MODE_WRITE:
AccessMode = GENERIC_WRITE;
ShareMode = 0;
Disposition = OPEN_ALWAYS;
break;
case MODE_SAFE:
AccessMode = GENERIC_WRITE|GENERIC_READ;
ShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE;
Disposition = OPEN_ALWAYS;
break;
case MODE_CREATE:
AccessMode = GENERIC_WRITE;
ShareMode = 0;
Disposition = CREATE_ALWAYS;
break;
default:
assert(false);
}
if ((LONG)GetVersion() >= 0) {
@ -180,8 +177,7 @@ bool WinIOCallback::open(const wchar_t* Path, const open_mode aMode, DWORD dwFla
return mOk = false;
}
}
if ((mFile == INVALID_HANDLE_VALUE) || ((long)mFile == 0xffffffff))
{
if ((mFile == INVALID_HANDLE_VALUE) || ((long)mFile == 0xffffffff)) {
//File was not opened
char err_msg[256];
DWORD error_code = GetLastError();
@ -226,32 +222,28 @@ uint64 WinIOCallback::getFilePointer()
void WinIOCallback::setFilePointer(int64 Offset, seek_mode Mode)
{
DWORD Method;
switch(Mode)
{
case seek_beginning:
Method=FILE_BEGIN;
break;
case seek_current:
Method=FILE_CURRENT;
break;
case seek_end:
Method=FILE_END;
break;
default:
assert(false);
break;
switch(Mode) {
case seek_beginning:
Method=FILE_BEGIN;
break;
case seek_current:
Method=FILE_CURRENT;
break;
case seek_end:
Method=FILE_END;
break;
default:
assert(false);
break;
}
LONG High = LONG(Offset>>32);
mCurrentPosition = SetFilePointer(mFile, LONG(Offset & 0xffffffff), &High, Method);
if ( mCurrentPosition == INVALID_SET_FILE_POINTER )
{
if ( mCurrentPosition == INVALID_SET_FILE_POINTER ) {
High = 0;
DWORD Low = SetFilePointer(mFile, 0, &High, FILE_CURRENT);
mCurrentPosition = ((uint64(High)<<32) | Low);
}
else
{
} else {
mCurrentPosition |= uint64(High)<<32;
}
}