Skip to content

Commit

Permalink
turn "pure" EBML macros into static inline
Browse files Browse the repository at this point in the history
So we have stronger typing and a better sense of the input type.

Put the "macros" right after the input type declaration they are associated with.
  • Loading branch information
robUx4 committed Feb 24, 2024
1 parent b7db848 commit 7436d75
Showing 1 changed file with 62 additions and 13 deletions.
75 changes: 62 additions & 13 deletions ebml/EbmlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,22 +244,9 @@ class DllApi x : public BaseClass { \
#define EBML_ID(ref) ref::ClassId()
#define EBML_CLASS_SEMCONTEXT(ref) Context_##ref
#define EBML_CLASS_CONTEXT(ref) EBML_INFO_CONTEXT(EBML_INFO(ref))
#define EBML_CONTEXT(e) (e)->Context()
#define EBML_NAME(e) (e)->DebugName()

#define EBML_INFO_ID(cb) (cb).ClassId()
#define EBML_INFO_NAME(cb) (cb).GetName()
#define EBML_INFO_CREATE(cb) (cb).NewElement()
#define EBML_INFO_CONTEXT(cb) (cb).GetContext()

#define EBML_SEM_SPECS(s) (s).GetCallbacks()
#define EBML_SEM_CONTEXT(s) EBML_INFO_CONTEXT(EBML_SEM_SPECS(s))
#define EBML_SEM_CREATE(s) (s).Create()

#define EBML_CTX_SIZE(c) (c).GetSize()
#define EBML_CTX_MASTER(c) (c).GetMaster()
#define EBML_CTX_PARENT(c) (c).Parent()
#define EBML_CTX_IDX(c,i) (c).GetSemantic(i)
#define EBML_CTX_IDX_INFO(c,i) EBML_SEM_SPECS(EBML_CTX_IDX(c,i))
#define EBML_CTX_IDX_ID(c,i) EBML_INFO_ID(EBML_CTX_IDX_INFO(c,i))

Expand Down Expand Up @@ -378,6 +365,26 @@ class EBML_DLL_API EbmlCallbacksWithDefault : public EbmlCallbacksDefault<T> {
const T defaultValue;
};

static inline constexpr const EbmlId & EBML_INFO_ID(const EbmlCallbacks & cb)
{
return cb.ClassId();
}

static inline constexpr const char * EBML_INFO_NAME(const EbmlCallbacks & cb)
{
return cb.GetName();
}

static inline EbmlElement & EBML_INFO_CREATE(const EbmlCallbacks & cb)
{
return cb.NewElement();
}

static inline constexpr const EbmlSemanticContext & EBML_INFO_CONTEXT(const EbmlCallbacks & cb)
{
return cb.GetContext();
}

/*!
\brief contains the semantic informations for a given level and all sublevels
\todo move the ID in the element class
Expand All @@ -399,6 +406,16 @@ class EBML_DLL_API EbmlSemantic {
const EbmlCallbacks & Callbacks;
};

static inline constexpr const EbmlCallbacks & EBML_SEM_SPECS(const EbmlSemantic & s)
{
return s.GetCallbacks();
}

static inline EbmlElement & EBML_SEM_CREATE(const EbmlSemantic & s)
{
return s.Create();
}

using _GetSemanticContext = const class EbmlSemanticContext &(*)();

/*!
Expand Down Expand Up @@ -436,6 +453,26 @@ class EBML_DLL_API EbmlSemanticContext {
const EbmlCallbacks *MasterElt;
};

static inline constexpr size_t EBML_CTX_SIZE(const EbmlSemanticContext & c)
{
return c.GetSize();
}

static inline constexpr const EbmlCallbacks * EBML_CTX_MASTER(const EbmlSemanticContext & c)
{
return c.GetMaster();
}

static inline constexpr const EbmlSemanticContext * EBML_CTX_PARENT(const EbmlSemanticContext & c)
{
return c.Parent();
}

static inline const EbmlSemantic & EBML_CTX_IDX(const EbmlSemanticContext & c, std::size_t i)
{
return c.GetSemantic(i);
}

/*!
\class EbmlElement
\brief Hold basic informations about an EBML element (ID + length)
Expand Down Expand Up @@ -701,6 +738,18 @@ class EBML_DLL_API EbmlElementDefaultStorage : public EbmlElementDefault<T> {
S Value;
};


static inline constexpr const EbmlSemanticContext & EBML_CONTEXT(const EbmlElement * e)
{
return e->Context();
}

static inline constexpr const char * EBML_NAME(const EbmlElement * e)
{
return e->DebugName();
}


} // namespace libebml

#define EBML_WRITE_FILTER 1
Expand Down

0 comments on commit 7436d75

Please sign in to comment.