disable access to internal values when EBML_STRICT_API is defined

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libebml@20 a6f86f6d-0131-4f8e-9e7b-e335508773d5
This commit is contained in:
Steve Lhomme 2010-03-15 16:21:50 +00:00
parent c331b9b443
commit 66f1b56fba
15 changed files with 1784 additions and 1694 deletions

View File

@ -1,103 +1,106 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlBinary.h 1298 2008-02-21 22:14:18Z mosu $ \version \$Id: EbmlBinary.h 1298 2008-02-21 22:14:18Z mosu $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
\author Julien Coloos <suiryc @ users.sf.net> \author Julien Coloos <suiryc @ users.sf.net>
*/ */
#ifndef LIBEBML_BINARY_H #ifndef LIBEBML_BINARY_H
#define LIBEBML_BINARY_H #define LIBEBML_BINARY_H
#include <string> #include <string>
#include <cstring> #include <cstring>
#include "EbmlTypes.h" #include "EbmlTypes.h"
#include "EbmlElement.h" #include "EbmlElement.h"
// ----- Added 10/15/2003 by jcsston from Zen ----- // ----- Added 10/15/2003 by jcsston from Zen -----
#if defined (__BORLANDC__) //Maybe other compilers? #if defined (__BORLANDC__) //Maybe other compilers?
#include <mem.h> #include <mem.h>
#endif //__BORLANDC__ #endif //__BORLANDC__
// ------------------------------------------------ // ------------------------------------------------
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
/*! /*!
\class EbmlBinary \class EbmlBinary
\brief Handle all operations on an EBML element that contains "unknown" binary data \brief Handle all operations on an EBML element that contains "unknown" binary data
\todo handle fix sized elements (like UID of CodecID) \todo handle fix sized elements (like UID of CodecID)
*/ */
class EBML_DLL_API EbmlBinary : public EbmlElement { class EBML_DLL_API EbmlBinary : public EbmlElement {
public: public:
EbmlBinary(); EbmlBinary();
EbmlBinary(const EbmlBinary & ElementToClone); EbmlBinary(const EbmlBinary & ElementToClone);
virtual ~EbmlBinary(void); virtual ~EbmlBinary(void);
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false); uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false); uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
void SetBuffer(const binary *Buffer, const uint32 BufferSize) { void SetBuffer(const binary *Buffer, const uint32 BufferSize) {
Data = (binary *) Buffer; Data = (binary *) Buffer;
SetSize_(BufferSize); SetSize_(BufferSize);
SetValueIsSet(); SetValueIsSet();
} }
binary *GetBuffer() const {return Data;} binary *GetBuffer() const {return Data;}
void CopyBuffer(const binary *Buffer, const uint32 BufferSize) { void CopyBuffer(const binary *Buffer, const uint32 BufferSize) {
if (Data != NULL) if (Data != NULL)
free(Data); free(Data);
Data = (binary *)malloc(BufferSize * sizeof(binary)); Data = (binary *)malloc(BufferSize * sizeof(binary));
memcpy(Data, Buffer, BufferSize); memcpy(Data, Buffer, BufferSize);
SetSize_(BufferSize); SetSize_(BufferSize);
SetValueIsSet(); SetValueIsSet();
} }
operator const binary &() const {return *Data;} operator const binary &() const {return *Data;}
bool IsDefaultValue() const { bool IsDefaultValue() const {
return false; return false;
} }
bool operator==(const EbmlBinary & ElementToCompare) const; bool operator==(const EbmlBinary & ElementToCompare) const;
protected: protected:
binary *GetData() const {return Data;} binary *GetData() const {return Data;}
binary *Data; // the binary data inside the element #if defined(EBML_STRICT_API)
}; private:
#endif
END_LIBEBML_NAMESPACE binary *Data; // the binary data inside the element
};
#endif // LIBEBML_BINARY_H
END_LIBEBML_NAMESPACE
#endif // LIBEBML_BINARY_H

View File

@ -1,151 +1,155 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlCrc32.h 1326 2009-08-23 00:47:52Z robux4 $ \version \$Id: EbmlCrc32.h 1326 2009-08-23 00:47:52Z robux4 $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
\author Jory Stone <jcsston @ toughguy.net> \author Jory Stone <jcsston @ toughguy.net>
*/ */
#ifndef LIBEBML_CRC32_H #ifndef LIBEBML_CRC32_H
#define LIBEBML_CRC32_H #define LIBEBML_CRC32_H
#include "EbmlTypes.h" #include "EbmlTypes.h"
#include "EbmlBinary.h" #include "EbmlBinary.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
const uint32 CRC32_NEGL = 0xffffffffL; const uint32 CRC32_NEGL = 0xffffffffL;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
# define CRC32_INDEX(c) (c >> 24) # define CRC32_INDEX(c) (c >> 24)
# define CRC32_SHIFTED(c) (c << 8) # define CRC32_SHIFTED(c) (c << 8)
#else #else
# define CRC32_INDEX(c) (c & 0xff) # define CRC32_INDEX(c) (c & 0xff)
# define CRC32_SHIFTED(c) (c >> 8) # define CRC32_SHIFTED(c) (c >> 8)
#endif #endif
class EBML_DLL_API EbmlCrc32 : public EbmlBinary { class EBML_DLL_API EbmlCrc32 : public EbmlBinary {
public: public:
EbmlCrc32(); EbmlCrc32();
EbmlCrc32(const EbmlCrc32 & ElementToClone); EbmlCrc32(const EbmlCrc32 & ElementToClone);
bool ValidateSize() const {return (GetSize() == 4);} bool ValidateSize() const {return (GetSize() == 4);}
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false); uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
// uint64 UpdateSize(bool bKeepIntact = false); // uint64 UpdateSize(bool bKeepIntact = false);
bool IsDefaultValue() const { bool IsDefaultValue() const {
return false; return false;
} }
void AddElementCRC32(EbmlElement &ElementToCRC); void AddElementCRC32(EbmlElement &ElementToCRC);
bool CheckElementCRC32(EbmlElement &ElementToCRC); bool CheckElementCRC32(EbmlElement &ElementToCRC);
/*! /*!
CRC Checksum Calculation CRC Checksum Calculation
*/ */
enum {DIGESTSIZE = 4}; enum {DIGESTSIZE = 4};
/*! /*!
Use this to quickly check a CRC32 with some data Use this to quickly check a CRC32 with some data
\return True if inputCRC matches CRC32 generated from input data \return True if inputCRC matches CRC32 generated from input data
*/ */
static bool CheckCRC(uint32 inputCRC, const binary *input, uint32 length); static bool CheckCRC(uint32 inputCRC, const binary *input, uint32 length);
/*! /*!
Calls Update() and Finalize(), use to create a CRC32 in one go Calls Update() and Finalize(), use to create a CRC32 in one go
*/ */
void FillCRC32(const binary *input, uint32 length); void FillCRC32(const binary *input, uint32 length);
/*! /*!
Add data to the CRC table, in other words process some data bit by bit Add data to the CRC table, in other words process some data bit by bit
*/ */
void Update(const binary *input, uint32 length); void Update(const binary *input, uint32 length);
/*! /*!
Use this with Update() to Finalize() or Complete the CRC32 Use this with Update() to Finalize() or Complete the CRC32
*/ */
void Finalize(); void Finalize();
/*! /*!
Returns a uint32 that has the value of the CRC32 Returns a uint32 that has the value of the CRC32
*/ */
uint32 GetCrc32() const { uint32 GetCrc32() const {
return m_crc_final; return m_crc_final;
}; };
void ForceCrc32(uint32 NewValue) { m_crc_final = NewValue; SetValueIsSet();} void ForceCrc32(uint32 NewValue) { m_crc_final = NewValue; SetValueIsSet();}
protected: #if defined(EBML_STRICT_API)
void ResetCRC() {m_crc = CRC32_NEGL;} private:
void UpdateByte(binary b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} #else
protected:
static const uint32 m_tab[256]; #endif
uint32 m_crc; void ResetCRC() {m_crc = CRC32_NEGL;}
uint32 m_crc_final; void UpdateByte(binary b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
EBML_CONCRETE_CLASS(EbmlCrc32) static const uint32 m_tab[256];
}; uint32 m_crc;
uint32 m_crc_final;
template <class T>
inline unsigned int GetAlignment(T *dummy=NULL) // VC60 workaround EBML_CONCRETE_CLASS(EbmlCrc32)
{ };
#if (_MSC_VER >= 1300)
return __alignof(T); template <class T>
#elif defined(__GNUC__) inline unsigned int GetAlignment(T *dummy=NULL) // VC60 workaround
return __alignof__(T); {
#else #if (_MSC_VER >= 1300)
return sizeof(T); return __alignof(T);
#endif #elif defined(__GNUC__)
} return __alignof__(T);
#else
template <class T> return sizeof(T);
inline bool IsPowerOf2(T n) #endif
{ }
return n > 0 && (n & (n-1)) == 0;
} template <class T>
inline bool IsPowerOf2(T n)
template <class T1, class T2> {
inline T2 ModPowerOf2(T1 a, T2 b) return n > 0 && (n & (n-1)) == 0;
{ }
assert(IsPowerOf2(b));
return T2(a) & (b-1); template <class T1, class T2>
} inline T2 ModPowerOf2(T1 a, T2 b)
{
inline bool IsAlignedOn(const void *p, unsigned int alignment) assert(IsPowerOf2(b));
{ return T2(a) & (b-1);
return IsPowerOf2(alignment) ? ModPowerOf2((uintptr_t)p, alignment) == 0 : (uintptr_t)p % alignment == 0; }
}
inline bool IsAlignedOn(const void *p, unsigned int alignment)
template <class T> {
inline bool IsAligned(const void *p, T *dummy=NULL) // VC60 workaround return IsPowerOf2(alignment) ? ModPowerOf2((uintptr_t)p, alignment) == 0 : (uintptr_t)p % alignment == 0;
{ }
return IsAlignedOn(p, GetAlignment<T>());
} template <class T>
inline bool IsAligned(const void *p, T *dummy=NULL) // VC60 workaround
END_LIBEBML_NAMESPACE {
return IsAlignedOn(p, GetAlignment<T>());
#endif // LIBEBML_CRC32_H }
END_LIBEBML_NAMESPACE
#endif // LIBEBML_CRC32_H

View File

@ -1,94 +1,98 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlDate.h 1079 2005-03-03 13:18:14Z robux4 $ \version \$Id: EbmlDate.h 1079 2005-03-03 13:18:14Z robux4 $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#ifndef LIBEBML_DATE_H #ifndef LIBEBML_DATE_H
#define LIBEBML_DATE_H #define LIBEBML_DATE_H
#include "EbmlTypes.h" #include "EbmlTypes.h"
#include "EbmlElement.h" #include "EbmlElement.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
/*! /*!
\class EbmlDate \class EbmlDate
\brief Handle all operations related to an EBML date \brief Handle all operations related to an EBML date
*/ */
class EBML_DLL_API EbmlDate : public EbmlElement { class EBML_DLL_API EbmlDate : public EbmlElement {
public: public:
EbmlDate() :EbmlElement(8, false), myDate(0) {} EbmlDate() :EbmlElement(8, false), myDate(0) {}
EbmlDate(const EbmlDate & ElementToClone); EbmlDate(const EbmlDate & ElementToClone);
/*! /*!
\brief set the date with a UNIX/C/EPOCH form \brief set the date with a UNIX/C/EPOCH form
\param NewDate UNIX/C date in UTC (no timezone) \param NewDate UNIX/C date in UTC (no timezone)
*/ */
void SetEpochDate(int32 NewDate) {myDate = int64(NewDate - UnixEpochDelay) * 1000000000; SetValueIsSet();} void SetEpochDate(int32 NewDate) {myDate = int64(NewDate - UnixEpochDelay) * 1000000000; SetValueIsSet();}
/*! /*!
\brief get the date with a UNIX/C/EPOCH form \brief get the date with a UNIX/C/EPOCH form
\note the date is in UTC (no timezone) \note the date is in UTC (no timezone)
*/ */
int32 GetEpochDate() const {return int32(myDate/1000000000 + UnixEpochDelay);} int32 GetEpochDate() const {return int32(myDate/1000000000 + UnixEpochDelay);}
bool ValidateSize() const {return ((GetSize() == 8) || (GetSize() == 0));} bool ValidateSize() const {return ((GetSize() == 8) || (GetSize() == 0));}
/*! /*!
\note no Default date handled \note no Default date handled
*/ */
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false) { uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false) {
if(!ValueIsSet()) if(!ValueIsSet())
SetSize_(0); SetSize_(0);
else else
SetSize_(8); SetSize_(8);
return GetSize(); return GetSize();
} }
bool operator<(const EbmlDate & EltCmp) const {return myDate < EltCmp.myDate;} bool operator<(const EbmlDate & EltCmp) const {return myDate < EltCmp.myDate;}
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
bool IsDefaultValue() const { bool IsDefaultValue() const {
return false; return false;
} }
protected: #if defined(EBML_STRICT_API)
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false); private:
#else
int64 myDate; ///< internal format of the date protected:
#endif
static const uint64 UnixEpochDelay; uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
};
int64 myDate; ///< internal format of the date
END_LIBEBML_NAMESPACE
static const uint64 UnixEpochDelay;
#endif // LIBEBML_DATE_H };
END_LIBEBML_NAMESPACE
#endif // LIBEBML_DATE_H

