Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use macros to define global context and make all semantic constexpr #190

Merged
merged 6 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ set(libebml_SOURCES
src/EbmlSInteger.cpp
src/EbmlStream.cpp
src/EbmlString.cpp
src/EbmlSubHead.cpp
src/EbmlUInteger.cpp
src/EbmlUnicodeString.cpp
src/EbmlVersion.cpp
Expand Down
11 changes: 1 addition & 10 deletions ebml/EbmlContexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@

namespace libebml {

extern const EbmlSemanticContext EBML_DLL_API EbmlHead_Context;
extern const EbmlSemanticContext EBML_DLL_API EVersion_Context;
extern const EbmlSemanticContext EBML_DLL_API EReadVersion_Context;
extern const EbmlSemanticContext EBML_DLL_API EMaxIdLength_Context;
extern const EbmlSemanticContext EBML_DLL_API EMaxSizeLength_Context;
extern const EbmlSemanticContext EBML_DLL_API EDocType_Context;
extern const EbmlSemanticContext EBML_DLL_API EDocTypeVersion_Context;
extern const EbmlSemanticContext EBML_DLL_API EDocTypeReadVersion_Context;

#define Context_EbmlHead EbmlHead_Context
extern const EbmlSemanticContext EBML_DLL_API Context_EbmlHead;

// global elements
extern const EbmlSemanticContext EBML_DLL_API & GetEbmlGlobal_Context();
Expand Down
27 changes: 13 additions & 14 deletions ebml/EbmlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,18 @@ class EbmlStream;
class EbmlSemanticContext;
class EbmlElement;

extern const EbmlSemanticContext Context_EbmlGlobal;

#define DEFINE_xxx_CONTEXT(x,global) \
const EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, nullptr, global, nullptr); \
constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, nullptr, global, nullptr); \

#define DEFINE_xxx_MASTER(x,id,idl,parent,infinite,name,global) \
constexpr EbmlId Id_##x (id, idl); \
const EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, infinite, name, Context_##x); \
x::x() :EbmlMaster(x::ClassInfos, Context_##x) {}

#define DEFINE_xxx_MASTER_CONS(x,id,idl,parent,infinite,name,global) \
constexpr EbmlId Id_##x (id, idl); \
const EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, infinite, name, Context_##x);

// define a master class with no parent class
Expand All @@ -74,46 +72,47 @@ extern const EbmlSemanticContext Context_EbmlGlobal;

#define DEFINE_xxx_CLASS(x,id,idl,parent,name,global) \
constexpr EbmlId Id_##x (id, idl); \
const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \
x::x() {}

#define DEFINE_xxx_CLASS_CONS(x,id,idl,parent,name,global) \
constexpr EbmlId Id_##x (id, idl); \
const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x);

#define DEFINE_xxx_UINTEGER_DEF(x,id,idl,parent,name,global,defval) \
constexpr EbmlId Id_##x (id, idl); \
const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \
x::x() :EbmlUInteger(x::ClassInfos, defval) {}

#define DEFINE_xxx_SINTEGER_DEF(x,id,idl,parent,name,global,defval) \
constexpr EbmlId Id_##x (id, idl); \
const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \
x::x() :EbmlSInteger(x::ClassInfos, defval) {}

#define DEFINE_xxx_STRING_DEF(x,id,idl,parent,name,global,defval) \
constexpr EbmlId Id_##x (id, idl); \
const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \
x::x() :EbmlString(x::ClassInfos, defval) {}

#define DEFINE_xxx_FLOAT_DEF(x,id,idl,parent,name,global,defval) \
constexpr EbmlId Id_##x (id, idl); \
const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \
constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \
x::x() :EbmlFloat(x::ClassInfos, defval) {}

#define DEFINE_xxx_CLASS_GLOBAL(x,id,idl,name,global) \
constexpr EbmlId Id_##x (id, idl); \
constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_EbmlGlobal); \
constexpr EbmlSemanticContext EmptyContext_##x = EbmlSemanticContext(0, nullptr, nullptr, global, nullptr); \
constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, EmptyContext_##x); \

