Skip to content

Commit

Permalink
make GetSemantic() constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
robUx4 committed Mar 3, 2024
1 parent f61ef13 commit f288c5f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
9 changes: 8 additions & 1 deletion 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,7 +527,13 @@ 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
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

0 comments on commit f288c5f

Please sign in to comment.