View File

@ -1,62 +1,66 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlDummy.h 639 2004-07-09 20:59:14Z mosu $ \version \$Id: EbmlDummy.h 639 2004-07-09 20:59:14Z mosu $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#ifndef LIBEBML_DUMMY_H #ifndef LIBEBML_DUMMY_H
#define LIBEBML_DUMMY_H #define LIBEBML_DUMMY_H
#include "EbmlBinary.h" #include "EbmlBinary.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
class EBML_DLL_API EbmlDummy : public EbmlBinary { class EBML_DLL_API EbmlDummy : public EbmlBinary {
public: public:
EbmlDummy() :DummyId(DummyRawId) {} EbmlDummy() :DummyId(DummyRawId) {}
EbmlDummy(const EbmlId & aId) :EbmlBinary(), DummyId(aId) {} EbmlDummy(const EbmlId & aId) :EbmlBinary(), DummyId(aId) {}
EbmlDummy(const EbmlDummy & ElementToClone):EbmlBinary(ElementToClone), DummyId(ElementToClone.DummyId) {} EbmlDummy(const EbmlDummy & ElementToClone):EbmlBinary(ElementToClone), DummyId(ElementToClone.DummyId) {}
bool ValidateSize() const {return true;} bool ValidateSize() const {return true;}
bool IsDummy() const {return true;} bool IsDummy() const {return true;}
bool IsDefaultValue() const {return true;} bool IsDefaultValue() const {return true;}
protected: #if defined(EBML_STRICT_API)
const EbmlId DummyId; private:
static const EbmlId DummyRawId; #else
protected:
EBML_CONCRETE_CLASS(EbmlDummy) #endif
}; const EbmlId DummyId;
static const EbmlId DummyRawId;
END_LIBEBML_NAMESPACE
EBML_CONCRETE_CLASS(EbmlDummy)
#endif // LIBEBML_DUMMY_H };
END_LIBEBML_NAMESPACE
#endif // LIBEBML_DUMMY_H

View File

@ -1,301 +1,329 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlElement.h 1232 2005-10-15 15:56:52Z robux4 $ \version \$Id: EbmlElement.h 1232 2005-10-15 15:56:52Z robux4 $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#ifndef LIBEBML_ELEMENT_H #ifndef LIBEBML_ELEMENT_H
#define LIBEBML_ELEMENT_H #define LIBEBML_ELEMENT_H
#include <cassert> #include <cassert>
#include "EbmlTypes.h" #include "EbmlTypes.h"
#include "EbmlId.h" #include "EbmlId.h"
#include "IOCallback.h" #include "IOCallback.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
/*! /*!
\brief The size of the EBML-coded length \brief The size of the EBML-coded length
*/ */
int EBML_DLL_API CodedSizeLength(uint64 Length, unsigned int SizeLength, bool bSizeIsFinite = true); int EBML_DLL_API CodedSizeLength(uint64 Length, unsigned int SizeLength, bool bSizeIsFinite = true);
/*! /*!
\brief The coded value of the EBML-coded length \brief The coded value of the EBML-coded length
\note The size of OutBuffer must be 8 octets at least \note The size of OutBuffer must be 8 octets at least
*/ */
int EBML_DLL_API CodedValueLength(uint64 Length, int CodedSize, binary * OutBuffer); int EBML_DLL_API CodedValueLength(uint64 Length, int CodedSize, binary * OutBuffer);
/*! /*!
\brief Read an EBML-coded value from a buffer \brief Read an EBML-coded value from a buffer
\return the value read \return the value read
*/ */
uint64 EBML_DLL_API ReadCodedSizeValue(const binary * InBuffer, uint32 & BufferSize, uint64 & SizeUnknown); uint64 EBML_DLL_API ReadCodedSizeValue(const binary * InBuffer, uint32 & BufferSize, uint64 & SizeUnknown);
/*! /*!
\brief The size of the EBML-coded signed length \brief The size of the EBML-coded signed length
*/ */
int EBML_DLL_API CodedSizeLengthSigned(int64 Length, unsigned int SizeLength); int EBML_DLL_API CodedSizeLengthSigned(int64 Length, unsigned int SizeLength);
/*! /*!
\brief The coded value of the EBML-coded signed length \brief The coded value of the EBML-coded signed length
\note the size of OutBuffer must be 8 octets at least \note the size of OutBuffer must be 8 octets at least
*/ */
int EBML_DLL_API CodedValueLengthSigned(int64 Length, int CodedSize, binary * OutBuffer); int EBML_DLL_API CodedValueLengthSigned(int64 Length, int CodedSize, binary * OutBuffer);
/*! /*!
\brief Read a signed EBML-coded value from a buffer \brief Read a signed EBML-coded value from a buffer
\return the value read \return the value read
*/ */
int64 EBML_DLL_API ReadCodedSizeSignedValue(const binary * InBuffer, uint32 & BufferSize, uint64 & SizeUnknown); int64 EBML_DLL_API ReadCodedSizeSignedValue(const binary * InBuffer, uint32 & BufferSize, uint64 & SizeUnknown);
class EbmlStream; class EbmlStream;
class EbmlSemanticContext; class EbmlSemanticContext;
class EbmlElement; class EbmlElement;
// functions for generic handling of data (should be static to all classes) // functions for generic handling of data (should be static to all classes)
/*! /*!
\todo Handle default value \todo Handle default value
*/ */
class EBML_DLL_API EbmlCallbacks { class EBML_DLL_API EbmlCallbacks {
public: public:
EbmlCallbacks(EbmlElement & (*Creator)(), const EbmlId & aGlobalId, const char * aDebugName, const EbmlSemanticContext & aContext) EbmlCallbacks(EbmlElement & (*Creator)(), const EbmlId & aGlobalId, const char * aDebugName, const EbmlSemanticContext & aContext)
:Create(Creator) :Create(Creator)
,GlobalId(aGlobalId) ,GlobalId(aGlobalId)
,DebugName(aDebugName) ,DebugName(aDebugName)
,Context(aContext) ,Context(aContext)
{} {}
EbmlElement & (*Create)(); EbmlElement & (*Create)();
const EbmlId & GlobalId; const EbmlId & GlobalId;
const char * DebugName; const char * DebugName;
const EbmlSemanticContext & Context; const EbmlSemanticContext & Context;
}; };
/*! /*!
\brief contains the semantic informations for a given level and all sublevels \brief contains the semantic informations for a given level and all sublevels
\todo move the ID in the element class \todo move the ID in the element class
*/ */
class EBML_DLL_API EbmlSemantic { class EBML_DLL_API EbmlSemantic {
public: public:
EbmlSemantic(bool aMandatory, bool aUnique, const EbmlCallbacks & aGetCallbacks) EbmlSemantic(bool aMandatory, bool aUnique, const EbmlCallbacks & aGetCallbacks)
:Mandatory(aMandatory), Unique(aUnique), GetCallbacks(aGetCallbacks) {} :Mandatory(aMandatory), Unique(aUnique), GetCallbacks(aGetCallbacks) {}
bool Mandatory; ///< wether the element is mandatory in the context or not bool Mandatory; ///< wether the element is mandatory in the context or not
bool Unique; bool Unique;
const EbmlCallbacks & GetCallbacks; const EbmlCallbacks & GetCallbacks;
}; };
typedef const class EbmlSemanticContext & (*_GetSemanticContext)(); typedef const class EbmlSemanticContext & (*_GetSemanticContext)();
/*! /*!
Context of the element Context of the element
\todo allow more than one parent ? \todo allow more than one parent ?
*/ */
class EBML_DLL_API EbmlSemanticContext { class EBML_DLL_API EbmlSemanticContext {
public: public:
EbmlSemanticContext(unsigned int aSize, EbmlSemanticContext(unsigned int aSize,
const EbmlSemantic *aMyTable, const EbmlSemantic *aMyTable,
const EbmlSemanticContext *aUpTable, const EbmlSemanticContext *aUpTable,
const _GetSemanticContext aGetGlobalContext, const _GetSemanticContext aGetGlobalContext,
const EbmlCallbacks *aMasterElt) const EbmlCallbacks *aMasterElt)
:Size(aSize), MyTable(aMyTable), UpTable(aUpTable), :Size(aSize), MyTable(aMyTable), UpTable(aUpTable),
GetGlobalContext(aGetGlobalContext), MasterElt(aMasterElt) {} GetGlobalContext(aGetGlobalContext), MasterElt(aMasterElt) {}
bool operator!=(const EbmlSemanticContext & aElt) const { bool operator!=(const EbmlSemanticContext & aElt) const {
return ((Size != aElt.Size) || (MyTable != aElt.MyTable) || return ((Size != aElt.Size) || (MyTable != aElt.MyTable) ||
(UpTable != aElt.UpTable) || (GetGlobalContext != aElt.GetGlobalContext) | (UpTable != aElt.UpTable) || (GetGlobalContext != aElt.GetGlobalContext) |
(MasterElt != aElt.MasterElt)); (MasterElt != aElt.MasterElt));
} }
unsigned int Size; ///< number of elements in the table unsigned int Size; ///< number of elements in the table
const EbmlSemantic *MyTable; ///< First element in the table const EbmlSemantic *MyTable; ///< First element in the table
const EbmlSemanticContext *UpTable; ///< Parent element const EbmlSemanticContext *UpTable; ///< Parent element
/// \todo replace with the global context directly /// \todo replace with the global context directly
const _GetSemanticContext GetGlobalContext; ///< global elements supported at this level const _GetSemanticContext GetGlobalContext; ///< global elements supported at this level
const EbmlCallbacks *MasterElt; const EbmlCallbacks *MasterElt;
}; };
#define EBML_CONCRETE_CLASS(Type) \ #if defined(EBML_STRICT_API)
public: \ #define EBML_CONCRETE_CLASS(Type) \
virtual const EbmlCallbacks & Generic() const {return ClassInfos;} \ public: \
virtual operator const EbmlId &() const {return ClassInfos.GlobalId;} \ virtual const EbmlSemanticContext &Context() const {return ClassInfos.Context;} \
virtual EbmlElement & CreateElement() const {return Create();} \ virtual const char *DebugName() const {return ClassInfos.DebugName;} \
virtual EbmlElement * Clone() const { return new Type(*this); } \ virtual operator const EbmlId &() const {return ClassInfos.GlobalId;} \
static EbmlElement & Create() {return *(new Type);} \ virtual EbmlElement & CreateElement() const {return Create();} \
static const EbmlCallbacks ClassInfos; \ virtual EbmlElement * Clone() const { return new Type(*this); } \
static EbmlElement & Create() {return *(new Type);} \
#define EBML_INFO(ref) ref::ClassInfos static const EbmlCallbacks & ClassInfo() {return ClassInfos;} \
#define EBML_ID(ref) ref::ClassInfos.GlobalId static const EbmlId & ClassId() {return ClassInfos.GlobalId;} \
#define EBML_CONTEXT(e) e->Generic().Context private: \
#define EBML_NAME(e) e->Generic().DebugName static const EbmlCallbacks ClassInfos; \
/*! #define EBML_INFO(ref) ref::ClassInfo()
\class EbmlElement #define EBML_ID(ref) ref::ClassId()
\brief Hold basic informations about an EBML element (ID + length) #define EBML_CONTEXT(e) e->Context()
*/ #define EBML_NAME(e) e->DebugName()
class EBML_DLL_API EbmlElement { #else
public: #define EBML_CONCRETE_CLASS(Type) \
EbmlElement(uint64 aDefaultSize, bool bValueSet = false); public: \
virtual ~EbmlElement() {assert(!bLocked);} virtual const EbmlCallbacks & Generic() const {return ClassInfos;} \
virtual operator const EbmlId &() const {return ClassInfos.GlobalId;} \
/// Set the minimum length that will be used to write the element size (-1 = optimal) virtual EbmlElement & CreateElement() const {return Create();} \
void SetSizeLength(int NewSizeLength) {SizeLength = NewSizeLength;} virtual EbmlElement * Clone() const { return new Type(*this); } \
int GetSizeLength() const {return SizeLength;} static EbmlElement & Create() {return *(new Type);} \
static const EbmlCallbacks ClassInfos; \
static EbmlElement * FindNextElement(IOCallback & DataStream, const EbmlSemanticContext & Context, int & UpperLevel, uint64 MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel = 1);
static EbmlElement * FindNextID(IOCallback & DataStream, const EbmlCallbacks & ClassInfos, const uint64 MaxDataSize); #define EBML_INFO(ref) ref::ClassInfos
#define EBML_ID(ref) ref::ClassInfos.GlobalId
/*! #define EBML_CONTEXT(e) e->Generic().Context
\brief find the next element with the same ID #define EBML_NAME(e) e->Generic().DebugName
*/ #endif
EbmlElement * FindNext(IOCallback & DataStream, const uint64 MaxDataSize);
/*!
EbmlElement * SkipData(EbmlStream & DataStream, const EbmlSemanticContext & Context, EbmlElement * TestReadElt = NULL, bool AllowDummyElt = false); \class EbmlElement
\brief Hold basic informations about an EBML element (ID + length)
/*! */
\brief Give a copy of the element, all data inside the element is copied class EBML_DLL_API EbmlElement {
\return NULL if there is not enough memory public:
*/ EbmlElement(uint64 aDefaultSize, bool bValueSet = false);
virtual EbmlElement * Clone() const = 0; virtual ~EbmlElement() {assert(!bLocked);}
virtual operator const EbmlId &() const = 0; /// Set the minimum length that will be used to write the element size (-1 = optimal)
/// return the generic callback to monitor a derived class void SetSizeLength(int NewSizeLength) {SizeLength = NewSizeLength;}
virtual const EbmlCallbacks & Generic() const = 0; int GetSizeLength() const {return SizeLength;}
virtual EbmlElement & CreateElement() const = 0;
static EbmlElement * FindNextElement(IOCallback & DataStream, const EbmlSemanticContext & Context, int & UpperLevel, uint64 MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel = 1);
// by default only allow to set element as finite (override when needed) static EbmlElement * FindNextID(IOCallback & DataStream, const EbmlCallbacks & ClassInfos, const uint64 MaxDataSize);
virtual bool SetSizeInfinite(bool bIsInfinite = true) {return !bIsInfinite;}
/*!
virtual bool ValidateSize() const = 0; \brief find the next element with the same ID
*/
uint64 GetElementPosition() const { EbmlElement * FindNext(IOCallback & DataStream, const uint64 MaxDataSize);
return ElementPosition;
} EbmlElement * SkipData(EbmlStream & DataStream, const EbmlSemanticContext & Context, EbmlElement * TestReadElt = NULL, bool AllowDummyElt = false);
uint64 ElementSize(bool bKeepIntact = false) const; /// return the size of the header+data, before writing /*!
\brief Give a copy of the element, all data inside the element is copied
uint32 Render(IOCallback & output, bool bKeepIntact = false, bool bKeepPosition = false, bool bForceRender = false); \return NULL if there is not enough memory
*/
virtual uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false) = 0; /// update the Size of the Data stored virtual EbmlElement * Clone() const = 0;
virtual uint64 GetSize() const {return Size;} /// return the size of the data stored in the element, on reading
virtual operator const EbmlId &() const = 0;
virtual uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) = 0; #if defined(EBML_STRICT_API)
virtual void Read(EbmlStream & inDataStream, const EbmlSemanticContext & Context, int & UpperEltFound, EbmlElement * & FoundElt, bool AllowDummyElt = false, ScopeMode ReadFully = SCOPE_ALL_DATA); virtual const char *DebugName() const = 0;
virtual const EbmlSemanticContext &Context() const = 0;
bool IsLocked() const {return bLocked;} #else
void Lock(bool bLock = true) { bLocked = bLock;} /// return the generic callback to monitor a derived class
virtual const EbmlCallbacks & Generic() const = 0;
/*! #endif
\brief default comparison for elements that can't be compared virtual EbmlElement & CreateElement() const = 0;
*/
virtual bool operator<(const EbmlElement & EltB) const { // by default only allow to set element as finite (override when needed)
return true; virtual bool SetSizeInfinite(bool bIsInfinite = true) {return !bIsInfinite;}
}
virtual bool ValidateSize() const = 0;
static bool CompareElements(const EbmlElement *A, const EbmlElement *B);
uint64 GetElementPosition() const {
virtual bool IsDummy() const {return false;} return ElementPosition;
virtual bool IsMaster() const {return false;} }
uint8 HeadSize() const { uint64 ElementSize(bool bKeepIntact = false) const; /// return the size of the header+data, before writing
return EBML_ID_LENGTH(EbmlId(*this)) + CodedSizeLength(Size, SizeLength, bSizeIsFinite);
} /// return the size of the head, on reading/writing uint32 Render(IOCallback & output, bool bKeepIntact = false, bool bKeepPosition = false, bool bForceRender = false);
/*! virtual uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false) = 0; /// update the Size of the Data stored
\brief Force the size of an element virtual uint64 GetSize() const {return Size;} /// return the size of the data stored in the element, on reading
\warning only possible if the size is "undefined"
*/ virtual uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) = 0;
bool ForceSize(uint64 NewSize); virtual void Read(EbmlStream & inDataStream, const EbmlSemanticContext & Context, int & UpperEltFound, EbmlElement * & FoundElt, bool AllowDummyElt = false, ScopeMode ReadFully = SCOPE_ALL_DATA);
uint32 OverwriteHead(IOCallback & output, bool bKeepPosition = false); bool IsLocked() const {return bLocked;}
void Lock(bool bLock = true) { bLocked = bLock;}
/*!
\brief void the content of the element (replace by EbmlVoid) /*!
*/ \brief default comparison for elements that can't be compared
uint32 VoidMe(IOCallback & output, bool bKeepIntact = false); */
virtual bool operator<(const EbmlElement & EltB) const {
bool DefaultISset() const {return DefaultIsSet;} return true;
virtual bool IsDefaultValue() const = 0; }
bool IsFiniteSize() const {return bSizeIsFinite;}
static bool CompareElements(const EbmlElement *A, const EbmlElement *B);
/*!
\brief set the default size of an element virtual bool IsDummy() const {return false;}
*/ virtual bool IsMaster() const {return false;}
virtual void SetDefaultSize(uint64 aDefaultSize) {DefaultSize = aDefaultSize;}
uint8 HeadSize() const {
bool ValueIsSet() const {return bValueIsSet;} return EBML_ID_LENGTH(EbmlId(*this)) + CodedSizeLength(Size, SizeLength, bSizeIsFinite);
} /// return the size of the head, on reading/writing
inline uint64 GetEndPosition() const {
return SizePosition + CodedSizeLength(Size, SizeLength, bSizeIsFinite) + Size; /*!
} \brief Force the size of an element
\warning only possible if the size is "undefined"
protected: */
/*! bool ForceSize(uint64 NewSize);
\brief find any element in the stream
\return a DummyRawElement if the element is unknown or NULL if the element dummy is not allowed uint32 OverwriteHead(IOCallback & output, bool bKeepPosition = false);
*/
static EbmlElement *CreateElementUsingContext(const EbmlId & aID, const EbmlSemanticContext & Context, int & LowLevel, bool IsGlobalContext, bool bAllowDummy = false, unsigned int MaxLowerLevel = 1); /*!
\brief void the content of the element (replace by EbmlVoid)
uint32 RenderHead(IOCallback & output, bool bForceRender, bool bKeepIntact = false, bool bKeepPosition = false); */
uint32 MakeRenderHead(IOCallback & output, bool bKeepPosition); uint32 VoidMe(IOCallback & output, bool bKeepIntact = false);
/*! bool DefaultISset() const {return DefaultIsSet;}
\brief prepare the data before writing them (in case it's not already done by default) virtual bool IsDefaultValue() const = 0;
*/ bool IsFiniteSize() const {return bSizeIsFinite;}
virtual uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false) = 0;
/*!
/*! \brief set the default size of an element
\brief special constructor for cloning */
*/ virtual void SetDefaultSize(uint64 aDefaultSize) {DefaultSize = aDefaultSize;}
EbmlElement(const EbmlElement & ElementToClone);
bool ValueIsSet() const {return bValueIsSet;}
inline uint64 GetDefaultSize() const {return DefaultSize;}
inline void SetSize_(uint64 aSize) {Size = aSize;} inline uint64 GetEndPosition() const {
inline void SetValueIsSet(bool Set = true) {bValueIsSet = Set;} return SizePosition + CodedSizeLength(Size, SizeLength, bSizeIsFinite) + Size;
inline void SetDefaultIsSet(bool Set = true) {DefaultIsSet = Set;} }
inline void SetSizeIsFinite(bool Set = true) {bSizeIsFinite = Set;}
inline uint64 GetSizePosition() const {return SizePosition;} protected:
/*!
uint64 Size; ///< the size of the data to write \brief find any element in the stream
uint64 DefaultSize; ///< Minimum data size to fill on rendering (0 = optimal) \return a DummyRawElement if the element is unknown or NULL if the element dummy is not allowed
int SizeLength; /// the minimum size on which the size will be written (0 = optimal) */
bool bSizeIsFinite; static EbmlElement *CreateElementUsingContext(const EbmlId & aID, const EbmlSemanticContext & Context, int & LowLevel, bool IsGlobalContext, bool bAllowDummy = false, unsigned int MaxLowerLevel = 1);
uint64 ElementPosition;
uint64 SizePosition; uint32 RenderHead(IOCallback & output, bool bForceRender, bool bKeepIntact = false, bool bKeepPosition = false);
bool bValueIsSet; uint32 MakeRenderHead(IOCallback & output, bool bKeepPosition);
bool DefaultIsSet;
bool bLocked; /*!
}; \brief prepare the data before writing them (in case it's not already done by default)
*/
END_LIBEBML_NAMESPACE virtual uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false) = 0;
#endif // LIBEBML_ELEMENT_H /*!
\brief special constructor for cloning
*/
EbmlElement(const EbmlElement & ElementToClone);
inline uint64 GetDefaultSize() const {return DefaultSize;}
inline void SetSize_(uint64 aSize) {Size = aSize;}
inline void SetValueIsSet(bool Set = true) {bValueIsSet = Set;}
inline void SetDefaultIsSet(bool Set = true) {DefaultIsSet = Set;}
inline void SetSizeIsFinite(bool Set = true) {bSizeIsFinite = Set;}
inline uint64 GetSizePosition() const {return SizePosition;}
#if defined(EBML_STRICT_API)
private:
#endif
uint64 Size; ///< the size of the data to write
uint64 DefaultSize; ///< Minimum data size to fill on rendering (0 = optimal)
int SizeLength; /// the minimum size on which the size will be written (0 = optimal)
bool bSizeIsFinite;
uint64 ElementPosition;
uint64 SizePosition;
bool bValueIsSet;
bool DefaultIsSet;
bool bLocked;
};
END_LIBEBML_NAMESPACE
#endif // LIBEBML_ELEMENT_H

