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
This commit is contained in:
Steve Lhomme
2010-03-15 16:07:14 +00:00
parent 9122d30f15
commit cd378f23ff
7 changed files with 144 additions and 139 deletions

View File

@@ -144,6 +144,11 @@ class EBML_DLL_API EbmlSemanticContext {
const EbmlCallbacks *MasterElt; 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 \class EbmlElement
\brief Hold basic informations about an EBML element (ID + length) \brief Hold basic informations about an EBML element (ID + length)

View File

@@ -183,7 +183,7 @@ class EBML_DLL_API EbmlMaster : public EbmlElement {
template <typename Type> template <typename Type>
Type & GetChild(EbmlMaster & Master) Type & GetChild(EbmlMaster & Master)
{ {
return *(static_cast<Type *>(Master.FindFirstElt(Type::ClassInfos, true))); return *(static_cast<Type *>(Master.FindFirstElt(EBML_INFO(Type), true)));
} }
// call with // call with
// MyDocType = GetChild<EDocType>(TestHead); // MyDocType = GetChild<EDocType>(TestHead);
@@ -191,7 +191,7 @@ Type & GetChild(EbmlMaster & Master)
template <typename Type> template <typename Type>
Type * FindChild(EbmlMaster & Master) Type * FindChild(EbmlMaster & Master)
{ {
return static_cast<Type *>(Master.FindFirstElt(Type::ClassInfos, false)); return static_cast<Type *>(Master.FindFirstElt(EBML_INFO(Type), false));
} }
template <typename Type> template <typename Type>
@@ -203,7 +203,7 @@ Type & GetNextChild(EbmlMaster & Master, const Type & PastElt)
template <typename Type> template <typename Type>
Type & AddNewChild(EbmlMaster & Master) Type & AddNewChild(EbmlMaster & Master)
{ {
return *(static_cast<Type *>(Master.AddNewElt(Type::ClassInfos))); return *(static_cast<Type *>(Master.AddNewElt(EBML_INFO(Type))));
} }
END_LIBEBML_NAMESPACE END_LIBEBML_NAMESPACE

View File

@@ -1,57 +1,57 @@
/**************************************************************************** /****************************************************************************
** 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-2004 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2004 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: EbmlContexts.cpp 639 2004-07-09 20:59:14Z mosu $ \version \$Id: EbmlContexts.cpp 639 2004-07-09 20:59:14Z mosu $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#include "ebml/EbmlContexts.h" #include "ebml/EbmlContexts.h"
#include "ebml/EbmlCrc32.h" #include "ebml/EbmlCrc32.h"
#include "ebml/EbmlVoid.h" #include "ebml/EbmlVoid.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
const EbmlSemantic EbmlGlobal_ContextList[2] = const EbmlSemantic EbmlGlobal_ContextList[2] =
{ {
EbmlSemantic(false, false, EbmlCrc32::ClassInfos), ///< EbmlCrc32 EbmlSemantic(false, false, EBML_INFO(EbmlCrc32)), ///< EbmlCrc32
EbmlSemantic(false, false, EbmlVoid::ClassInfos), ///< EbmlVoid EbmlSemantic(false, false, EBML_INFO(EbmlVoid)), ///< EbmlVoid
}; };
const EbmlSemanticContext EbmlVoid_Context = EbmlSemanticContext(0, NULL, NULL, *GetEbmlGlobal_Context, NULL); 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); static const EbmlSemanticContext EbmlGlobal_Context = EbmlSemanticContext(countof(EbmlGlobal_ContextList), EbmlGlobal_ContextList, NULL, *GetEbmlGlobal_Context, NULL);
const EbmlSemanticContext & GetEbmlGlobal_Context() const EbmlSemanticContext & GetEbmlGlobal_Context()
{ {
return EbmlGlobal_Context; return EbmlGlobal_Context;
} }
END_LIBEBML_NAMESPACE END_LIBEBML_NAMESPACE

View File

@@ -39,7 +39,7 @@
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
const EbmlId EbmlDummy::DummyRawId(0xFF, 1); 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); const EbmlCallbacks EbmlDummy::ClassInfos(NULL, DummyRawId, "DummyElement", EbmlDummy_Context);
END_LIBEBML_NAMESPACE END_LIBEBML_NAMESPACE

View File

@@ -41,16 +41,16 @@ START_LIBEBML_NAMESPACE
const EbmlSemantic EbmlHead_ContextList[] = const EbmlSemantic EbmlHead_ContextList[] =
{ {
EbmlSemantic(true, true, EVersion::ClassInfos), ///< EBMLVersion EbmlSemantic(true, true, EBML_INFO(EVersion)), ///< EBMLVersion
EbmlSemantic(true, true, EReadVersion::ClassInfos), ///< EBMLReadVersion EbmlSemantic(true, true, EBML_INFO(EReadVersion)), ///< EBMLReadVersion
EbmlSemantic(true, true, EMaxIdLength::ClassInfos), ///< EBMLMaxIdLength EbmlSemantic(true, true, EBML_INFO(EMaxIdLength)), ///< EBMLMaxIdLength
EbmlSemantic(true, true, EMaxSizeLength::ClassInfos), ///< EBMLMaxSizeLength EbmlSemantic(true, true, EBML_INFO(EMaxSizeLength)), ///< EBMLMaxSizeLength
EbmlSemantic(true, true, EDocType::ClassInfos), ///< DocType EbmlSemantic(true, true, EBML_INFO(EDocType)), ///< DocType
EbmlSemantic(true, true, EDocTypeVersion::ClassInfos), ///< DocTypeVersion EbmlSemantic(true, true, EBML_INFO(EDocTypeVersion)), ///< DocTypeVersion
EbmlSemantic(true, true, EDocTypeReadVersion::ClassInfos), ///< DocTypeReadVersion 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); EbmlId EbmlHead_TheId(0x1A45DFA3, 4);
const EbmlCallbacks EbmlHead::ClassInfos(EbmlHead::Create, EbmlHead_TheId, "EBMLHead\0ratamapaga", EbmlHead_Context); const EbmlCallbacks EbmlHead::ClassInfos(EbmlHead::Create, EbmlHead_TheId, "EBMLHead\0ratamapaga", EbmlHead_Context);

View File

@@ -227,9 +227,9 @@ std::vector<std::string> EbmlMaster::FindAllMissingElements()
if (!childElement->ValueIsSet()) { if (!childElement->ValueIsSet()) {
std::string missingValue; std::string missingValue;
missingValue = "The Child Element \""; missingValue = "The Child Element \"";
missingValue.append(childElement->Generic().DebugName); missingValue.append(EBML_NAME(childElement));
missingValue.append("\" of EbmlMaster \""); missingValue.append("\" of EbmlMaster \"");
missingValue.append(this->Generic().DebugName); missingValue.append(EBML_NAME(this));
missingValue.append("\", does not have a value set."); missingValue.append("\", does not have a value set.");
missingElements.push_back(missingValue); missingElements.push_back(missingValue);
} }
@@ -424,10 +424,10 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo
// more logical to do it afterward // more logical to do it afterward
ElementList.push_back(ElementLevelA); 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 // just in case
ElementLevelA->SkipData(inDataStream, ElementLevelA->Generic().Context); ElementLevelA->SkipData(inDataStream, EBML_CONTEXT(ElementLevelA));
} }
if (UpperEltFound > 0) { if (UpperEltFound > 0) {
@@ -456,7 +456,7 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo
} }
processCrc: processCrc:
for (Index=0; Index<ElementList.size(); Index++) { for (Index=0; Index<ElementList.size(); Index++) {
if ((EbmlId)(*ElementList[Index]) == EbmlCrc32::ClassInfos.GlobalId) { if ((EbmlId)(*ElementList[Index]) == EBML_ID(EbmlCrc32)) {
bChecksumUsed = true; bChecksumUsed = true;
// remove the element // remove the element
Checksum = *(static_cast<EbmlCrc32*>(ElementList[Index])); Checksum = *(static_cast<EbmlCrc32*>(ElementList[Index]));

View File

@@ -1,65 +1,65 @@
/**************************************************************************** /****************************************************************************
** 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-2004 Steve Lhomme. All rights reserved. ** Copyright (C) 2002-2004 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: EbmlSubHead.cpp 639 2004-07-09 20:59:14Z mosu $ \version \$Id: EbmlSubHead.cpp 639 2004-07-09 20:59:14Z mosu $
\author Steve Lhomme <robux4 @ users.sf.net> \author Steve Lhomme <robux4 @ users.sf.net>
*/ */
#include "ebml/EbmlSubHead.h" #include "ebml/EbmlSubHead.h"
#include "ebml/EbmlContexts.h" #include "ebml/EbmlContexts.h"
START_LIBEBML_NAMESPACE START_LIBEBML_NAMESPACE
EbmlId EVersion_TheId (0x4286, 2); EbmlId EVersion_TheId (0x4286, 2);
EbmlId EReadVersion_TheId (0x42F7, 2); EbmlId EReadVersion_TheId (0x42F7, 2);
EbmlId EMaxIdLength_TheId (0x42F2, 2); EbmlId EMaxIdLength_TheId (0x42F2, 2);
EbmlId EMaxSizeLength_TheId (0x42F3, 2); EbmlId EMaxSizeLength_TheId (0x42F3, 2);
EbmlId EDocType_TheId (0x4282, 2); EbmlId EDocType_TheId (0x4282, 2);
EbmlId EDocTypeVersion_TheId (0x4287, 2); EbmlId EDocTypeVersion_TheId (0x4287, 2);
EbmlId EDocTypeReadVersion_TheId (0x4285, 2); EbmlId EDocTypeReadVersion_TheId (0x4285, 2);
const EbmlCallbacks EVersion::ClassInfos(EVersion::Create, EVersion_TheId, "EBMLVersion", EVersion_Context); const EbmlCallbacks EVersion::ClassInfos(EVersion::Create, EVersion_TheId, "EBMLVersion", EVersion_Context);
const EbmlCallbacks EReadVersion::ClassInfos(EReadVersion::Create, EReadVersion_TheId, "EBMLReadVersion", EReadVersion_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 EMaxIdLength::ClassInfos(EMaxIdLength::Create, EMaxIdLength_TheId, "EBMLMaxIdLength", EMaxIdLength_Context);
const EbmlCallbacks EMaxSizeLength::ClassInfos(EMaxSizeLength::Create, EMaxSizeLength_TheId, "EBMLMaxSizeLength", EMaxSizeLength_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 EDocType::ClassInfos(EDocType::Create, EDocType_TheId, "EBMLDocType", EDocType_Context);
const EbmlCallbacks EDocTypeVersion::ClassInfos(EDocTypeVersion::Create, EDocTypeVersion_TheId, "EBMLDocTypeVersion", EDocTypeVersion_Context); const EbmlCallbacks EDocTypeVersion::ClassInfos(EDocTypeVersion::Create, EDocTypeVersion_TheId, "EBMLDocTypeVersion", EDocTypeVersion_Context);
const EbmlCallbacks EDocTypeReadVersion::ClassInfos(EDocTypeReadVersion::Create, EDocTypeReadVersion_TheId, "EBMLDocTypeReadVersion", EDocTypeReadVersion_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 EVersion_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EBML_INFO(EVersion));
const EbmlSemanticContext EReadVersion_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EReadVersion::ClassInfos); 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, &EMaxIdLength::ClassInfos); 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, &EMaxSizeLength::ClassInfos); 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, &EDocType::ClassInfos); 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, &EDocTypeVersion::ClassInfos); 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, &EDocTypeReadVersion::ClassInfos); const EbmlSemanticContext EDocTypeReadVersion_Context = EbmlSemanticContext(0, NULL, &EbmlHead_Context, *GetEbmlGlobal_Context, &EBML_INFO(EDocTypeReadVersion));
END_LIBEBML_NAMESPACE END_LIBEBML_NAMESPACE