libebml/libebml2: only Master elements can have an infinite/unknown size

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libebml@270 a6f86f6d-0131-4f8e-9e7b-e335508773d5
This commit is contained in:
Steve Lhomme 2010-05-25 12:02:30 +00:00
parent ece95ac6b7
commit 8f6b7a6fd9
8 changed files with 488 additions and 487 deletions

View File

@ -1,106 +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$
\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 <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);
virtual bool ValidateSize() const {return true;} // we don't mind about what's inside virtual bool ValidateSize() const {return IsFiniteSize() && GetSize() < INT_MAX;} // we don't mind about what's inside
filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false); filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false);
filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false); filepos_t UpdateSize(bool bWithDefault = 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;
#if defined(EBML_STRICT_API) #if defined(EBML_STRICT_API)
private: private:
#else #else
protected: protected:
#endif #endif
binary *Data; // the binary data inside the element binary *Data; // the binary data inside the element
}; };
END_LIBEBML_NAMESPACE END_LIBEBML_NAMESPACE
#endif // LIBEBML_BINARY_H #endif // LIBEBML_BINARY_H

View File

@ -1,156 +1,156 @@
/**************************************************************************** /****************************************************************************
** 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$
\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 <cassert> #include <cassert>
#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
DECLARE_EBML_BINARY(EbmlCrc32) DECLARE_EBML_BINARY(EbmlCrc32)
public: public:
EbmlCrc32(const EbmlCrc32 & ElementToClone); EbmlCrc32(const EbmlCrc32 & ElementToClone);
virtual bool ValidateSize() const {return (GetSize() == 4);} virtual bool ValidateSize() const {return IsFiniteSize() && (GetSize() == 4);}
filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false); filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false);
filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
// filepos_t UpdateSize(bool bWithDefault = false); // filepos_t UpdateSize(bool bWithDefault = 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();}
#if defined(EBML_STRICT_API) #if defined(EBML_STRICT_API)
private: private:
#else #else
protected: protected:
#endif #endif
void ResetCRC() {m_crc = CRC32_NEGL;} void ResetCRC() {m_crc = CRC32_NEGL;}
void UpdateByte(binary b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} void UpdateByte(binary b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
static const uint32 m_tab[256]; static const uint32 m_tab[256];
uint32 m_crc; uint32 m_crc;
uint32 m_crc_final; uint32 m_crc_final;
EBML_CONCRETE_CLASS(EbmlCrc32) EBML_CONCRETE_CLASS(EbmlCrc32)
}; };
template <class T> template <class T>
inline unsigned int GetAlignment(T *dummy=NULL) // VC60 workaround inline unsigned int GetAlignment(T *dummy=NULL) // VC60 workaround
{ {
#if (_MSC_VER >= 1300) #if (_MSC_VER >= 1300)
return __alignof(T); return __alignof(T);
#elif defined(__GNUC__) #elif defined(__GNUC__)
return __alignof__(T); return __alignof__(T);
#else #else
return sizeof(T); return sizeof(T);
#endif #endif
} }
template <class T> template <class T>
inline bool IsPowerOf2(T n) inline bool IsPowerOf2(T n)
{ {
return n > 0 && (n & (n-1)) == 0; return n > 0 && (n & (n-1)) == 0;
} }
template <class T1, class T2> template <class T1, class T2>
inline T2 ModPowerOf2(T1 a, T2 b) inline T2 ModPowerOf2(T1 a, T2 b)
{ {
assert(IsPowerOf2(b)); assert(IsPowerOf2(b));
return T2(a) & (b-1); return T2(a) & (b-1);
} }
inline bool IsAlignedOn(const void *p, unsigned int alignment) inline bool IsAlignedOn(const void *p, unsigned int alignment)
{ {
return IsPowerOf2(alignment) ? ModPowerOf2((uintptr_t)p, alignment) == 0 : (uintptr_t)p % alignment == 0; return IsPowerOf2(alignment) ? ModPowerOf2((uintptr_t)p, alignment) == 0 : (uintptr_t)p % alignment == 0;
} }
template <class T> template <class T>
inline bool IsAligned(const void *p, T *dummy=NULL) // VC60 workaround inline bool IsAligned(const void *p, T *dummy=NULL) // VC60 workaround
{ {
return IsAlignedOn(p, GetAlignment<T>()); return IsAlignedOn(p, GetAlignment<T>());
} }
END_LIBEBML_NAMESPACE END_LIBEBML_NAMESPACE
#endif // LIBEBML_CRC32_H #endif // LIBEBML_CRC32_H

View File

@ -28,7 +28,7 @@
/*! /*!
\file \file
\version \$Id: EbmlDate.h 1079 2005-03-03 13:18:14Z robux4 $ \version \$Id$
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#ifndef LIBEBML_DATE_H #ifndef LIBEBML_DATE_H
@ -60,7 +60,7 @@ class EBML_DLL_API EbmlDate : public EbmlElement {
*/ */
int32 GetEpochDate() const {return int32(myDate/1000000000 + UnixEpochDelay);} int32 GetEpochDate() const {return int32(myDate/1000000000 + UnixEpochDelay);}
virtual bool ValidateSize() const {return ((GetSize() == 8) || (GetSize() == 0));} virtual bool ValidateSize() const {return IsFiniteSize() && ((GetSize() == 8) || (GetSize() == 0));}
/*! /*!
\note no Default date handled \note no Default date handled

View File

@ -456,6 +456,7 @@ class EBML_DLL_API EbmlElement {
bool ValueIsSet() const {return bValueIsSet;} bool ValueIsSet() const {return bValueIsSet;}
inline uint64 GetEndPosition() const { inline uint64 GetEndPosition() const {
assert(bSizeIsFinite); // we don't know where the end is
return SizePosition + CodedSizeLength(Size, SizeLength, bSizeIsFinite) + Size; return SizePosition + CodedSizeLength(Size, SizeLength, bSizeIsFinite) + Size;
} }

View File

@ -30,7 +30,7 @@
/*! /*!
\file \file
\version \$Id: EbmlSInteger.h 1079 2005-03-03 13:18:14Z robux4 $ \version \$Id$
\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>
@ -64,7 +64,7 @@ class EBML_DLL_API EbmlSInteger : public EbmlElement {
*/ */
virtual void SetDefaultSize(uint64 nDefaultSize = DEFAULT_INT_SIZE) {EbmlElement::SetDefaultSize(nDefaultSize); SetSize_(nDefaultSize);} virtual void SetDefaultSize(uint64 nDefaultSize = DEFAULT_INT_SIZE) {EbmlElement::SetDefaultSize(nDefaultSize); SetSize_(nDefaultSize);}
virtual bool ValidateSize() const {return (GetSize() <= 8);} virtual bool ValidateSize() const {return IsFiniteSize() && (GetSize() <= 8);}
filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false); filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false);
filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false); filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false);