View File

@ -1,120 +1,124 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlEndian.h 1298 2008-02-21 22:14:18Z mosu $ \version \$Id: EbmlEndian.h 1298 2008-02-21 22:14:18Z mosu $
\author Ingo Ralf Blum <ingoralfblum @ users.sf.net> \author Ingo Ralf Blum <ingoralfblum @ users.sf.net>
\author Lasse Kärkkäinen <tronic @ users.sf.net> \author Lasse Kärkkäinen <tronic @ users.sf.net>
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#ifndef LIBEBML_ENDIAN_H #ifndef LIBEBML_ENDIAN_H
#define LIBEBML_ENDIAN_H #define LIBEBML_ENDIAN_H
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include "EbmlConfig.h" // contains _ENDIANESS_ #include "EbmlConfig.h" // contains _ENDIANESS_
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
enum endianess { enum endianess {
big_endian, ///< PowerPC, Alpha, 68000 big_endian, ///< PowerPC, Alpha, 68000
little_endian ///< Intel x86 platforms little_endian ///< Intel x86 platforms
}; };
/*! /*!
\class Endian \class Endian
\brief general class to handle endian-specific buffers \brief general class to handle endian-specific buffers
\note don't forget to define/undefine _ENDIANESS_ to BIG_ENDIAN depending on your machine \note don't forget to define/undefine _ENDIANESS_ to BIG_ENDIAN depending on your machine
*/ */
template<class TYPE, endianess ENDIAN> class Endian template<class TYPE, endianess ENDIAN> class Endian
{ {
public: public:
Endian() {} Endian() {}
Endian(const TYPE value) Endian(const TYPE value)
{ {
memcpy(&platform_value, &value, sizeof(TYPE)); memcpy(&platform_value, &value, sizeof(TYPE));
process_endian(); process_endian();
} }
inline Endian & Eval(const binary *endian_buffer) inline Endian & Eval(const binary *endian_buffer)
{ {
//endian_value = *(TYPE *)(endian_buffer); //endian_value = *(TYPE *)(endian_buffer);
memcpy(&endian_value, endian_buffer, sizeof(TYPE)); // Some (all?) RISC processors do not allow reading objects bigger than 1 byte from non-aligned addresses, and endian_buffer may point to a non-aligned address. memcpy(&endian_value, endian_buffer, sizeof(TYPE)); // Some (all?) RISC processors do not allow reading objects bigger than 1 byte from non-aligned addresses, and endian_buffer may point to a non-aligned address.
process_platform(); process_platform();
return *this; return *this;
} }
inline void Fill(binary *endian_buffer) const inline void Fill(binary *endian_buffer) const
{ {
//*(TYPE*)endian_buffer = endian_value; //*(TYPE*)endian_buffer = endian_value;
memcpy(endian_buffer, &endian_value, sizeof(TYPE)); // See above. memcpy(endian_buffer, &endian_value, sizeof(TYPE)); // See above.
} }
inline operator const TYPE&() const { return platform_value; } inline operator const TYPE&() const { return platform_value; }
// inline TYPE endian() const { return endian_value; } // inline TYPE endian() const { return endian_value; }
inline const TYPE &endian() const { return endian_value; } inline const TYPE &endian() const { return endian_value; }
inline size_t size() const { return sizeof(TYPE); } inline size_t size() const { return sizeof(TYPE); }
inline bool operator!=(const binary *buffer) const {return *((TYPE*)buffer) == platform_value;} inline bool operator!=(const binary *buffer) const {return *((TYPE*)buffer) == platform_value;}
protected: #if defined(EBML_STRICT_API)
TYPE platform_value; private:
TYPE endian_value; #else
protected:
inline void process_endian() #endif
{ TYPE platform_value;
endian_value = platform_value; TYPE endian_value;
#ifdef WORDS_BIGENDIAN
if (ENDIAN == little_endian) inline void process_endian()
std::reverse(reinterpret_cast<uint8*>(&endian_value),reinterpret_cast<uint8*>(&endian_value+1)); {
#else // _ENDIANESS_ endian_value = platform_value;
if (ENDIAN == big_endian) #ifdef WORDS_BIGENDIAN
std::reverse(reinterpret_cast<uint8*>(&endian_value),reinterpret_cast<uint8*>(&endian_value+1)); if (ENDIAN == little_endian)
#endif // _ENDIANESS_ std::reverse(reinterpret_cast<uint8*>(&endian_value),reinterpret_cast<uint8*>(&endian_value+1));
} #else // _ENDIANESS_
if (ENDIAN == big_endian)
inline void process_platform() std::reverse(reinterpret_cast<uint8*>(&endian_value),reinterpret_cast<uint8*>(&endian_value+1));
{ #endif // _ENDIANESS_
platform_value = endian_value; }
#ifdef WORDS_BIGENDIAN
if (ENDIAN == little_endian) inline void process_platform()
std::reverse(reinterpret_cast<uint8*>(&platform_value),reinterpret_cast<uint8*>(&platform_value+1)); {
#else // _ENDIANESS_ platform_value = endian_value;
if (ENDIAN == big_endian) #ifdef WORDS_BIGENDIAN
std::reverse(reinterpret_cast<uint8*>(&platform_value),reinterpret_cast<uint8*>(&platform_value+1)); if (ENDIAN == little_endian)
#endif // _ENDIANESS_ std::reverse(reinterpret_cast<uint8*>(&platform_value),reinterpret_cast<uint8*>(&platform_value+1));
} #else // _ENDIANESS_
}; if (ENDIAN == big_endian)
std::reverse(reinterpret_cast<uint8*>(&platform_value),reinterpret_cast<uint8*>(&platform_value+1));
END_LIBEBML_NAMESPACE #endif // _ENDIANESS_
}
#endif // LIBEBML_ENDIAN_H };
END_LIBEBML_NAMESPACE
#endif // LIBEBML_ENDIAN_H

View File

@ -1,100 +1,104 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlFloat.h 1079 2005-03-03 13:18:14Z robux4 $ \version \$Id: EbmlFloat.h 1079 2005-03-03 13:18:14Z robux4 $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#ifndef LIBEBML_FLOAT_H #ifndef LIBEBML_FLOAT_H
#define LIBEBML_FLOAT_H #define LIBEBML_FLOAT_H
#include "EbmlTypes.h" #include "EbmlTypes.h"
#include "EbmlElement.h" #include "EbmlElement.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
/*! /*!
\class EbmlFloat \class EbmlFloat
\brief Handle all operations on a float EBML element \brief Handle all operations on a float EBML element
*/ */
class EBML_DLL_API EbmlFloat : public EbmlElement { class EBML_DLL_API EbmlFloat : public EbmlElement {
public: public:
enum Precision { enum Precision {
FLOAT_32 FLOAT_32
,FLOAT_64 ,FLOAT_64
}; };
EbmlFloat(const Precision prec = FLOAT_32); EbmlFloat(const Precision prec = FLOAT_32);
EbmlFloat(const double DefaultValue, const Precision prec = FLOAT_32); EbmlFloat(const double DefaultValue, const Precision prec = FLOAT_32);
EbmlFloat(const EbmlFloat & ElementToClone); EbmlFloat(const EbmlFloat & ElementToClone);
bool ValidateSize() const bool ValidateSize() const
{ {
return (GetSize() == 4 || GetSize() == 8); return (GetSize() == 4 || GetSize() == 8);
} }
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false); uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false); uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
void SetPrecision(const EbmlFloat::Precision prec = FLOAT_32) void SetPrecision(const EbmlFloat::Precision prec = FLOAT_32)
{ {
if (prec == FLOAT_64) if (prec == FLOAT_64)
SetSize_(8); SetSize_(8);
else else
SetSize_(4); // default size SetSize_(4); // default size
} }
// EbmlFloat & operator=(const float NewValue) { Value = NewValue; return *this;} // EbmlFloat & operator=(const float NewValue) { Value = NewValue; return *this;}
EbmlFloat & operator=(const double NewValue) { Value = NewValue; SetValueIsSet(); return *this;} EbmlFloat & operator=(const double NewValue) { Value = NewValue; SetValueIsSet(); return *this;}
bool operator<(const EbmlFloat & EltCmp) const {return Value < EltCmp.Value;} bool operator<(const EbmlFloat & EltCmp) const {return Value < EltCmp.Value;}
operator const float() const {return float(Value);} operator const float() const {return float(Value);}
operator const double() const {return double(Value);} operator const double() const {return double(Value);}
void SetDefaultValue(double aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();} 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 { bool IsDefaultValue() const {
return (DefaultISset() && Value == DefaultValue); return (DefaultISset() && Value == DefaultValue);
} }
protected: #if defined(EBML_STRICT_API)
double Value; /// The actual value of the element private:
double DefaultValue; #else
}; protected:
#endif
END_LIBEBML_NAMESPACE double Value; /// The actual value of the element
double DefaultValue;
#endif // LIBEBML_FLOAT_H };
END_LIBEBML_NAMESPACE
#endif // LIBEBML_FLOAT_H

