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

Make GetSemantic(i) return a constexpr #266

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
11 changes: 9 additions & 2 deletions ebml/EbmlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <string>
#include <limits>
#include <cstddef>
#include <stdexcept>

namespace libebml {

Expand Down Expand Up @@ -526,13 +527,19 @@ class EBML_DLL_API EbmlSemanticContextMaster : public EbmlSemanticContext {
return false;
}

const EbmlSemantic & GetSemantic(std::size_t i) const;
inline constexpr const EbmlSemantic & GetSemantic(std::size_t i) const
{
if (i<GetSize())
return MyTable[i];

throw std::logic_error("EbmlSemanticContext::GetSemantic: programming error: index outside of table size");
}

private:
const EbmlSemantic *MyTable; ///< First element in the table
};

static inline const EbmlSemantic & tEBML_CTX_IDX(const EbmlSemanticContextMaster & c, std::size_t i)
static inline constexpr const EbmlSemantic & tEBML_CTX_IDX(const EbmlSemanticContextMaster & c, std::size_t i)
{
return c.GetSemantic(i);
}
Expand Down
12 changes: 0 additions & 12 deletions src/EbmlMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ EbmlMaster::~EbmlMaster()
}
}

const EbmlSemantic & EbmlSemanticContextMaster::GetSemantic(std::size_t i) const
{
assert(i<GetSize());
if (i<GetSize())
return MyTable[i];

std::stringstream ss;
ss << "EbmlSemanticContext::GetSemantic: programming error: index i outside of table size (" << i << " >= " << GetSize() << ")";
throw std::logic_error(ss.str());
}


/*!
\todo handle exception on errors
\todo write all the Mandatory elements in the Context, otherwise assert
Expand Down
Loading