mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[base-typemaps.i] add VECTOR_HELPER_INOUT for Split* and Account*
efficiently convert std::vector<Obj> to/from guile list of objects
This commit is contained in:
parent
0f791c474a
commit
cb7196a393
@ -73,6 +73,8 @@ GLIST_HELPER_INOUT(AccountList, SWIGTYPE_p_Account);
|
|||||||
GLIST_HELPER_INOUT(PriceList, SWIGTYPE_p_GNCPrice);
|
GLIST_HELPER_INOUT(PriceList, SWIGTYPE_p_GNCPrice);
|
||||||
// TODO: free PriceList?
|
// TODO: free PriceList?
|
||||||
GLIST_HELPER_INOUT(CommodityList, SWIGTYPE_p_gnc_commodity);
|
GLIST_HELPER_INOUT(CommodityList, SWIGTYPE_p_gnc_commodity);
|
||||||
|
VECTOR_HELPER_INOUT(SplitsVec, SWIGTYPE_p_Split, Split);
|
||||||
|
VECTOR_HELPER_INOUT(AccountVec, SWIGTYPE_p_Account, Account);
|
||||||
|
|
||||||
%typemap(newfree) char * "g_free($1);"
|
%typemap(newfree) char * "g_free($1);"
|
||||||
|
|
||||||
|
@ -162,6 +162,29 @@ typedef char gchar;
|
|||||||
$result = scm_reverse(list);
|
$result = scm_reverse(list);
|
||||||
}
|
}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
|
%define VECTOR_HELPER_INOUT(VectorType, ElemSwigType, ElemType)
|
||||||
|
%typemap(in) VectorType {
|
||||||
|
std::vector<ElemType*> accum;
|
||||||
|
for (auto node = $input; !scm_is_null (node); node = scm_cdr (node))
|
||||||
|
{
|
||||||
|
auto p_scm = scm_car (node);
|
||||||
|
auto p = (scm_is_false (p_scm) || scm_is_null (p_scm)) ? static_cast<ElemType*>(nullptr) :
|
||||||
|
static_cast<ElemType*>(SWIG_MustGetPtr(p_scm, ElemSwigType, 1, 0));
|
||||||
|
accum.push_back (p);
|
||||||
|
}
|
||||||
|
accum.swap ($1);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) VectorType {
|
||||||
|
SCM list = SCM_EOL;
|
||||||
|
std::for_each ($1.rbegin(), $1.rend(), [&list](auto n)
|
||||||
|
{ list = scm_cons(SWIG_NewPointerObj(n, ElemSwigType, 0), list); });
|
||||||
|
$result = list;
|
||||||
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
#elif defined(SWIGPYTHON) /* Typemaps for Python */
|
#elif defined(SWIGPYTHON) /* Typemaps for Python */
|
||||||
|
|
||||||
%import "glib.h"
|
%import "glib.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user