View File

@ -1,89 +1,99 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlId.h 936 2004-11-10 20:46:28Z mosu $ \version \$Id: EbmlId.h 936 2004-11-10 20:46:28Z mosu $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#ifndef LIBEBML_ID_H #ifndef LIBEBML_ID_H
#define LIBEBML_ID_H #define LIBEBML_ID_H
#include "EbmlTypes.h" #include "EbmlTypes.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
#define EBML_ID_VALUE(id) id.Value
#define EBML_ID_LENGTH(id) id.Length #if defined(EBML_STRICT_API)
/*! #define EBML_ID_VALUE(id) id.GetValue()
\class EbmlId #define EBML_ID_LENGTH(id) id.GetLength()
*/ #else
class EBML_DLL_API EbmlId { #define EBML_ID_VALUE(id) id.Value
public: #define EBML_ID_LENGTH(id) id.Length
EbmlId(const binary aValue[4], const unsigned int aLength) #endif
:Length(aLength)
{ /*!
Value = 0; \class EbmlId
unsigned int i; */
for (i=0; i<aLength; i++) { class EBML_DLL_API EbmlId {
Value <<= 8; public:
Value += aValue[i]; EbmlId(const binary aValue[4], const unsigned int aLength)
} :Length(aLength)
} {
Value = 0;
EbmlId(const uint32 aValue, const unsigned int aLength) unsigned int i;
:Value(aValue), Length(aLength) {} for (i=0; i<aLength; i++) {
Value <<= 8;
inline bool operator==(const EbmlId & TestId) const Value += aValue[i];
{ }
return ((TestId.Length == Length) && (TestId.Value == Value)); }
}
inline bool operator!=(const EbmlId & TestId) const EbmlId(const uint32 aValue, const unsigned int aLength)
{ :Value(aValue), Length(aLength) {}
return !(*this == TestId);
} inline bool operator==(const EbmlId & TestId) const
{
inline void Fill(binary * Buffer) const { return ((TestId.Length == Length) && (TestId.Value == Value));
unsigned int i; }
for (i = 0; i<Length; i++) { inline bool operator!=(const EbmlId & TestId) const
Buffer[i] = (Value >> (8*(Length-i-1))) & 0xFF; {
} return !(*this == TestId);
} }
inline size_t GetLength() const { return Length; } inline void Fill(binary * Buffer) const {
inline uint32 GetValue() const { return Value; } unsigned int i;
for (i = 0; i<Length; i++) {
uint32 Value; Buffer[i] = (Value >> (8*(Length-i-1))) & 0xFF;
size_t Length; }
}; }
END_LIBEBML_NAMESPACE inline size_t GetLength() const { return Length; }
inline uint32 GetValue() const { return Value; }
#endif // LIBEBML_ID_H
#if defined(EBML_STRICT_API)
private:
#endif
uint32 Value;
size_t Length;
};
END_LIBEBML_NAMESPACE
#endif // LIBEBML_ID_H

