Compile time check preflight returns no tec (RIPD-1624):

The six different ranges of TER codes are broken up into six
different enumerations.  A template class allows subsets of
these enumerations to be aggregated.  This technique allows
verification at compile time that no TEC codes are returned
before the signature is checked.

Conversion between TER instance and integer is provided by
named functions.  This makes accidental conversion almost
impossible and makes type abuse easier to spot in the code
base.
This commit is contained in:
Scott Schurr
2018-04-16 17:51:36 -07:00
committed by seelabs
parent 7d163a45dc
commit 118c25c0f0
54 changed files with 612 additions and 161 deletions

View File

@@ -28,13 +28,13 @@ namespace detail {
static
std::unordered_map<
std::underlying_type_t<TER>,
TERUnderlyingType,
std::pair<char const* const, char const* const>> const&
transResults()
{
static
std::unordered_map<
std::underlying_type_t<TER>,
TERUnderlyingType,
std::pair<char const* const, char const* const>> const
results
{
@@ -162,8 +162,7 @@ bool transResultInfo (TER code, std::string& token, std::string& text)
{
auto& results = detail::transResults();
auto const r = results.find (
static_cast<std::underlying_type_t<TER>> (code));
auto const r = results.find (TERtoInt (code));
if (r == results.end())
return false;
@@ -207,7 +206,7 @@ transCode(std::string const& token)
);
std::unordered_map<
std::string,
std::underlying_type_t<TER>> const
TERUnderlyingType> const
byToken(tRange.begin(), tRange.end());
return byToken;
}();
@@ -217,7 +216,7 @@ transCode(std::string const& token)
if (r == results.end())
return boost::none;
return static_cast<TER>(r->second);
return TER::fromInt (r->second);
}
} // ripple