Make gnc_register_number_range_option a template on ValueType.

GtkSpinButton works with doubles, but we want to preserve the
ability to use other types.
It really should have enable_if<is_arithmetic(ValueType)>.
This commit is contained in:
John Ralls 2020-04-04 14:34:45 -07:00
parent e78c012699
commit 3514725a97
2 changed files with 23 additions and 10 deletions

View File

@ -853,14 +853,15 @@ gnc_register_list_option(GncOptionDB* db, const char* section,
/* Only balance-forecast.scm, hello-world.scm, and net-charts.scm
* use decimals and fractional steps and they can be worked around.
*/
void
template <typename ValueType> void
gnc_register_number_range_option(GncOptionDB* db, const char* section,
const char* name, const char* key,
const char* doc_string, int value, int min,
int max, int step)
const char* doc_string, ValueType value,
ValueType min, ValueType max, ValueType step)
{
GncOption option{GncOptionRangeValue<int>{section, name, key, doc_string,
value, min, max, step}};
GncOption option{GncOptionRangeValue<ValueType>{section, name, key,
doc_string, value, min,
max, step}};
db->register_option(section, std::move(option));
}
@ -928,10 +929,10 @@ gnc_register_taxtable_option(GncOptionDB* db, const char* section,
void
gnc_register_counter_option(GncOptionDB* db, const char* section,
const char* name, const char* key,
const char* doc_string, int value)
const char* doc_string, double value)
{
GncOption option{GncOptionRangeValue<int>{section, name, key, doc_string,
value, 0, 999999999, 1}};
GncOption option{GncOptionRangeValue<double>{section, name, key, doc_string,
value, 0.0, 999999999.0, 1.0}};
db->register_option(section, std::move(option));
}
@ -1312,3 +1313,13 @@ gnc_option_db_set_glist_value(GncOptionDB*, const char*, const char*, GList*)
{
}
// Force creation of templates
template void gnc_register_number_range_option(GncOptionDB* db,
const char* section, const char* name,
const char* key, const char* doc_string,
int value, int min, int max, int step);
template void gnc_register_number_range_option(GncOptionDB* db,
const char* section, const char* name,
const char* key, const char* doc_string,
double value, double min,
double max, double step);

View File

@ -138,10 +138,12 @@ void gnc_register_list_option(GncOptionDB* db, const char* section,
const char* doc_string, const char* value,
GncMultichoiceOptionChoices&& list);
template <typename ValueType>
void gnc_register_number_range_option(GncOptionDB* db,
const char* section, const char* name,
const char* key, const char* doc_string,
int value, int min, int max, int step);
ValueType value, ValueType min,
ValueType max, ValueType step);
void gnc_register_number_plot_size_option(GncOptionDB* db,
const char* section, const char* name,
@ -180,7 +182,7 @@ void gnc_register_taxtable_option(GncOptionDB* db, const char* section,
void gnc_register_counter_option(GncOptionDB* db, const char* section,
const char* name, const char* key,
const char* doc_string, int value);
const char* doc_string, double value);
void gnc_register_counter_format_option(GncOptionDB* db,
const char* section, const char* name,