mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
Replace the direct wrapping of GncOptionDB-set-option-string-foo.
With a simple type-free function gnc_option_set. This mirrors the current (gnc:option-set(gnc:lookup-option... and takes care of SCM type conversion.
This commit is contained in:
parent
252ba9b477
commit
2f2ac99944
@ -540,9 +540,9 @@ public:
|
|||||||
option.make_internal();
|
option.make_internal();
|
||||||
}, m_option);
|
}, m_option);
|
||||||
}
|
}
|
||||||
const GncOptionVariant& _get_option() const { return m_option; }
|
GncOptionVariant& _get_option() const { return m_option; }
|
||||||
private:
|
private:
|
||||||
GncOptionVariant m_option;
|
mutable GncOptionVariant m_option;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //GNC_OPTION_HPP_
|
#endif //GNC_OPTION_HPP_
|
||||||
|
@ -100,6 +100,7 @@ scm_from_value<const QofInstance*>(const QofInstance* value)
|
|||||||
return scm_guid;
|
return scm_guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Not needed now, the default template will do this
|
/* Not needed now, the default template will do this
|
||||||
template <> inline SCM
|
template <> inline SCM
|
||||||
scm_from_value<QofQuer*>(const QofQuery* value)
|
scm_from_value<QofQuer*>(const QofQuery* value)
|
||||||
@ -129,6 +130,44 @@ template <>inline SCM
|
|||||||
return SCM_BOOL_F;
|
return SCM_BOOL_F;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
template <typename ValueType> inline ValueType
|
||||||
|
scm_to_value(SCM new_value)
|
||||||
|
{
|
||||||
|
return ValueType{};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> inline std::string
|
||||||
|
scm_to_value<std::string>(SCM new_value)
|
||||||
|
{
|
||||||
|
auto strval = scm_to_utf8_stringn(new_value, nullptr);
|
||||||
|
std::string retval{strval};
|
||||||
|
free(strval);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
template <> inline std::string
|
||||||
|
scm_to_value<char*>(SCM new_value)
|
||||||
|
{
|
||||||
|
auto strval = scm_to_utf8_stringn(new_value, nullptr);
|
||||||
|
std::string retval{strval};
|
||||||
|
free(strval);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
template <> inline int
|
||||||
|
scm_to_value<int>(SCM new_value)
|
||||||
|
{
|
||||||
|
return scm_to_int(new_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> inline int64_t
|
||||||
|
scm_to_value<int64_t>(SCM new_value)
|
||||||
|
{
|
||||||
|
return scm_to_int64(new_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
%}
|
%}
|
||||||
%ignore OptionClassifier;
|
%ignore OptionClassifier;
|
||||||
%ignore OptionUIItem;
|
%ignore OptionUIItem;
|
||||||
@ -177,6 +216,12 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
|
|||||||
return scm_from_value(static_cast<decltype(value)>(value));
|
return scm_from_value(static_cast<decltype(value)>(value));
|
||||||
}, $self->_get_option());
|
}, $self->_get_option());
|
||||||
}
|
}
|
||||||
|
void set_value_from_scm(SCM new_value)
|
||||||
|
{
|
||||||
|
std::visit([new_value](auto& option) {
|
||||||
|
option.set_value(scm_to_value<std::decay_t<decltype(option.get_value())>>(new_value));
|
||||||
|
}, $self->_get_option());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
%extend GncOptionDB {
|
%extend GncOptionDB {
|
||||||
@ -195,6 +240,17 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
|
|||||||
return GncOption_get_scm_value(&(db_opt->get()));
|
return GncOption_get_scm_value(&(db_opt->get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gnc_set_option(const GncOptionDBPtr& optiondb, const char* section,
|
||||||
|
const char* name, SCM new_value)
|
||||||
|
{
|
||||||
|
auto db_opt = optiondb->find_option(section, name);
|
||||||
|
if (!db_opt)
|
||||||
|
{
|
||||||
|
// PWARN("Attempt to write non-existent option %s/%s", section, name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GncOption_set_value_from_scm(&(db_opt->get()), new_value);
|
||||||
|
}
|
||||||
%}
|
%}
|
||||||
/*
|
/*
|
||||||
TEST(GncOption, test_string_scm_functions)
|
TEST(GncOption, test_string_scm_functions)
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
"Phony Option" "waldo")))
|
"Phony Option" "waldo")))
|
||||||
(test-equal "waldo" (gnc-option-value 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")
|
(gnc-set-option option-db "foo" "bar" "pepper")
|
||||||
(test-equal "pepper" (gnc-option-value option-db "foo" "bar")))
|
(test-equal "pepper" (gnc-option-value option-db "foo" "bar")))
|
||||||
(test-end "test-gnc-make-string-option"))
|
(test-end "test-gnc-make-string-option"))
|
||||||
|
|
||||||
@ -76,8 +76,7 @@
|
|||||||
(multi-opt (gnc-register-multichoice-option option-db "foo" "bar" "baz"
|
(multi-opt (gnc-register-multichoice-option option-db "foo" "bar" "baz"
|
||||||
"Phony Option" multichoice)))
|
"Phony Option" multichoice)))
|
||||||
|
|
||||||
(GncOptionDB-set-option-string
|
(gnc-set-option option-db "foo" "bar" "corge")
|
||||||
(GncOptionDBPtr-get option-db) "foo" "bar" "corge")
|
|
||||||
(test-equal "corge" (gnc-option-value option-db "foo" "bar")))
|
(test-equal "corge" (gnc-option-value option-db "foo" "bar")))
|
||||||
(test-end "test-gnc-test-multichoice-option"))
|
(test-end "test-gnc-test-multichoice-option"))
|
||||||
|
|
||||||
@ -88,7 +87,7 @@
|
|||||||
"baz" "Phony Option"))
|
"baz" "Phony Option"))
|
||||||
(a-time (gnc-dmy2time64 11 07 2019)))
|
(a-time (gnc-dmy2time64 11 07 2019)))
|
||||||
(test-equal (current-time) (gnc-option-value 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)
|
(gnc-set-option option-db "foo" "bar" a-time)
|
||||||
(test-equal a-time (gnc-option-value option-db "foo" "bar"))
|
(test-equal a-time (gnc-option-value option-db "foo" "bar"))
|
||||||
(test-end "test-gnc-test-date-option")))
|
(test-end "test-gnc-test-date-option")))
|
||||||
|
|
||||||
@ -99,6 +98,6 @@
|
|||||||
"baz" "Phony Option"
|
"baz" "Phony Option"
|
||||||
15 5 30 1)))
|
15 5 30 1)))
|
||||||
(test-equal 15 (gnc-option-value 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)
|
(gnc-set-option option-db "foo" "bar" 20)
|
||||||
(test-equal 20 (gnc-option-value option-db "foo" "bar")))
|
(test-equal 20 (gnc-option-value option-db "foo" "bar")))
|
||||||
(test-end "test-gnc-number-range-option"))
|
(test-end "test-gnc-number-range-option"))
|
||||||
|
Loading…
Reference in New Issue
Block a user