Change GncOptionDB::lookup_option to gnc_option_value().

The old gnc:lookup-option returned the option object so that it could be
manipulated rather than getting its value; gnc_option_value replicates
the behavior of (gnc:option-value (gnc:lookup-option)).
This commit is contained in:
John Ralls 2019-11-01 14:59:49 -07:00
parent ff7b263a5f
commit 252ba9b477
2 changed files with 17 additions and 22 deletions

View File

@ -180,20 +180,22 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
};
%extend GncOptionDB {
SCM lookup_option(const char* section, const char* name)
{
auto db_opt = $self->find_option(section, name);
if (!db_opt)
return SCM_BOOL_F;
return GncOption_get_scm_value(&(db_opt->get()));
}
%template(set_option_string) set_option<std::string>;
%template(set_option_int) set_option<int>;
%template(set_option_time64) set_option<time64>;
};
%inline %{
SCM gnc_option_value(const GncOptionDBPtr& optiondb, const char* section,
const char* name)
{
auto db_opt = optiondb->find_option(section, name);
if (!db_opt)
return SCM_BOOL_F;
return GncOption_get_scm_value(&(db_opt->get()));
}
%}
/*
TEST(GncOption, test_string_scm_functions)
{

View File

@ -45,12 +45,10 @@
(let* ((option-db (gnc-option-db-new))
(string-opt (gnc-register-string-option option-db "foo" "bar" "baz"
"Phony Option" "waldo")))
(test-equal "waldo" (GncOptionDB-lookup-option
(GncOptionDBPtr-get option-db) "foo" "bar"))
(test-equal "waldo" (gnc-option-value option-db "foo" "bar"))
(GncOptionDB-set-option-string (GncOptionDBPtr-get option-db) "foo" "bar" "pepper")
(test-equal "pepper" (GncOptionDB-lookup-option
(GncOptionDBPtr-get option-db) "foo" "bar")))
(test-equal "pepper" (gnc-option-value option-db "foo" "bar")))
(test-end "test-gnc-make-string-option"))
(define (test-gnc-make-multichoice-option)
@ -80,8 +78,7 @@
(GncOptionDB-set-option-string
(GncOptionDBPtr-get option-db) "foo" "bar" "corge")
(test-equal "corge" (GncOptionDB-lookup-option
(GncOptionDBPtr-get option-db) "foo" "bar")))
(test-equal "corge" (gnc-option-value option-db "foo" "bar")))
(test-end "test-gnc-test-multichoice-option"))
(define (test-gnc-make-date-option)
@ -90,11 +87,9 @@
(date-opt (gnc-register-date-interval-option option-db "foo" "bar"
"baz" "Phony Option"))
(a-time (gnc-dmy2time64 11 07 2019)))
(test-equal (current-time) (GncOptionDB-lookup-option
(GncOptionDBPtr-get option-db) "foo" "bar"))
(test-equal (current-time) (gnc-option-value option-db "foo" "bar"))
(GncOptionDB-set-option-time64 (GncOptionDBPtr-get option-db) "foo" "bar" a-time)
(test-equal a-time (GncOptionDB-lookup-option
(GncOptionDBPtr-get option-db) "foo" "bar"))
(test-equal a-time (gnc-option-value option-db "foo" "bar"))
(test-end "test-gnc-test-date-option")))
(define (test-gnc-make-number-range-option)
@ -103,9 +98,7 @@
(number-opt (gnc-register-number-range-option option-db "foo" "bar"
"baz" "Phony Option"
15 5 30 1)))
(test-equal 15 (GncOptionDB-lookup-option
(GncOptionDBPtr-get option-db) "foo" "bar"))
(test-equal 15 (gnc-option-value option-db "foo" "bar"))
(GncOptionDB-set-option-int (GncOptionDBPtr-get option-db) "foo" "bar" 20)
(test-equal 20 (GncOptionDB-lookup-option
(GncOptionDBPtr-get option-db) "foo" "bar")))
(test-equal 20 (gnc-option-value option-db "foo" "bar")))
(test-end "test-gnc-number-range-option"))