View File

@ -1,211 +1,215 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlMaster.h 1232 2005-10-15 15:56:52Z robux4 $ \version \$Id: EbmlMaster.h 1232 2005-10-15 15:56:52Z robux4 $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#ifndef LIBEBML_MASTER_H #ifndef LIBEBML_MASTER_H
#define LIBEBML_MASTER_H #define LIBEBML_MASTER_H
#include <string> #include <string>
#include <vector> #include <vector>
#include "EbmlTypes.h" #include "EbmlTypes.h"
#include "EbmlElement.h" #include "EbmlElement.h"
#include "EbmlCrc32.h" #include "EbmlCrc32.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
const bool bChecksumUsedByDefault = false; const bool bChecksumUsedByDefault = false;
/*! /*!
\class EbmlMaster \class EbmlMaster
\brief Handle all operations on an EBML element that contains other EBML elements \brief Handle all operations on an EBML element that contains other EBML elements
*/ */
class EBML_DLL_API EbmlMaster : public EbmlElement { class EBML_DLL_API EbmlMaster : public EbmlElement {
public: public:
EbmlMaster(const EbmlSemanticContext & aContext, bool bSizeIsKnown = true); EbmlMaster(const EbmlSemanticContext & aContext, bool bSizeIsKnown = true);
EbmlMaster(const EbmlMaster & ElementToClone); EbmlMaster(const EbmlMaster & ElementToClone);
bool ValidateSize() const {return true;} bool ValidateSize() const {return true;}
/*! /*!
\warning be carefull to clear the memory allocated in the ElementList elsewhere \warning be carefull to clear the memory allocated in the ElementList elsewhere
*/ */
virtual ~EbmlMaster(); virtual ~EbmlMaster();
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false); uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully); uint64 ReadData(IOCallback & input, ScopeMode ReadFully);
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false); uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
/*! /*!
\brief Set wether the size is finite (size is known in advance when writing, or infinite size is not known on writing) \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) {SetSizeIsFinite(!aIsInfinite); return true;} bool SetSizeInfinite(bool aIsInfinite = true) {SetSizeIsFinite(!aIsInfinite); return true;}
bool PushElement(EbmlElement & element); bool PushElement(EbmlElement & element);
uint64 GetSize() const { uint64 GetSize() const {
if (IsFiniteSize()) if (IsFiniteSize())
return GetSize(); return GetSize();
else else
return (0-1); return (0-1);
} }
uint64 GetDataStart() const { uint64 GetDataStart() const {
return GetElementPosition() + EBML_ID_LENGTH(EbmlId(*this)) + CodedSizeLength(GetSize(), GetSizeLength(), IsFiniteSize()); return GetElementPosition() + EBML_ID_LENGTH(EbmlId(*this)) + CodedSizeLength(GetSize(), GetSizeLength(), IsFiniteSize());
} }
/*! /*!
\brief find the element corresponding to the ID of the element, NULL if not found \brief find the element corresponding to the ID of the element, NULL if not found
*/ */
EbmlElement *FindElt(const EbmlCallbacks & Callbacks) const; EbmlElement *FindElt(const EbmlCallbacks & Callbacks) const;
/*! /*!
\brief find the first element corresponding to the ID of the element \brief find the first element corresponding to the ID of the element
*/ */
EbmlElement *FindFirstElt(const EbmlCallbacks & Callbacks, bool bCreateIfNull); EbmlElement *FindFirstElt(const EbmlCallbacks & Callbacks, bool bCreateIfNull);
EbmlElement *FindFirstElt(const EbmlCallbacks & Callbacks) const; EbmlElement *FindFirstElt(const EbmlCallbacks & Callbacks) const;
/*! /*!
\brief find the element of the same type of PasElt following in the list of elements \brief find the element of the same type of PasElt following in the list of elements
*/ */
EbmlElement *FindNextElt(const EbmlElement & PastElt, bool bCreateIfNull); EbmlElement *FindNextElt(const EbmlElement & PastElt, bool bCreateIfNull);
EbmlElement *FindNextElt(const EbmlElement & PastElt) const; EbmlElement *FindNextElt(const EbmlElement & PastElt) const;
EbmlElement *AddNewElt(const EbmlCallbacks & Callbacks); EbmlElement *AddNewElt(const EbmlCallbacks & Callbacks);
/*! /*!
\brief add an element at a specified location \brief add an element at a specified location
*/ */
bool InsertElement(EbmlElement & element, size_t position = 0); bool InsertElement(EbmlElement & element, size_t position = 0);
bool InsertElement(EbmlElement & element, const EbmlElement & before); bool InsertElement(EbmlElement & element, const EbmlElement & before);
/*! /*!
\brief Read the data and keep the known children \brief Read the data and keep the known children
*/ */
void Read(EbmlStream & inDataStream, const EbmlSemanticContext & Context, int & UpperEltFound, EbmlElement * & FoundElt, bool AllowDummyElt, ScopeMode ReadFully = SCOPE_ALL_DATA); void Read(EbmlStream & inDataStream, const EbmlSemanticContext & Context, int & UpperEltFound, EbmlElement * & FoundElt, bool AllowDummyElt, ScopeMode ReadFully = SCOPE_ALL_DATA);
/*! /*!
\brief sort Data when they can \brief sort Data when they can
*/ */
void Sort(); void Sort();
size_t ListSize() const {return ElementList.size();} size_t ListSize() const {return ElementList.size();}
inline std::vector<EbmlElement *>::const_iterator begin() {return ElementList.begin();} inline std::vector<EbmlElement *>::const_iterator begin() {return ElementList.begin();}
inline std::vector<EbmlElement *>::const_iterator end() {return ElementList.end();} inline std::vector<EbmlElement *>::const_iterator end() {return ElementList.end();}
EbmlElement * operator[](unsigned int position) {return ElementList[position];} EbmlElement * operator[](unsigned int position) {return ElementList[position];}
const EbmlElement * operator[](unsigned int position) const {return ElementList[position];} const EbmlElement * operator[](unsigned int position) const {return ElementList[position];}
bool IsDefaultValue() const { bool IsDefaultValue() const {
return (ElementList.size() == 0); return (ElementList.size() == 0);
} }
virtual bool IsMaster() const {return true;} virtual bool IsMaster() const {return true;}
/*! /*!
\brief verify that all mandatory elements are present \brief verify that all mandatory elements are present
\note usefull after reading or before writing \note usefull after reading or before writing
*/ */
bool CheckMandatory() const; bool CheckMandatory() const;
/*! /*!
\brief Remove an element from the list of the master \brief Remove an element from the list of the master
*/ */
void Remove(size_t Index); void Remove(size_t Index);
/*! /*!
\brief remove all elements, even the mandatory ones \brief remove all elements, even the mandatory ones
*/ */
void RemoveAll() {ElementList.clear();} void RemoveAll() {ElementList.clear();}
/*! /*!
\brief facility for Master elements to write only the head and force the size later \brief facility for Master elements to write only the head and force the size later
\warning \warning
*/ */
uint32 WriteHead(IOCallback & output, int SizeLength, bool bKeepIntact = false); uint32 WriteHead(IOCallback & output, int SizeLength, bool bKeepIntact = false);
void EnableChecksum(bool bIsEnabled = true) { bChecksumUsed = bIsEnabled; } void EnableChecksum(bool bIsEnabled = true) { bChecksumUsed = bIsEnabled; }
bool HasChecksum() const {return bChecksumUsed;} bool HasChecksum() const {return bChecksumUsed;}
bool VerifyChecksum() const; bool VerifyChecksum() const;
uint32 GetCrc32() const {return Checksum.GetCrc32();} uint32 GetCrc32() const {return Checksum.GetCrc32();}
void ForceChecksum(uint32 NewChecksum) { void ForceChecksum(uint32 NewChecksum) {
Checksum.ForceCrc32(NewChecksum); Checksum.ForceCrc32(NewChecksum);
bChecksumUsed = true; bChecksumUsed = true;
} }
/*! /*!
\brief drill down all sub-elements, finding any missing elements \brief drill down all sub-elements, finding any missing elements
*/ */
std::vector<std::string> FindAllMissingElements(); std::vector<std::string> FindAllMissingElements();
protected: #if defined(EBML_STRICT_API)
std::vector<EbmlElement *> ElementList; private:
#else
const EbmlSemanticContext & Context; protected:
#endif
bool bChecksumUsed; std::vector<EbmlElement *> ElementList;
EbmlCrc32 Checksum;
const EbmlSemanticContext & Context;
private:
/*! bool bChecksumUsed;
\brief Add all the mandatory elements to the list EbmlCrc32 Checksum;
*/
bool ProcessMandatory(); private:
}; /*!
\brief Add all the mandatory elements to the list
///< \todo add a restriction to only elements legal in the context */
template <typename Type> bool ProcessMandatory();
Type & GetChild(EbmlMaster & Master) };
{
return *(static_cast<Type *>(Master.FindFirstElt(EBML_INFO(Type), true))); ///< \todo add a restriction to only elements legal in the context
} template <typename Type>
// call with Type & GetChild(EbmlMaster & Master)
// MyDocType = GetChild<EDocType>(TestHead); {
return *(static_cast<Type *>(Master.FindFirstElt(EBML_INFO(Type), true)));
template <typename Type> }
Type * FindChild(EbmlMaster & Master) // call with
{ // MyDocType = GetChild<EDocType>(TestHead);
return static_cast<Type *>(Master.FindFirstElt(EBML_INFO(Type), false));
} template <typename Type>
Type * FindChild(EbmlMaster & Master)
template <typename Type> {
Type & GetNextChild(EbmlMaster & Master, const Type & PastElt) return static_cast<Type *>(Master.FindFirstElt(EBML_INFO(Type), false));
{ }
return *(static_cast<Type *>(Master.FindNextElt(PastElt, true)));
} template <typename Type>
Type & GetNextChild(EbmlMaster & Master, const Type & PastElt)
template <typename Type> {
Type & AddNewChild(EbmlMaster & Master) return *(static_cast<Type *>(Master.FindNextElt(PastElt, true)));
{ }
return *(static_cast<Type *>(Master.AddNewElt(EBML_INFO(Type))));
} template <typename Type>
Type & AddNewChild(EbmlMaster & Master)
END_LIBEBML_NAMESPACE {
return *(static_cast<Type *>(Master.AddNewElt(EBML_INFO(Type))));
#endif // LIBEBML_MASTER_H }
END_LIBEBML_NAMESPACE
#endif // LIBEBML_MASTER_H

View File

@ -1,92 +1,96 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlSInteger.h 1079 2005-03-03 13:18:14Z robux4 $ \version \$Id: EbmlSInteger.h 1079 2005-03-03 13:18:14Z robux4 $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
\author Julien Coloos <suiryc @ users.sf.net> \author Julien Coloos <suiryc @ users.sf.net>
\author Moritz Bunkus <moritz @ bunkus.org> \author Moritz Bunkus <moritz @ bunkus.org>
*/ */
#ifndef LIBEBML_SINTEGER_H #ifndef LIBEBML_SINTEGER_H
#define LIBEBML_SINTEGER_H #define LIBEBML_SINTEGER_H
#include "EbmlTypes.h" #include "EbmlTypes.h"
#include "EbmlElement.h" #include "EbmlElement.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
const int DEFAULT_INT_SIZE = 1; ///< optimal size stored const int DEFAULT_INT_SIZE = 1; ///< optimal size stored
/*! /*!
\class EbmlSInteger \class EbmlSInteger
\brief Handle all operations on a signed integer EBML element \brief Handle all operations on a signed integer EBML element
*/ */
class EBML_DLL_API EbmlSInteger : public EbmlElement { class EBML_DLL_API EbmlSInteger : public EbmlElement {
public: public:
EbmlSInteger(); EbmlSInteger();
EbmlSInteger(int64 DefaultValue); EbmlSInteger(int64 DefaultValue);
EbmlSInteger(const EbmlSInteger & ElementToClone); EbmlSInteger(const EbmlSInteger & ElementToClone);
EbmlSInteger & operator = (int64 NewValue) {Value = NewValue; SetValueIsSet(); return *this;} EbmlSInteger & operator = (int64 NewValue) {Value = NewValue; SetValueIsSet(); return *this;}
/*! /*!
Set the default size of the integer (usually 1,2,4 or 8) Set the default size of the integer (usually 1,2,4 or 8)
*/ */
void SetDefaultSize(int nDefaultSize = DEFAULT_INT_SIZE) {SetSize_(nDefaultSize);} void SetDefaultSize(int nDefaultSize = DEFAULT_INT_SIZE) {SetSize_(nDefaultSize);}
bool ValidateSize() const {return (GetSize() <= 8);} bool ValidateSize() const {return (GetSize() <= 8);}
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false); uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false); uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
bool operator<(const EbmlSInteger & EltCmp) const {return Value < EltCmp.Value;} bool operator<(const EbmlSInteger & EltCmp) const {return Value < EltCmp.Value;}
operator int8() {return int8(Value);} operator int8() {return int8(Value);}
operator int16() {return int16(Value);} operator int16() {return int16(Value);}
operator int32() {return int32(Value);} operator int32() {return int32(Value);}
operator int64() {return Value;} operator int64() {return Value;}
void SetDefaultValue(int64 aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();} 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 { bool IsDefaultValue() const {
return (DefaultISset() && Value == DefaultValue); return (DefaultISset() && Value == DefaultValue);
} }
protected: #if defined(EBML_STRICT_API)
int64 Value; /// The actual value of the element private:
int64 DefaultValue; #else
}; protected:
#endif
END_LIBEBML_NAMESPACE int64 Value; /// The actual value of the element
int64 DefaultValue;
#endif // LIBEBML_SINTEGER_H };
END_LIBEBML_NAMESPACE
#endif // LIBEBML_SINTEGER_H

