From 3aa86ca9925b85ea9316a54c6e2e64e35c4f0708 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 2 Mar 2021 14:15:43 -0800 Subject: [PATCH] QofInstance* needs a typemap to match the from/to SCM logic. --- libgnucash/app-utils/gnc-optiondb.i | 51 ++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/libgnucash/app-utils/gnc-optiondb.i b/libgnucash/app-utils/gnc-optiondb.i index 20aa66e0cc..64773857f5 100644 --- a/libgnucash/app-utils/gnc-optiondb.i +++ b/libgnucash/app-utils/gnc-optiondb.i @@ -59,6 +59,55 @@ SCM scm_init_sw_gnc_optiondb_module(void); * resolution is more strict so the overload prefers the exact decltype(value) * to implicit conversion candidates. */ + +%typemap (out) QofInstance_s* { + if ($1 == nullptr) + { + $result = SCM_BOOL_F; + } + else + { + + auto ptr{static_cast(const_cast($1))}; + swig_type_info *type = SWIGTYPE_p_QofInstance_s; + if (GNC_IS_COMMODITY($1)) + type = SWIGTYPE_p_gnc_commodity; + else if (GNC_IS_ACCOUNT($1)) + type = SWIGTYPE_p_Account; + else if (GNC_IS_BUDGET($1)) + type = SWIGTYPE_p_GncBudget; + else if (GNC_IS_INVOICE($1)) + type = SWIGTYPE_p_GncInvoice; + else if (GNC_IS_TAXTABLE($1)) + type = SWIGTYPE_p_GncTaxTable; + $result = SWIG_NewPointerObj(ptr, type, FALSE); + } +} + +%typemap (in) QofInstance_s* { + if (scm_is_true($input)) + { + static const std::array types { + SWIGTYPE_p_QofInstance_s, SWIGTYPE_p_gnc_commodity, + SWIGTYPE_p_GncBudget, SWIGTYPE_p_GncInvoice, + SWIGTYPE_p_GncTaxTable, SWIGTYPE_p_Account + }; + void* ptr{}; + auto pos = std::find_if(types.begin(), types.end(), + [&$input, &ptr](auto type){ + SWIG_ConvertPtr($input, &ptr, type, 0); + return ptr != nullptr; }); + if (pos == types.end()) + $1 = nullptr; + else + $1 = static_cast(ptr); + } + else + { + $1 = nullptr; + } + } + %inline %{ template inline SCM scm_from_value(ValueType value); @@ -184,7 +233,7 @@ scm_to_value(SCM new_value) if (new_value == SCM_BOOL_F) return nullptr; - static const std::array types{ + static const std::array types{ SWIGTYPE_p_QofInstance_s, SWIGTYPE_p_gnc_commodity, SWIGTYPE_p_GncBudget, SWIGTYPE_p_GncInvoice, SWIGTYPE_p_GncTaxTable, SWIGTYPE_p_Account