View File

@ -1,85 +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$
\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() {}
virtual bool ValidateSize() const {return true;} // any size is possible virtual bool ValidateSize() const {return IsFiniteSize();} // any size is possible
filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false); filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false);
filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false); filepos_t UpdateSize(bool bWithDefault = 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 &); void SetDefaultValue(std::string &);
const std::string & DefaultVal() const; const std::string & DefaultVal() const;
bool IsDefaultValue() const { bool IsDefaultValue() const {
return (DefaultISset() && Value == DefaultValue); return (DefaultISset() && Value == DefaultValue);
} }
#if defined(EBML_STRICT_API) #if defined(EBML_STRICT_API)
private: private:
#else #else
protected: protected:
#endif #endif
std::string Value; /// The actual value of the element std::string Value; /// The actual value of the element
std::string DefaultValue; std::string DefaultValue;
}; };
END_LIBEBML_NAMESPACE END_LIBEBML_NAMESPACE
#endif // LIBEBML_STRING_H #endif // LIBEBML_STRING_H

View File

@ -30,7 +30,7 @@
/*! /*!
\file \file
\version \$Id: EbmlUInteger.h 1079 2005-03-03 13:18:14Z robux4 $ \version \$Id$
\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>
@ -62,7 +62,7 @@ class EBML_DLL_API EbmlUInteger : public EbmlElement {
*/ */
virtual void SetDefaultSize(uint64 nDefaultSize = DEFAULT_UINT_SIZE) {EbmlElement::SetDefaultSize(nDefaultSize); SetSize_(nDefaultSize);} virtual void SetDefaultSize(uint64 nDefaultSize = DEFAULT_UINT_SIZE) {EbmlElement::SetDefaultSize(nDefaultSize); SetSize_(nDefaultSize);}
virtual bool ValidateSize() const {return (GetSize() <= 8);} virtual bool ValidateSize() const {return IsFiniteSize() && (GetSize() <= 8);}
filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false); filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false);
filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false); filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false);