View File

@ -1,72 +1,76 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlStream.h 639 2004-07-09 20:59:14Z mosu $ \version \$Id: EbmlStream.h 639 2004-07-09 20:59:14Z mosu $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#ifndef LIBEBML_STREAM_H #ifndef LIBEBML_STREAM_H
#define LIBEBML_STREAM_H #define LIBEBML_STREAM_H
#include "EbmlTypes.h" #include "EbmlTypes.h"
#include "IOCallback.h" #include "IOCallback.h"
#include "EbmlElement.h" #include "EbmlElement.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
/*! /*!
\class EbmlStream \class EbmlStream
\brief Handle an input/output stream of EBML elements \brief Handle an input/output stream of EBML elements
*/ */
class EBML_DLL_API EbmlStream { class EBML_DLL_API EbmlStream {
public: public:
EbmlStream(IOCallback & output); EbmlStream(IOCallback & output);
~EbmlStream(); ~EbmlStream();
/*! /*!
\brief Find a possible next ID in the data stream \brief Find a possible next ID in the data stream
\param MaxDataSize The maximum possible of the data in the element (for sanity checks) \param MaxDataSize The maximum possible of the data in the element (for sanity checks)
\note the user will have to delete that element later \note the user will have to delete that element later
*/ */
EbmlElement * FindNextID(const EbmlCallbacks & ClassInfos, const uint64 MaxDataSize); EbmlElement * FindNextID(const EbmlCallbacks & ClassInfos, const uint64 MaxDataSize);
EbmlElement * FindNextElement(const EbmlSemanticContext & Context, int & UpperLevel, const uint64 MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel = 1); EbmlElement * FindNextElement(const EbmlSemanticContext & Context, int & UpperLevel, const uint64 MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel = 1);
inline IOCallback & I_O() {return Stream;} inline IOCallback & I_O() {return Stream;}
operator IOCallback &() {return Stream;} operator IOCallback &() {return Stream;}
protected: #if defined(EBML_STRICT_API)
IOCallback & Stream; private:
}; #else
protected:
END_LIBEBML_NAMESPACE #endif
IOCallback & Stream;
#endif // LIBEBML_STREAM_H };
END_LIBEBML_NAMESPACE
#endif // LIBEBML_STREAM_H

View File

@ -1,81 +1,85 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlString.h 1079 2005-03-03 13:18:14Z robux4 $ \version \$Id: EbmlString.h 1079 2005-03-03 13:18:14Z robux4 $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#ifndef LIBEBML_STRING_H #ifndef LIBEBML_STRING_H
#define LIBEBML_STRING_H #define LIBEBML_STRING_H
#include <string> #include <string>
#include "EbmlTypes.h" #include "EbmlTypes.h"
#include "EbmlElement.h" #include "EbmlElement.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
/*! /*!
\class EbmlString \class EbmlString
\brief Handle all operations on a printable string EBML element \brief Handle all operations on a printable string EBML element
*/ */
class EBML_DLL_API EbmlString : public EbmlElement { class EBML_DLL_API EbmlString : public EbmlElement {
public: public:
EbmlString(); EbmlString();
EbmlString(const std::string & aDefaultValue); EbmlString(const std::string & aDefaultValue);
EbmlString(const EbmlString & ElementToClone); EbmlString(const EbmlString & ElementToClone);
virtual ~EbmlString() {} virtual ~EbmlString() {}
bool ValidateSize() const {return true;} // any size is possible bool ValidateSize() const {return true;} // any size is possible
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false); uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false); uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
EbmlString & operator=(const std::string); EbmlString & operator=(const std::string);
operator const std::string &() const {return Value;} operator const std::string &() const {return Value;}
void SetDefaultValue(std::string & aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();} 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 { bool IsDefaultValue() const {
return (DefaultISset() && Value == DefaultValue); return (DefaultISset() && Value == DefaultValue);
} }
protected: #if defined(EBML_STRICT_API)
std::string Value; /// The actual value of the element private:
std::string DefaultValue; #else
}; protected:
#endif
END_LIBEBML_NAMESPACE std::string Value; /// The actual value of the element
std::string DefaultValue;
#endif // LIBEBML_STRING_H };
END_LIBEBML_NAMESPACE
#endif // LIBEBML_STRING_H

