Skip to content

Commit

Permalink
add some macros to access the EBML ID/Context and use them
Browse files Browse the repository at this point in the history
git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/libebml@14 a6f86f6d-0131-4f8e-9e7b-e335508773d5
  • Loading branch information
robUx4 committed Mar 15, 2010
1 parent 9122d30 commit cd378f2
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 139 deletions.
5 changes: 5 additions & 0 deletions ebml/EbmlElement.h
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ebml/EbmlMaster.h
Expand Up @@ -183,15 +183,15 @@ class EBML_DLL_API EbmlMaster : public EbmlElement {
template <typename Type>
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
// MyDocType = GetChild<EDocType>(TestHead);

template <typename Type>
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>
Expand All @@ -203,7 +203,7 @@ Type & GetNextChild(EbmlMaster & Master, const Type & PastElt)
template <typename Type>
Type & AddNewChild(EbmlMaster & Master)
{
return *(static_cast<Type *>(Master.AddNewElt(Type::ClassInfos)));
return *(static_cast<Type *>(Master.AddNewElt(EBML_INFO(Type))));
}

END_LIBEBML_NAMESPACE
Expand Down
114 changes: 57 additions & 57 deletions src/EbmlContexts.cpp
@@ -1,57 +1,57 @@
/****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/
**
** <file/class description>
**
** 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 <robux4 @ users.sf.net>
*/
#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/
**
** <file/class description>
**
** 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 <robux4 @ users.sf.net>
*/
#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
2 changes: 1 addition & 1 deletion src/EbmlDummy.cpp
Expand Up @@ -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
16 changes: 8 additions & 8 deletions src/EbmlHead.cpp
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/EbmlMaster.cpp
Expand Up @@ -227,9 +227,9 @@ std::vector<std::string> 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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -456,7 +456,7 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo
}
processCrc:
for (Index=0; Index<ElementList.size(); Index++) {
if ((EbmlId)(*ElementList[Index]) == EbmlCrc32::ClassInfos.GlobalId) {
if ((EbmlId)(*ElementList[Index]) == EBML_ID(EbmlCrc32)) {
bChecksumUsed = true;
// remove the element
Checksum = *(static_cast<EbmlCrc32*>(ElementList[Index]));
Expand Down
130 changes: 65 additions & 65 deletions src/EbmlSubHead.cpp
@@ -1,65 +1,65 @@
/****************************************************************************
** libebml : parse EBML files, see http://embl.sourceforge.net/
**
** <file/class description>
**
** 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 <robux4 @ users.sf.net>
*/
#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/
**
** <file/class description>
**
** 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 <robux4 @ users.sf.net>
*/
#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

0 comments on commit cd378f2

Please sign in to comment.