[apps/shared] Templatize FloatParameterController to handle float/double

parameters.

Fix bug: when entering "e^234" as a parameter of a model keeping floats,
the FloatParameterController would accept the number (because e^234 is
defined in double) and store an undefined value in the model (because
e^234 is undefined in float).
This commit is contained in:
Émilie Feral
2019-09-02 11:48:43 +02:00
parent 77304040ad
commit 6de497c2ed
18 changed files with 71 additions and 45 deletions

View File

@@ -40,8 +40,9 @@ bool TextFieldDelegateApp::isAcceptableText(const char * text) {
return isAcceptable;
}
bool TextFieldDelegateApp::hasUndefinedValue(const char * text, double & value) {
value = PoincareHelpers::ApproximateToScalar<double>(text, localContext());
template<typename T>
bool TextFieldDelegateApp::hasUndefinedValue(const char * text, T & value) {
value = PoincareHelpers::ApproximateToScalar<T>(text, localContext());
bool isUndefined = std::isnan(value) || std::isinf(value);
if (isUndefined) {
displayWarning(I18n::Message::UndefinedValue);
@@ -115,4 +116,7 @@ bool TextFieldDelegateApp::ExpressionCanBeSerialized(const Expression expression
return true;
}
template bool TextFieldDelegateApp::hasUndefinedValue(const char * text, float & value);
template bool TextFieldDelegateApp::hasUndefinedValue(const char * text, double & value);
}