View File

@ -1,92 +1,96 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlUInteger.h 1079 2005-03-03 13:18:14Z robux4 $ \version \$Id: EbmlUInteger.h 1079 2005-03-03 13:18:14Z robux4 $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
\author Julien Coloos <suiryc @ users.sf.net> \author Julien Coloos <suiryc @ users.sf.net>
\author Moritz Bunkus <moritz @ bunkus.org> \author Moritz Bunkus <moritz @ bunkus.org>
*/ */
#ifndef LIBEBML_UINTEGER_H #ifndef LIBEBML_UINTEGER_H
#define LIBEBML_UINTEGER_H #define LIBEBML_UINTEGER_H
#include "EbmlTypes.h" #include "EbmlTypes.h"
#include "EbmlElement.h" #include "EbmlElement.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
const int DEFAULT_UINT_SIZE = 0; ///< optimal size stored const int DEFAULT_UINT_SIZE = 0; ///< optimal size stored
/*! /*!
\class EbmlUInteger \class EbmlUInteger
\brief Handle all operations on an unsigned integer EBML element \brief Handle all operations on an unsigned integer EBML element
*/ */
class EBML_DLL_API EbmlUInteger : public EbmlElement { class EBML_DLL_API EbmlUInteger : public EbmlElement {
public: public:
EbmlUInteger(); EbmlUInteger();
EbmlUInteger(uint64 DefaultValue); EbmlUInteger(uint64 DefaultValue);
EbmlUInteger(const EbmlUInteger & ElementToClone); EbmlUInteger(const EbmlUInteger & ElementToClone);
EbmlUInteger & operator=(uint64 NewValue) {Value = NewValue; SetValueIsSet(); return *this;} EbmlUInteger & operator=(uint64 NewValue) {Value = NewValue; SetValueIsSet(); return *this;}
/*! /*!
Set the default size of the integer (usually 1,2,4 or 8) Set the default size of the integer (usually 1,2,4 or 8)
*/ */
void SetDefaultSize(int nDefaultSize = DEFAULT_UINT_SIZE) {SetSize_(nDefaultSize);} void SetDefaultSize(int nDefaultSize = DEFAULT_UINT_SIZE) {SetSize_(nDefaultSize);}
bool ValidateSize() const {return (GetSize() <= 8);} bool ValidateSize() const {return (GetSize() <= 8);}
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false); uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false); uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
bool operator<(const EbmlUInteger & EltCmp) const {return Value < EltCmp.Value;} bool operator<(const EbmlUInteger & EltCmp) const {return Value < EltCmp.Value;}
operator uint8() const {return uint8(Value); } operator uint8() const {return uint8(Value); }
operator uint16() const {return uint16(Value);} operator uint16() const {return uint16(Value);}
operator uint32() const {return uint32(Value);} operator uint32() const {return uint32(Value);}
operator uint64() const {return Value;} operator uint64() const {return Value;}
void SetDefaultValue(uint64 aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();} 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 { bool IsDefaultValue() const {
return (DefaultISset() && Value == DefaultValue); return (DefaultISset() && Value == DefaultValue);
} }
protected: #if defined(EBML_STRICT_API)
uint64 Value; /// The actual value of the element private:
uint64 DefaultValue; #else
}; protected:
#endif
END_LIBEBML_NAMESPACE uint64 Value; /// The actual value of the element
uint64 DefaultValue;
#endif // LIBEBML_UINTEGER_H };
END_LIBEBML_NAMESPACE
#endif // LIBEBML_UINTEGER_H

