From 9cdcaf0da876dca96630f6e025bdb77843607d29 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 12 Oct 2019 18:14:22 -0700 Subject: [PATCH] Remove GncOptionDB::set_selectable and convert set_option to a template. --- libgnucash/app-utils/gnc-optiondb.cpp | 11 ----------- libgnucash/app-utils/gnc-optiondb.hpp | 21 +++++++++++++++++++-- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/libgnucash/app-utils/gnc-optiondb.cpp b/libgnucash/app-utils/gnc-optiondb.cpp index 3dde5739e1..80fb768919 100644 --- a/libgnucash/app-utils/gnc-optiondb.cpp +++ b/libgnucash/app-utils/gnc-optiondb.cpp @@ -174,17 +174,6 @@ GncOptionDB::lookup_string_option(const char* section, const char* name) return db_opt->get_value(); } -bool -GncOptionDB::set_option(const char* section, const char* name, SCM value) -{ - return false; -} - -void -GncOptionDB::set_selectable(const char* section, const char* name) -{ -} - void GncOptionDB::make_internal(const char* section, const char* name) { diff --git a/libgnucash/app-utils/gnc-optiondb.hpp b/libgnucash/app-utils/gnc-optiondb.hpp index bf0cdade37..abc783e055 100644 --- a/libgnucash/app-utils/gnc-optiondb.hpp +++ b/libgnucash/app-utils/gnc-optiondb.hpp @@ -26,6 +26,7 @@ #include "gnc-option.hpp" #include +#include #include extern "C" { @@ -62,8 +63,24 @@ public: SCM lookup_option(const char* section, const char* name); std::string lookup_string_option(const char* section, const char* name); - bool set_option(const char* section, const char* name, SCM value); - void set_selectable(const char* section, const char* name); + template + bool set_option(const char* section, const char* name, ValueType value) + { + try + { + auto option{find_option(section, name)}; + if (!option) + return false; + option->set_value(value); + return true; + } + catch(const std::invalid_argument& err) + { + printf("Set Failed: %s\n", err.what()); + return false; + } + } +// void set_selectable(const char* section, const char* name); void make_internal(const char* section, const char* name); void commit(); private: