From cd378f23ff5c8bd477fe066fccca532bf00f974b Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Mon, 15 Mar 2010 16:07:14 +0000 Subject: [PATCH] add some macros to access the EBML ID/Context and use them git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libebml@14 a6f86f6d-0131-4f8e-9e7b-e335508773d5 --- ebml/EbmlElement.h | 5 ++ ebml/EbmlMaster.h | 6 +- src/EbmlContexts.cpp | 114 ++++++++++++++++++------------------- src/EbmlDummy.cpp | 2 +- src/EbmlHead.cpp | 16 +++--- src/EbmlMaster.cpp | 10 ++-- src/EbmlSubHead.cpp | 130 +++++++++++++++++++++---------------------- 7 files changed, 144 insertions(+), 139 deletions(-) diff --git a/ebml/EbmlElement.h b/ebml/EbmlElement.h index e335b4fd..eaa0ead0 100644 --- a/ebml/EbmlElement.h +++ b/ebml/EbmlElement.h @@ -144,6 +144,11 @@ class EBML_DLL_API EbmlSemanticContext { const EbmlCallbacks *MasterElt; }; +#define EBML_INFO(ref) ref::ClassInfos +#define EBML_ID(ref) ref::ClassInfos.GlobalId +#define EBML_CONTEXT(e) e->Generic().Context +#define EBML_NAME(e) e->Generic().DebugName + /*! \class EbmlElement \brief Hold basic informations about an EBML element (ID + length) diff --git a/ebml/EbmlMaster.h b/ebml/EbmlMaster.h index 218d03d8..6cd5df26 100644 --- a/ebml/EbmlMaster.h +++ b/ebml/EbmlMaster.h @@ -183,7 +183,7 @@ class EBML_DLL_API EbmlMaster : public EbmlElement { template Type & GetChild(EbmlMaster & Master) { - return *(static_cast(Master.FindFirstElt(Type::ClassInfos, true))); + return *(static_cast(Master.FindFirstElt(EBML_INFO(Type), true))); } // call with // MyDocType = GetChild(TestHead); @@ -191,7 +191,7 @@ Type & GetChild(EbmlMaster & Master) template Type * FindChild(EbmlMaster & Master) { - return static_cast(Master.FindFirstElt(Type::ClassInfos, false)); + return static_cast(Master.FindFirstElt(EBML_INFO(Type), false)); } template @@ -203,7 +203,7 @@ Type & GetNextChild(EbmlMaster & Master, const Type & PastElt) template Type & AddNewChild(EbmlMaster & Master) { - return *(static_cast(Master.AddNewElt(Type::ClassInfos))); + return *(static_cast(Master.AddNewElt(EBML_INFO(Type)))); } END_LIBEBML_NAMESPACE diff --git a/src/EbmlContexts.cpp b/src/EbmlContexts.cpp index d5c362b2..e96598c4 100644 --- a/src/EbmlContexts.cpp +++ b/src/EbmlContexts.cpp @@ -1,57 +1,57 @@ -/**************************************************************************** -** libebml : parse EBML files, see http://embl.sourceforge.net/ -** -** -** -** Copyright (C) 2002-2004 Steve Lhomme. All rights reserved. -** -** This file is part of libebml. -** -** This library is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** 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, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with this library; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -** -** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. -** -** Contact license@matroska.org if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -/*! - \file - \version \$Id: EbmlContexts.cpp 639 2004-07-09 20:59:14Z mosu $ - \author Steve Lhomme -*/ -#include "ebml/EbmlContexts.h" -#include "ebml/EbmlCrc32.h" -#include "ebml/EbmlVoid.h" - -START_LIBEBML_NAMESPACE - -const EbmlSemantic EbmlGlobal_ContextList[2] = -{ - EbmlSemantic(false, false, EbmlCrc32::ClassInfos), ///< EbmlCrc32 - EbmlSemantic(false, false, EbmlVoid::ClassInfos), ///< EbmlVoid -}; - -const EbmlSemanticContext EbmlVoid_Context = EbmlSemanticContext(0, NULL, NULL, *GetEbmlGlobal_Context, NULL); - -static const EbmlSemanticContext EbmlGlobal_Context = EbmlSemanticContext(countof(EbmlGlobal_ContextList), EbmlGlobal_ContextList, NULL, *GetEbmlGlobal_Context, NULL); - -const EbmlSemanticContext & GetEbmlGlobal_Context() -{ - return EbmlGlobal_Context; -} - -END_LIBEBML_NAMESPACE +/**************************************************************************** +** libebml : parse EBML files, see http://embl.sourceforge.net/ +** +** +** +** Copyright (C) 2002-2004 Steve Lhomme. All rights reserved. +** +** This file is part of libebml. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** 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, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +** +** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. +** +** Contact license@matroska.org if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +/*! + \file + \version \$Id: EbmlContexts.cpp 639 2004-07-09 20:59:14Z mosu $ + \author Steve Lhomme +*/ +#include "ebml/EbmlContexts.h" +#include "ebml/EbmlCrc32.h" +#include "ebml/EbmlVoid.h" + +START_LIBEBML_NAMESPACE + +const EbmlSemantic EbmlGlobal_ContextList[2] = +{ + EbmlSemantic(false, false, EBML_INFO(EbmlCrc32)), ///< EbmlCrc32 + EbmlSemantic(false, false, EBML_INFO(EbmlVoid)), ///< EbmlVoid +}; + +const EbmlSemanticContext EbmlVoid_Context = EbmlSemanticContext(0, NULL, NULL, *GetEbmlGlobal_Context, NULL); + +static const EbmlSemanticContext EbmlGlobal_Context = EbmlSemanticContext(countof(EbmlGlobal_ContextList), EbmlGlobal_ContextList, NULL, *GetEbmlGlobal_Context, NULL); + +const EbmlSemanticContext & GetEbmlGlobal_Context() +{ + return EbmlGlobal_Context; +} + +END_LIBEBML_NAMESPACE diff --git a/src/EbmlDummy.cpp b/src/EbmlDummy.cpp index 17bf40f5..225d189d 100644 --- a/src/EbmlDummy.cpp +++ b/src/EbmlDummy.cpp @@ -39,7 +39,7 @@ START_LIBEBML_NAMESPACE const EbmlId EbmlDummy::DummyRawId(0xFF, 1); -const EbmlSemanticContext EbmlDummy_Context = EbmlSemanticContext(0, NULL, NULL, *GetEbmlGlobal_Context, &EbmlDummy::ClassInfos); +const EbmlSemanticContext EbmlDummy_Context = EbmlSemanticContext(0, NULL, NULL, *GetEbmlGlobal_Context, &EBML_INFO(EbmlDummy)); const EbmlCallbacks EbmlDummy::ClassInfos(NULL, DummyRawId, "DummyElement", EbmlDummy_Context); END_LIBEBML_NAMESPACE diff --git a/src/EbmlHead.cpp b/src/EbmlHead.cpp index 5e36dbab..c7c20639 100644 --- a/src/EbmlHead.cpp +++ b/src/EbmlHead.cpp @@ -41,16 +41,16 @@ START_LIBEBML_NAMESPACE const EbmlSemantic EbmlHead_ContextList[] = { - EbmlSemantic(true, true, EVersion::ClassInfos), ///< EBMLVersion - EbmlSemantic(true, true, EReadVersion::ClassInfos), ///< EBMLReadVersion - EbmlSemantic(true, true, EMaxIdLength::ClassInfos), ///< EBMLMaxIdLength - EbmlSemantic(true, true, EMaxSizeLength::ClassInfos), ///< EBMLMaxSizeLength - EbmlSemantic(true, true, EDocType::ClassInfos), ///< DocType - EbmlSemantic(true, true, EDocTypeVersion::ClassInfos), ///< DocTypeVersion - EbmlSemantic(true, true, EDocTypeReadVersion::ClassInfos), ///< DocTypeReadVersion + EbmlSemantic(true, true, EBML_INFO(EVersion)), ///< EBMLVersion + EbmlSemantic(true, true, EBML_INFO(EReadVersion)), ///< EBMLReadVersion + EbmlSemantic(true, true, EBML_INFO(EMaxIdLength)), ///< EBMLMaxIdLength + EbmlSemantic(true, true, EBML_INFO(EMaxSizeLength)), ///< EBMLMaxSizeLength + EbmlSemantic(true, true, EBML_INFO(EDocType)), ///< DocType + EbmlSemantic(true, true, EBML_INFO(EDocTypeVersion)), ///< DocTypeVersion + EbmlSemantic(true, true, EBML_INFO(EDocTypeReadVersion)), ///< DocTypeReadVersion }; -const EbmlSemanticContext EbmlHead_Context = EbmlSemanticContext(countof(EbmlHead_ContextList), EbmlHead_ContextList, NULL, *GetEbmlGlobal_Context, &EbmlHead::ClassInfos); +const EbmlSemanticContext EbmlHead_Context = EbmlSemanticContext(countof(EbmlHead_ContextList), EbmlHead_ContextList, NULL, *GetEbmlGlobal_Context, &EBML_INFO(EbmlHead)); EbmlId EbmlHead_TheId(0x1A45DFA3, 4); const EbmlCallbacks EbmlHead::ClassInfos(EbmlHead::Create, EbmlHead_TheId, "EBMLHead\0ratamapaga", EbmlHead_Context); diff --git a/src/EbmlMaster.cpp b/src/EbmlMaster.cpp index 7b98a530..0b4a91c0 100644 --- a/src/EbmlMaster.cpp +++ b/src/EbmlMaster.cpp @@ -227,9 +227,9 @@ std::vector EbmlMaster::FindAllMissingElements() if (!childElement->ValueIsSet()) { std::string missingValue; missingValue = "The Child Element \""; - missingValue.append(childElement->Generic().DebugName); + missingValue.append(EBML_NAME(childElement)); missingValue.append("\" of EbmlMaster \""); - missingValue.append(this->Generic().DebugName); + missingValue.append(EBML_NAME(this)); missingValue.append("\", does not have a value set."); missingElements.push_back(missingValue); } @@ -424,10 +424,10 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo // more logical to do it afterward ElementList.push_back(ElementLevelA); - ElementLevelA->Read(inDataStream, ElementLevelA->Generic().Context, UpperEltFound, FoundElt, AllowDummyElt, ReadFully); + ElementLevelA->Read(inDataStream, EBML_CONTEXT(ElementLevelA), UpperEltFound, FoundElt, AllowDummyElt, ReadFully); // just in case - ElementLevelA->SkipData(inDataStream, ElementLevelA->Generic().Context); + ElementLevelA->SkipData(inDataStream, EBML_CONTEXT(ElementLevelA)); } if (UpperEltFound > 0) { @@ -456,7 +456,7 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo } processCrc: for (Index=0; Index(ElementList[Index])); diff --git a/src/EbmlSubHead.cpp b/src/EbmlSubHead.cpp index 1e76c905..10eb5f32 100644 --- a/src/EbmlSubHead.cpp +++ b/src/EbmlSubHead.cpp @@ -1,65 +1,65 @@ -/**************************************************************************** -** libebml : parse EBML files, see http://embl.sourceforge.net/ -** -** -** -** Copyright (C) 2002-2004 Steve Lhomme. All rights reserved. -** -** This file is part of libebml. -** -** This library is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** 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, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with this library; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -** -** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. -** -** Contact license@matroska.org if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -/*! - \file - \version \$Id: EbmlSubHead.cpp 639 2004-07-09 20:59:14Z mosu $ - \author Steve Lhomme -*/ -#include "ebml/EbmlSubHead.h" -#include "ebml/EbmlContexts.h" - -START_LIBEBML_NAMESPACE - -EbmlId EVersion_TheId (0x4286, 2); -EbmlId EReadVersion_TheId (0x42F7, 2); -EbmlId EMaxIdLength_TheId (0x42F2, 2); -EbmlId EMaxSizeLength_TheId (0x42F3, 2); -EbmlId EDocType_TheId (0x4282, 2); -EbmlId EDocTypeVersion_TheId (0x4287, 2); -EbmlId EDocTypeReadVersion_TheId (0x4285, 2); - -const EbmlCallbacks EVersion::ClassInfos(EVersion::Create, EVersion_TheId, "EBMLVersion", EVersion_Context); -const EbmlCallbacks EReadVersion::ClassInfos(EReadVersion::Create, EReadVersion_TheId, "EBMLReadVersion", EReadVersion_Context); -const EbmlCallbacks EMaxIdLength::ClassInfos(EMaxIdLength::Create, EMaxIdLength_TheId, "EBMLMaxIdLength", EMaxIdLength_Context); -const EbmlCallbacks EMaxSizeLength::ClassInfos(EMaxSizeLength::Create, EMaxSizeLength_TheId, "EBMLMaxSizeLength", EMaxSizeLength_Context); -const EbmlCallbacks EDocType::ClassInfos(EDocType::Create, EDocType_TheId, "EBMLDocType", EDocType_Context); -const EbmlCallbacks EDocTypeVersion::ClassInfos(EDocTypeVersion::Create, EDocTypeVersion_TheId, "EBMLDocTypeVersion", EDocTypeVersion_Context); -const EbmlCallbacks EDocTypeReadVersion::ClassInfos(EDocTypeReadVersion::Create, EDocTypeReadVersion_TheId, "EBMLDocTypeReadVersion", EDocTypeReadVersion_Context); - -const EbmlSemanticContext EVersion_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EVersion::ClassInfos); -const EbmlSemanticContext EReadVersion_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EReadVersion::ClassInfos); -const EbmlSemanticContext EMaxIdLength_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EMaxIdLength::ClassInfos); -const EbmlSemanticContext EMaxSizeLength_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EMaxSizeLength::ClassInfos); -const EbmlSemanticContext EDocType_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EDocType::ClassInfos); -const EbmlSemanticContext EDocTypeVersion_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EDocTypeVersion::ClassInfos); -const EbmlSemanticContext EDocTypeReadVersion_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EDocTypeReadVersion::ClassInfos); - -END_LIBEBML_NAMESPACE +/**************************************************************************** +** libebml : parse EBML files, see http://embl.sourceforge.net/ +** +** +** +** Copyright (C) 2002-2004 Steve Lhomme. All rights reserved. +** +** This file is part of libebml. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License as published by the Free Software Foundation; either +** 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, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** Lesser General Public License for more details. +** +** You should have received a copy of the GNU Lesser General Public +** License along with this library; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +** +** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. +** +** Contact license@matroska.org if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +/*! + \file + \version \$Id: EbmlSubHead.cpp 639 2004-07-09 20:59:14Z mosu $ + \author Steve Lhomme +*/ +#include "ebml/EbmlSubHead.h" +#include "ebml/EbmlContexts.h" + +START_LIBEBML_NAMESPACE + +EbmlId EVersion_TheId (0x4286, 2); +EbmlId EReadVersion_TheId (0x42F7, 2); +EbmlId EMaxIdLength_TheId (0x42F2, 2); +EbmlId EMaxSizeLength_TheId (0x42F3, 2); +EbmlId EDocType_TheId (0x4282, 2); +EbmlId EDocTypeVersion_TheId (0x4287, 2); +EbmlId EDocTypeReadVersion_TheId (0x4285, 2); + +const EbmlCallbacks EVersion::ClassInfos(EVersion::Create, EVersion_TheId, "EBMLVersion", EVersion_Context); +const EbmlCallbacks EReadVersion::ClassInfos(EReadVersion::Create, EReadVersion_TheId, "EBMLReadVersion", EReadVersion_Context); +const EbmlCallbacks EMaxIdLength::ClassInfos(EMaxIdLength::Create, EMaxIdLength_TheId, "EBMLMaxIdLength", EMaxIdLength_Context); +const EbmlCallbacks EMaxSizeLength::ClassInfos(EMaxSizeLength::Create, EMaxSizeLength_TheId, "EBMLMaxSizeLength", EMaxSizeLength_Context); +const EbmlCallbacks EDocType::ClassInfos(EDocType::Create, EDocType_TheId, "EBMLDocType", EDocType_Context); +const EbmlCallbacks EDocTypeVersion::ClassInfos(EDocTypeVersion::Create, EDocTypeVersion_TheId, "EBMLDocTypeVersion", EDocTypeVersion_Context); +const EbmlCallbacks EDocTypeReadVersion::ClassInfos(EDocTypeReadVersion::Create, EDocTypeReadVersion_TheId, "EBMLDocTypeReadVersion", EDocTypeReadVersion_Context); + +const EbmlSemanticContext EVersion_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EBML_INFO(EVersion)); +const EbmlSemanticContext EReadVersion_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EBML_INFO(EReadVersion)); +const EbmlSemanticContext EMaxIdLength_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EBML_INFO(EMaxIdLength)); +const EbmlSemanticContext EMaxSizeLength_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EBML_INFO(EMaxSizeLength)); +const EbmlSemanticContext EDocType_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EBML_INFO(EDocType)); +const EbmlSemanticContext EDocTypeVersion_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EBML_INFO(EDocTypeVersion)); +const EbmlSemanticContext EDocTypeReadVersion_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EBML_INFO(EDocTypeReadVersion)); + +END_LIBEBML_NAMESPACE