View File

@ -1,126 +1,134 @@
/**************************************************************************** /****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/ ** libebml : parse EBML files, see http://embl.sourceforge.net/
** **
** <file/class description> ** <file/class description>
** **
** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2010 Steve Lhomme. All rights reserved.
** **
** This file is part of libebml. ** This file is part of libebml.
** **
** This library is free software; you can redistribute it and/or ** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public ** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either ** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version. ** version 2.1 of the License, or (at your option) any later version.
** **
** This library is distributed in the hope that it will be useful, ** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details. ** Lesser General Public License for more details.
** **
** You should have received a copy of the GNU Lesser General Public ** You should have received a copy of the GNU Lesser General Public
** License along with this library; if not, write to the Free Software ** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
** **
** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
** **
** Contact license@matroska.org if any conditions of this licensing are ** Contact license@matroska.org if any conditions of this licensing are
** not clear to you. ** not clear to you.
** **
**********************************************************************/ **********************************************************************/
/*! /*!
\file \file
\version \$Id: EbmlUnicodeString.h 1079 2005-03-03 13:18:14Z robux4 $ \version \$Id: EbmlUnicodeString.h 1079 2005-03-03 13:18:14Z robux4 $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
\author Moritz Bunkus <moritz @ bunkus.org> \author Moritz Bunkus <moritz @ bunkus.org>
\author Jory Stone <jcsston @ toughguy.net> \author Jory Stone <jcsston @ toughguy.net>
*/ */
#ifndef LIBEBML_UNICODE_STRING_H #ifndef LIBEBML_UNICODE_STRING_H
#define LIBEBML_UNICODE_STRING_H #define LIBEBML_UNICODE_STRING_H
#include <string> #include <string>
#include "EbmlTypes.h" #include "EbmlTypes.h"
#include "EbmlElement.h" #include "EbmlElement.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
/*! /*!
\class UTFstring \class UTFstring
A class storing strings in a wchar_t (ie, in UCS-2 or UCS-4) A class storing strings in a wchar_t (ie, in UCS-2 or UCS-4)
\note inspired by wstring which is not available everywhere \note inspired by wstring which is not available everywhere
*/ */
class EBML_DLL_API UTFstring { class EBML_DLL_API UTFstring {
public: public:
typedef wchar_t value_type; typedef wchar_t value_type;
UTFstring(); UTFstring();
UTFstring(const wchar_t *); // should be NULL terminated UTFstring(const wchar_t *); // should be NULL terminated
UTFstring(const UTFstring &); UTFstring(const UTFstring &);
virtual ~UTFstring(); virtual ~UTFstring();
bool operator==(const UTFstring&) const; bool operator==(const UTFstring&) const;
inline bool operator!=(const UTFstring &cmp) const inline bool operator!=(const UTFstring &cmp) const
{ {
return !(*this == cmp); return !(*this == cmp);
} }
UTFstring & operator=(const UTFstring &); UTFstring & operator=(const UTFstring &);
UTFstring & operator=(const wchar_t *); UTFstring & operator=(const wchar_t *);
UTFstring & operator=(wchar_t); UTFstring & operator=(wchar_t);
/// Return length of string /// Return length of string
size_t length() const {return _Length;} size_t length() const {return _Length;}
operator const wchar_t*() const {return _Data;} operator const wchar_t*() const {return _Data;}
const wchar_t* c_str() const {return _Data;} const wchar_t* c_str() const {return _Data;}
const std::string & GetUTF8() const {return UTF8string;} const std::string & GetUTF8() const {return UTF8string;}
void SetUTF8(const std::string &); void SetUTF8(const std::string &);
protected: #if defined(EBML_STRICT_API)
size_t _Length; ///< length of the UCS string excluding the \0 private:
wchar_t* _Data; ///< internal UCS representation #else
std::string UTF8string; protected:
static bool wcscmp_internal(const wchar_t *str1, const wchar_t *str2); #endif
void UpdateFromUTF8(); size_t _Length; ///< length of the UCS string excluding the \0
void UpdateFromUCS2(); wchar_t* _Data; ///< internal UCS representation
}; std::string UTF8string;
static bool wcscmp_internal(const wchar_t *str1, const wchar_t *str2);
void UpdateFromUTF8();
/*! void UpdateFromUCS2();
\class EbmlUnicodeString };
\brief Handle all operations on a Unicode string EBML element
\note internally treated as a string made of wide characters (ie UCS-2 or UCS-4 depending on the machine)
*/ /*!
class EBML_DLL_API EbmlUnicodeString : public EbmlElement { \class EbmlUnicodeString
public: \brief Handle all operations on a Unicode string EBML element
EbmlUnicodeString(); \note internally treated as a string made of wide characters (ie UCS-2 or UCS-4 depending on the machine)
EbmlUnicodeString(const UTFstring & DefaultValue); */
EbmlUnicodeString(const EbmlUnicodeString & ElementToClone); class EBML_DLL_API EbmlUnicodeString : public EbmlElement {
public:
virtual ~EbmlUnicodeString() {} EbmlUnicodeString();
EbmlUnicodeString(const UTFstring & DefaultValue);
bool ValidateSize() const {return true;} // any size is possible EbmlUnicodeString(const EbmlUnicodeString & ElementToClone);
uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); virtual ~EbmlUnicodeString() {}
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
bool ValidateSize() const {return true;} // any size is possible
EbmlUnicodeString & operator=(const UTFstring &); ///< platform dependant code uint32 RenderData(IOCallback & output, bool bForceRender, bool bKeepIntact = false);
operator const UTFstring &() const {return Value;} uint64 ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
uint64 UpdateSize(bool bKeepIntact = false, bool bForceRender = false);
void SetDefaultValue(UTFstring & aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();}
EbmlUnicodeString & operator=(const UTFstring &); ///< platform dependant code
UTFstring DefaultVal() const {assert(DefaultISset()); return DefaultValue;} operator const UTFstring &() const {return Value;}
bool IsDefaultValue() const { void SetDefaultValue(UTFstring & aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();}
return (DefaultISset() && Value == DefaultValue);
} UTFstring DefaultVal() const {assert(DefaultISset()); return DefaultValue;}
protected: bool IsDefaultValue() const {
UTFstring Value; /// The actual value of the element return (DefaultISset() && Value == DefaultValue);
UTFstring DefaultValue; }
};
#if defined(EBML_STRICT_API)
END_LIBEBML_NAMESPACE private:
#else
#endif // LIBEBML_UNICODE_STRING_H protected:
#endif
UTFstring Value; /// The actual value of the element
UTFstring DefaultValue;
};
END_LIBEBML_NAMESPACE
#endif // LIBEBML_UNICODE_STRING_H

View File

@ -6,6 +6,7 @@ LIB ebml
INCLUDE . INCLUDE .
EXPINCLUDE . EXPINCLUDE .
EXPDEFINE(USE_EBML_STRICT_API) EBML_STRICT_API
// OPTIMIZE_GLOBALLY . // OPTIMIZE_GLOBALLY .
FAVOR_MAX_SPEED . FAVOR_MAX_SPEED .