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;
};
#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)

View File

@@ -183,7 +183,7 @@ 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);
@@ -191,7 +191,7 @@ Type & GetChild(EbmlMaster & Master)
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>
@@ -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

View File

@@ -41,8 +41,8 @@ START_LIBEBML_NAMESPACE
const EbmlSemantic EbmlGlobal_ContextList[2] =
{
EbmlSemantic(false, false, EbmlCrc32::ClassInfos), ///< EbmlCrc32
EbmlSemantic(false, false, EbmlVoid::ClassInfos), ///< EbmlVoid
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);

View File

@@ -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

View File

@@ -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);

View File

@@ -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);
}
@@ -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.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]));

View File

@@ -54,12 +54,12 @@ const EbmlCallbacks EDocType::ClassInfos(EDocType::Create, EDocTyp
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);
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