#define DEFINE_xxx_CLASS_ORPHAN(x,id,idl,name,global) \
constexpr EbmlId Id_##x (id, idl); \
const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, nullptr, global, nullptr); \
constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, nullptr, global, nullptr); \
constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \

#define DEFINE_EBML_CONTEXT(x) DEFINE_xxx_CONTEXT(x,GetEbmlGlobal_Context)
Expand Down Expand Up @@ -216,7 +215,7 @@ class EBML_DLL_API EbmlCallbacks {
}

inline const EbmlId & ClassId() const { return GlobalId; }
inline const EbmlSemanticContext & GetContext() const { return Context; }
inline constexpr const EbmlSemanticContext & GetContext() const { return Context; }
inline const char * GetName() const { return DebugName; }
inline EbmlElement & NewElement() const { return Create(); }
/// is infinite/unknown size allowed
Expand Down
15 changes: 6 additions & 9 deletions src/EbmlContexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@

namespace libebml {

static constexpr EbmlSemantic EbmlGlobal_ContextList[2] =
{
EbmlSemantic(false, false, EBML_INFO(EbmlCrc32)), ///< EbmlCrc32
EbmlSemantic(false, false, EBML_INFO(EbmlVoid)), ///< EbmlVoid
};

const EbmlSemanticContext Context_EbmlGlobal = EbmlSemanticContext(0, nullptr, nullptr, GetEbmlGlobal_Context, nullptr);
DEFINE_START_SEMANTIC(EbmlGlobal)
DEFINE_SEMANTIC_ITEM(false, false, EbmlCrc32)
DEFINE_SEMANTIC_ITEM(false, false, EbmlVoid)
DEFINE_END_SEMANTIC(EbmlGlobal)

static const EbmlSemanticContext EbmlGlobal_Context = EbmlSemanticContext(countof(EbmlGlobal_ContextList), EbmlGlobal_ContextList, nullptr, GetEbmlGlobal_Context, nullptr);
static DEFINE_xxx_CONTEXT(EbmlGlobal, GetEbmlGlobal_Context)

const EbmlSemanticContext & GetEbmlGlobal_Context()
{
return EbmlGlobal_Context;
return Context_EbmlGlobal;
}

} // namespace libebml
10 changes: 9 additions & 1 deletion src/EbmlHead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

namespace libebml {

DEFINE_EBML_UINTEGER_DEF(EVersion, 0x4286, 2, EbmlHead, "EBMLVersion", 1)
DEFINE_EBML_UINTEGER_DEF(EReadVersion, 0x42F7, 2, EbmlHead, "EBMLReadVersion", 1)
DEFINE_EBML_UINTEGER_DEF(EMaxIdLength, 0x42F2, 2, EbmlHead, "EBMLMaxIdLength", 4)
DEFINE_EBML_UINTEGER_DEF(EMaxSizeLength, 0x42F3, 2, EbmlHead, "EBMLMaxSizeLength", 8)
DEFINE_EBML_STRING_DEF (EDocType, 0x4282, 2, EbmlHead, "EBMLDocType", "matroska")
DEFINE_EBML_UINTEGER_DEF(EDocTypeVersion, 0x4287, 2, EbmlHead, "EBMLDocTypeVersion", 1)
DEFINE_EBML_UINTEGER_DEF(EDocTypeReadVersion, 0x4285, 2, EbmlHead, "EBMLDocTypeReadVersion", 1)

DEFINE_START_SEMANTIC(EbmlHead)
DEFINE_SEMANTIC_ITEM(true, true, EVersion) ///< EBMLVersion
DEFINE_SEMANTIC_ITEM(true, true, EReadVersion) ///< EBMLReadVersion
Expand All @@ -24,7 +32,7 @@ DEFINE_END_SEMANTIC(EbmlHead)
DEFINE_EBML_MASTER_ORPHAN(EbmlHead, 0x1A45DFA3, 4, false, "EBMLHead\0ratamapaga")

EbmlHead::EbmlHead()
:EbmlMaster(EbmlHead::ClassInfos, EbmlHead_Context)
:EbmlMaster(EbmlHead::ClassInfos, Context_EbmlHead)
{}

} // namespace libebml
21 changes: 0 additions & 21 deletions src/EbmlSubHead.cpp

This file was deleted.