View File

@ -1,134 +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$
\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 &);
#if defined(EBML_STRICT_API) #if defined(EBML_STRICT_API)
private: private:
#else #else
protected: protected:
#endif #endif
size_t _Length; ///< length of the UCS string excluding the \0 size_t _Length; ///< length of the UCS string excluding the \0
wchar_t* _Data; ///< internal UCS representation wchar_t* _Data; ///< internal UCS representation
std::string UTF8string; std::string UTF8string;
static bool wcscmp_internal(const wchar_t *str1, const wchar_t *str2); static bool wcscmp_internal(const wchar_t *str1, const wchar_t *str2);
void UpdateFromUTF8(); void UpdateFromUTF8();
void UpdateFromUCS2(); void UpdateFromUCS2();
}; };
/*! /*!
\class EbmlUnicodeString \class EbmlUnicodeString
\brief Handle all operations on a Unicode string EBML element \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) \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 EBML_DLL_API EbmlUnicodeString : public EbmlElement {
public: public:
EbmlUnicodeString(); EbmlUnicodeString();
EbmlUnicodeString(const UTFstring & DefaultValue); EbmlUnicodeString(const UTFstring & DefaultValue);
EbmlUnicodeString(const EbmlUnicodeString & ElementToClone); EbmlUnicodeString(const EbmlUnicodeString & ElementToClone);
virtual ~EbmlUnicodeString() {} virtual ~EbmlUnicodeString() {}
virtual bool ValidateSize() const {return true;} // any size is possible virtual bool ValidateSize() const {return IsFiniteSize();} // any size is possible
filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false); filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false);
filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA); filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA);
filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false); filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false);
EbmlUnicodeString & operator=(const UTFstring &); ///< platform dependant code EbmlUnicodeString & operator=(const UTFstring &); ///< platform dependant code
operator const UTFstring &() const {return Value;} operator const UTFstring &() const {return Value;}
void SetDefaultValue(UTFstring &); void SetDefaultValue(UTFstring &);
const UTFstring & DefaultVal() const; const UTFstring & DefaultVal() const;
bool IsDefaultValue() const { bool IsDefaultValue() const {
return (DefaultISset() && Value == DefaultValue); return (DefaultISset() && Value == DefaultValue);
} }
#if defined(EBML_STRICT_API) #if defined(EBML_STRICT_API)
private: private:
#else #else
protected: protected:
#endif #endif
UTFstring Value; /// The actual value of the element UTFstring Value; /// The actual value of the element
UTFstring DefaultValue; UTFstring DefaultValue;
}; };
END_LIBEBML_NAMESPACE END_LIBEBML_NAMESPACE
#endif // LIBEBML_UNICODE_STRING_H #endif // LIBEBML_UNICODE_STRING_H