Add opcode flag: permissive bounds
This commit is contained in:
parent
d4bbe806be
commit
8672a5b5f7
2 changed files with 23 additions and 14 deletions
|
|
@ -51,11 +51,12 @@ enum OpcodeFlags : int {
|
|||
kEnforceLowerBound = 1 << 1,
|
||||
kEnforceUpperBound = 1 << 2,
|
||||
kEnforceBounds = kEnforceLowerBound|kEnforceUpperBound,
|
||||
kNormalizePercent = 1 << 3,
|
||||
kNormalizeMidi = 1 << 4,
|
||||
kNormalizeBend = 1 << 5,
|
||||
kWrapPhase = 1 << 6,
|
||||
kDb2Mag = 1 << 7,
|
||||
kPermissiveBounds = 1 << 3,
|
||||
kNormalizePercent = 1 << 4,
|
||||
kNormalizeMidi = 1 << 5,
|
||||
kNormalizeBend = 1 << 6,
|
||||
kWrapPhase = 1 << 7,
|
||||
kDb2Mag = 1 << 8,
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include "absl/strings/ascii.h"
|
||||
#include "absl/strings/match.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include <limits>
|
||||
#include <iostream>
|
||||
#include <cctype>
|
||||
#include <cassert>
|
||||
|
|
@ -144,6 +145,8 @@ OpcodeCategory Opcode::identifyCategory(absl::string_view name)
|
|||
template <typename T>
|
||||
absl::optional<T> readInt_(OpcodeSpec<T> spec, absl::string_view v)
|
||||
{
|
||||
using Limits = std::numeric_limits<T>;
|
||||
|
||||
size_t numberEnd = 0;
|
||||
|
||||
if (numberEnd < v.size() && (v[numberEnd] == '+' || v[numberEnd] == '-'))
|
||||
|
|
@ -164,15 +167,18 @@ absl::optional<T> readInt_(OpcodeSpec<T> spec, absl::string_view v)
|
|||
if (returnedValue > static_cast<int64_t>(spec.bounds.getEnd())) {
|
||||
if (spec.flags & kEnforceUpperBound)
|
||||
return spec.bounds.getEnd();
|
||||
|
||||
return absl::nullopt;
|
||||
else if (!(spec.flags & kPermissiveBounds))
|
||||
return absl::nullopt;
|
||||
} else if (returnedValue < static_cast<int64_t>(spec.bounds.getStart())) {
|
||||
if (spec.flags & kEnforceLowerBound)
|
||||
return spec.bounds.getStart();
|
||||
|
||||
return absl::nullopt;
|
||||
else if (!(spec.flags & kPermissiveBounds))
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
returnedValue = std::max<int64_t>(returnedValue, Limits::min());
|
||||
returnedValue = std::min<int64_t>(returnedValue, Limits::max());
|
||||
|
||||
return static_cast<T>(returnedValue);
|
||||
}
|
||||
|
||||
|
|
@ -219,16 +225,18 @@ absl::optional<T> readFloat_(OpcodeSpec<T> spec, absl::string_view v)
|
|||
else if (returnedValue > static_cast<int64_t>(spec.bounds.getEnd())) {
|
||||
if (spec.flags & kEnforceUpperBound)
|
||||
return spec.bounds.getEnd();
|
||||
|
||||
return absl::nullopt;
|
||||
else if (!(spec.flags & kPermissiveBounds))
|
||||
return absl::nullopt;
|
||||
} else if (returnedValue < static_cast<int64_t>(spec.bounds.getStart())) {
|
||||
if (spec.flags & kEnforceLowerBound)
|
||||
return spec.bounds.getStart();
|
||||
|
||||
return absl::nullopt;
|
||||
else if (!(spec.flags & kPermissiveBounds))
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
return spec.normalizeInput(returnedValue);
|
||||
returnedValue = spec.normalizeInput(returnedValue);
|
||||
|
||||
return returnedValue;
|
||||
}
|
||||
|
||||
#define INSTANTIATE_FOR_FLOATING_POINT(T) \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue