"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "bindings/guile/gnc-optiondb.i" between
gnucash-5.0.tar.bz2 and gnucash-5.1.tar.bz2

About: GnuCash is personal and small-business financial-accounting software.

gnc-optiondb.i  (gnucash-5.0.tar.bz2):gnc-optiondb.i  (gnucash-5.1.tar.bz2)
skipping to change at line 415 skipping to change at line 415
template <> inline gnc_commodity* template <> inline gnc_commodity*
scm_to_value<gnc_commodity*>(SCM new_value) scm_to_value<gnc_commodity*>(SCM new_value)
{ {
auto comm{scm_to_value<const QofInstance*>(new_value)}; auto comm{scm_to_value<const QofInstance*>(new_value)};
if (comm) if (comm)
return GNC_COMMODITY(comm); return GNC_COMMODITY(comm);
if (scm_is_list(new_value)) if (scm_is_list(new_value))
{ {
auto len{scm_to_uint(scm_length(new_value))}; auto len{scm_to_uint(scm_length(new_value))};
std::string mnemonic{scm_to_utf8_string(scm_list_ref(new_value, auto mnemonic{scm_to_utf8_string(scm_list_ref(new_value, scm_from_uint(0
scm_from_uint(0)))}; )))};
std::string name_space{"CURRENCY"}; auto name_space{(len > 1) ? scm_to_utf8_string(scm_list_ref(new_value,
if (len > 1) scm_from_uin
name_space = scm_to_utf8_string(scm_list_ref(new_value, t(1)))
scm_from_uint(1))); : strdup ("CURRENCY")};
auto book{get_current_book()}; auto book{get_current_book()};
auto table = gnc_commodity_table_get_table(book); auto table = gnc_commodity_table_get_table(book);
return gnc_commodity_table_lookup(table, name_space.c_str(), auto rv = gnc_commodity_table_lookup (table, name_space, mnemonic);
mnemonic.c_str()); free (name_space);
free (mnemonic);
return rv;
} }
if (scm_is_string(new_value)) if (scm_is_string(new_value))
{ {
auto book{get_current_book()}; auto book{get_current_book()};
auto table = gnc_commodity_table_get_table(book); auto table = gnc_commodity_table_get_table(book);
std::string mnemonic{scm_to_utf8_string(new_value)}; auto mnemonic{scm_to_utf8_string(new_value)};
return gnc_commodity_table_lookup(table, "CURRENCY", mnemonic.c_str()); auto rv = gnc_commodity_table_lookup(table, "CURRENCY", mnemonic);
free (mnemonic);
return rv;
} }
return nullptr; return nullptr;
} }
template <> inline const Account* template <> inline const Account*
scm_to_value<const Account*>(SCM new_value) scm_to_value<const Account*>(SCM new_value)
{ {
return GNC_ACCOUNT(scm_to_value<const QofInstance*>(new_value)); return GNC_ACCOUNT(scm_to_value<const QofInstance*>(new_value));
} }
skipping to change at line 468 skipping to change at line 470
SWIG_ConvertPtr(new_value, &ptr, SWIGTYPE_p__gncOwner, 0); SWIG_ConvertPtr(new_value, &ptr, SWIGTYPE_p__gncOwner, 0);
return static_cast<const GncOwner*>(ptr); return static_cast<const GncOwner*>(ptr);
} }
template <>inline GncOptionAccountList template <>inline GncOptionAccountList
scm_to_value<GncOptionAccountList>(SCM new_value) scm_to_value<GncOptionAccountList>(SCM new_value)
{ {
GncOptionAccountList retval{}; GncOptionAccountList retval{};
if (scm_is_false(scm_list_p(new_value)) || scm_is_null(new_value)) if (scm_is_false(scm_list_p(new_value)) || scm_is_null(new_value))
return retval; return retval;
retval.reserve(scm_to_size_t(scm_length(new_value)));
auto next{new_value}; auto next{new_value};
auto from_report{true};
while (!scm_is_null(next) && scm_car(next)) while (!scm_is_null(next) && scm_car(next))
{ {
/* If the incoming scheme is from a report then it will contain an Account*, if /* If the incoming scheme is from a report then it will contain an Account*, if
* it's from restoring a saved report config it will be a guid. * it's from restoring a saved report config it will be a guid.
*/ */
if (scm_is_string(scm_car(next))) if (scm_is_string(scm_car(next)))
{ {
auto guid_str{scm_to_utf8_string(scm_car(next))}; auto guid_str{scm_to_utf8_string(scm_car(next))};
from_report = false;
GncGUID guid; GncGUID guid;
string_to_guid(guid_str, &guid); string_to_guid(guid_str, &guid);
retval.push_back(guid); retval.push_back(guid);
free (guid_str);
} }
else else
{ {
void *account{}; void *account{};
SWIG_ConvertPtr(scm_car(next), &account, SWIGTYPE_p_Account, 0); SWIG_ConvertPtr(scm_car(next), &account, SWIGTYPE_p_Account, 0);
if (account) if (account)
{ {
auto guid{qof_entity_get_guid(static_cast<Account *>(account))}; auto guid{qof_entity_get_guid(static_cast<Account *>(account))};
retval.push_back(*guid); retval.push_back(*guid);
} }
} }
next = scm_cdr(next); next = scm_cdr(next);
} }
if (!from_report)
std::reverse(retval.begin(), retval.end());
return retval; return retval;
} }
template <>inline GncOptionReportPlacementVec template <>inline GncOptionReportPlacementVec
scm_to_value<GncOptionReportPlacementVec>(SCM new_value) scm_to_value<GncOptionReportPlacementVec>(SCM new_value)
{ {
GncOptionReportPlacementVec rp; GncOptionReportPlacementVec rp;
GncOptionAccountList retval{}; GncOptionAccountList retval{};
if (scm_is_false(scm_list_p(new_value)) || scm_is_null(new_value)) if (scm_is_false(scm_list_p(new_value)) || scm_is_null(new_value))
return rp; return rp;
skipping to change at line 628 skipping to change at line 639
keyval = SCM_SIMPLE_VECTOR_REF(vec, 0); keyval = SCM_SIMPLE_VECTOR_REF(vec, 0);
keytype = KeyType::STRING; keytype = KeyType::STRING;
} }
else if (scm_is_integer(v_ref_0)) else if (scm_is_integer(v_ref_0))
{ {
keyval = scm_number_to_string(v_ref_0, scm_from_uint(10u)); keyval = scm_number_to_string(v_ref_0, scm_from_uint(10u));
keytype = KeyType::NUMBER; keytype = KeyType::NUMBER;
} }
else else
throw std::invalid_argument("Unsupported key type in multichoice opt ion."); throw std::invalid_argument("Unsupported key type in multichoice opt ion.");
std::string key{scm_to_utf8_string(keyval)}; auto key{scm_to_utf8_string(keyval)};
std::string name{scm_to_utf8_string(SCM_SIMPLE_VECTOR_REF(vec, 1))}; auto name{scm_to_utf8_string(SCM_SIMPLE_VECTOR_REF(vec, 1))};
choices.push_back({std::move(key), std::move(name), keytype}); choices.push_back({key, name, keytype});
free (name);
free (key);
} }
$1 = &choices; $1 = &choices;
} }
%typemap(in) GncOptionAccountList %typemap(in) GncOptionAccountList
{ {
auto len = scm_is_true($input) ? scm_to_size_t(scm_length($input)) : 0; auto len = scm_is_true($input) ? scm_to_size_t(scm_length($input)) : 0;
for (std::size_t i = 0; i < len; ++i) for (std::size_t i = 0; i < len; ++i)
{ {
SCM s_account = scm_list_ref($input, scm_from_size_t(i)); SCM s_account = scm_list_ref($input, scm_from_size_t(i));
skipping to change at line 920 skipping to change at line 933
return reldate_values[static_cast<uint16_t>(period) + 1]; return reldate_values[static_cast<uint16_t>(period) + 1];
} }
inline static bool scm_date_absolute(SCM date) inline static bool scm_date_absolute(SCM date)
{ {
if (scm_is_pair(date)) if (scm_is_pair(date))
{ {
if (scm_is_symbol(scm_car(date))) if (scm_is_symbol(scm_car(date)))
{ {
auto car{scm_to_utf8_string(scm_symbol_to_string(scm_car(date))) }; auto car{scm_to_utf8_string(scm_symbol_to_string(scm_car(date))) };
bool rv = false;
if (strcmp(car, "relative") == 0) if (strcmp(car, "relative") == 0)
return false; rv = false;
if (strcmp(car, "absolute") == 0) else if (strcmp(car, "absolute") == 0)
return true; rv = true;
else
assert(false); assert(false);
free (car);
return rv;
} }
else else
{ {
auto cdr{scm_cdr(date)}; auto cdr{scm_cdr(date)};
if (scm_is_symbol(cdr)) if (scm_is_symbol(cdr))
return false; return false;
if (scm_is_number(cdr)) if (scm_is_number(cdr))
return true; return true;
assert(false); assert(false);
skipping to change at line 976 skipping to change at line 992
is_gncoptiondb (const SCM ptr) is_gncoptiondb (const SCM ptr)
{ {
return SWIG_Guile_IsPointerOfType (ptr, SWIGTYPE_p_std__unique_ptrT_GncO ptionDB_t) ? SCM_BOOL_T : SCM_BOOL_F; return SWIG_Guile_IsPointerOfType (ptr, SWIGTYPE_p_std__unique_ptrT_GncO ptionDB_t) ? SCM_BOOL_T : SCM_BOOL_F;
} }
inline GncMultichoiceOptionIndexVec inline GncMultichoiceOptionIndexVec
scm_to_multichoices(const SCM new_value, scm_to_multichoices(const SCM new_value,
const GncOptionMultichoiceValue& option) const GncOptionMultichoiceValue& option)
{ {
static const auto uint16_t_max = std::numeric_limits<uint16_t>::max(); static const auto uint16_t_max = std::numeric_limits<uint16_t>::max();
static const char* empty{""}; auto scm_to_str = [](auto item)->char* {
auto scm_to_str = [](auto item)->const char* { static const char* empty{""};
if (scm_is_integer(item)) if (scm_is_integer(item))
item = scm_number_to_string(item, scm_from_uint(10u)); item = scm_number_to_string(item, scm_from_uint(10u));
else if (scm_is_symbol(item)) else if (scm_is_symbol(item))
item = scm_symbol_to_string(item); item = scm_symbol_to_string(item);
if (scm_is_string(item)) if (scm_is_string(item))
return scm_to_utf8_string(item); return scm_to_utf8_string(item);
return empty; return strdup(empty);
}; };
GncMultichoiceOptionIndexVec vec; GncMultichoiceOptionIndexVec vec;
auto choice_is_list{option.get_ui_type() == GncOptionUIType::LIST}; auto choice_is_list{option.get_ui_type() == GncOptionUIType::LIST};
if (scm_is_list(new_value)) if (scm_is_list(new_value))
{ {
if (!choice_is_list) if (!choice_is_list)
throw std::invalid_argument{"Attempt to set multichoice with a lis t of values."}; throw std::invalid_argument{"Attempt to set multichoice with a lis t of values."};
auto len{scm_to_size_t(scm_length(new_value))}; auto len{scm_to_size_t(scm_length(new_value))};
for (std::size_t i = 0; i < len; ++i) for (std::size_t i = 0; i < len; ++i)
{ {
auto item{scm_list_ref(new_value, scm_from_size_t(i))}; auto item{scm_list_ref(new_value, scm_from_size_t(i))};
auto index{option.permissible_value_index(scm_to_str(item))}; auto item_str{scm_to_str(item)};
auto index{option.permissible_value_index(item_str)};
free (item_str);
if (index < uint16_t_max) if (index < uint16_t_max)
vec.push_back(index); vec.push_back(index);
} }
} }
else else
{ {
auto index{option.permissible_value_index(scm_to_str(new_value))}; auto newval_str{scm_to_str(new_value)};
auto index{option.permissible_value_index(newval_str)};
free (newval_str);
if (index < uint16_t_max) if (index < uint16_t_max)
vec.push_back(index); vec.push_back(index);
} }
return vec; return vec;
} }
inline SCM scm_from_multichoices(const GncMultichoiceOptionIndexVec& indexes , inline SCM scm_from_multichoices(const GncMultichoiceOptionIndexVec& indexes ,
const GncOptionMultichoiceValue& option) const GncOptionMultichoiceValue& option)
{ {
using KeyType = GncOptionMultichoiceKeyType; using KeyType = GncOptionMultichoiceKeyType;
skipping to change at line 1191 skipping to change at line 1211
return std::visit([](const auto& option)->SCM { return std::visit([](const auto& option)->SCM {
if constexpr (is_MultichoiceDateOrRange_v<decltype(option)>) if constexpr (is_MultichoiceDateOrRange_v<decltype(option)>)
return get_scm_default_value(option); return get_scm_default_value(option);
auto value{option.get_default_value()}; auto value{option.get_default_value()};
return return_scm_value(value); return return_scm_value(value);
}, swig_get_option($self)); }, swig_get_option($self));
} }
SCM save_scm_value() SCM save_scm_value()
{ {
static const SCM plain_format_str{scm_from_utf8_string("~s")}; [[maybe_unused]] static const SCM plain_format_str{scm_from_utf8_string(
static const SCM ticked_format_str{scm_from_utf8_string("'~a")}; "~s")};
static const SCM list_format_str{scm_from_utf8_string("'~s")}; [[maybe_unused]] static const SCM ticked_format_str{scm_from_utf8_string
("'~a")};
[[maybe_unused]] static const SCM list_format_str{scm_from_utf8_string("
'~s")};
//scm_simple_format needs a scheme list of arguments to match the format //scm_simple_format needs a scheme list of arguments to match the format
//placeholders. //placeholders.
return std::visit([$self] (auto &option) -> SCM { return std::visit([$self] (auto &option) -> SCM {
static const auto no_value{scm_from_utf8_string("")}; static const auto no_value{scm_from_utf8_string("")};
if constexpr (is_same_decayed_v<decltype(option), if constexpr (is_same_decayed_v<decltype(option),
GncOptionAccountListValue>) GncOptionAccountListValue>)
{ {
auto guid_list{option.get_value()}; auto guid_list{option.get_value()};
if (guid_list.empty()) if (guid_list.empty())
return scm_simple_format(SCM_BOOL_F, list_format_str, sc m_list_1(no_value)); return scm_simple_format(SCM_BOOL_F, list_format_str, sc m_list_1(no_value));
skipping to change at line 1387 skipping to change at line 1407
} }
if constexpr (is_same_decayed_v<decltype(option), if constexpr (is_same_decayed_v<decltype(option),
GncOptionCommodityValue>) GncOptionCommodityValue>)
{ {
if (scm_list_p(new_value) == SCM_BOOL_F) if (scm_list_p(new_value) == SCM_BOOL_F)
{ {
if (scm_is_string(new_value)) if (scm_is_string(new_value))
{ {
auto strval{scm_to_utf8_string(new_value)}; auto strval{scm_to_utf8_string(new_value)};
option.deserialize(strval); option.deserialize(strval);
free (strval);
return; return;
} }
option.set_value(scm_to_value<gnc_commodity*>(new_va lue)); option.set_value(scm_to_value<gnc_commodity*>(new_va lue));
return; return;
} }
auto len{scm_to_uint(scm_length(new_value))}; auto len{scm_to_uint(scm_length(new_value))};
if (len > 1) if (len > 1)
{ {
auto revlist{scm_reverse(new_value)}; auto revlist{scm_reverse(new_value)};
std::string name_space{scm_to_utf8_string(scm_cadr(r auto name_space{scm_to_utf8_string(scm_cadr(revlist)
evlist))}; )};
std::string mnemonic{scm_to_utf8_string(scm_car(revl auto mnemonic{scm_to_utf8_string(scm_car(revlist))};
ist))}; option.deserialize(std::string (name_space) + ":" +
option.deserialize(name_space + ":" + mnemonic); std::string (mnemonic));
free (mnemonic);
free (name_space);
} }
else else
{ {
option.deserialize(scm_to_utf8_string(scm_car(new_va auto newval_str{scm_to_utf8_string(scm_car(new_value
lue))); ))};
option.deserialize(newval_str);
free (newval_str);
} }
return; return;
} }
if constexpr (is_QofInstanceValue_v<decltype(option)>) if constexpr (is_QofInstanceValue_v<decltype(option)>)
{ {
if (scm_is_string(new_value)) if (scm_is_string(new_value))
{ {
auto strval{scm_to_utf8_string(new_value)}; auto strval{scm_to_utf8_string(new_value)};
auto val{qof_instance_from_string(strval, option.get _ui_type())}; auto val{qof_instance_from_string(strval, option.get _ui_type())};
option.set_value(val); option.set_value(val);
free (strval);
} }
else else
{ {
auto val{scm_to_value<const QofInstance*>(new_value) }; auto val{scm_to_value<const QofInstance*>(new_value) };
option.set_value(val); option.set_value(val);
} }
return; return;
} }
if constexpr (is_GncOwnerValue_v<decltype(option)>) if constexpr (is_GncOwnerValue_v<decltype(option)>)
{ {
if (scm_is_pair(new_value)) if (scm_is_pair(new_value))
{ {
GncOwner owner{}; GncOwner owner{};
owner.type = static_cast<GncOwnerType>(scm_to_int(sc m_car(new_value))); owner.type = static_cast<GncOwnerType>(scm_to_int(sc m_car(new_value)));
auto strval{scm_to_utf8_string(scm_cdr(new_value))}; auto strval{scm_to_utf8_string(scm_cdr(new_value))};
owner.owner.undefined = qof_instance_from_string(str val, option.get_ui_type()); owner.owner.undefined = qof_instance_from_string(str val, option.get_ui_type());
option.set_value(&owner); option.set_value(&owner);
free (strval);
} }
else else
{ {
auto val{scm_to_value<const GncOwner*>(new_value)}; auto val{scm_to_value<const GncOwner*>(new_value)};
option.set_value(val); option.set_value(val);
} }
return; return;
} }
if constexpr (is_QofQueryValue_v<decltype(option)>) if constexpr (is_QofQueryValue_v<decltype(option)>)
skipping to change at line 1459 skipping to change at line 1487
option.set_value(val); option.set_value(val);
} }
return; return;
} }
if constexpr (is_same_decayed_v<decltype(option), if constexpr (is_same_decayed_v<decltype(option),
GncOptionAccountSelValue>) GncOptionAccountSelValue>)
{ {
if (scm_is_string(new_value)) if (scm_is_string(new_value))
{ {
auto strval{scm_to_utf8_string(new_value)}; auto strval{scm_to_utf8_string(new_value)};
GncGUID guid; GncGUID guid{};
string_to_guid(strval, &guid); string_to_guid(strval, &guid);
auto book{get_current_book()}; auto book{get_current_book()};
option.set_value(xaccAccountLookup(&guid, book)); option.set_value(xaccAccountLookup(&guid, book));
free (strval);
} }
else else
{ {
auto val{scm_to_value<const QofInstance*>(new_value) }; auto val{scm_to_value<const QofInstance*>(new_value) };
option.set_value(GNC_ACCOUNT(val)); option.set_value(GNC_ACCOUNT(val));
} }
return; return;
} }
auto value{scm_to_value<std::decay_t<decltype(option.get_val ue())>>(new_value)}; //Can't inline, set_value takes arg by reference. auto value{scm_to_value<std::decay_t<decltype(option.get_val ue())>>(new_value)}; //Can't inline, set_value takes arg by reference.
option.set_value(static_cast<decltype(option.get_value())>(v alue)); option.set_value(static_cast<decltype(option.get_value())>(v alue));
skipping to change at line 1527 skipping to change at line 1556
auto comm{scm_to_value<gnc_commodity*>(new_value)}; auto comm{scm_to_value<gnc_commodity*>(new_value)};
option.set_default_value(comm); option.set_default_value(comm);
} }
if constexpr (is_QofInstanceValue_v<decltype(option)>) if constexpr (is_QofInstanceValue_v<decltype(option)>)
{ {
if (scm_is_string(new_value)) if (scm_is_string(new_value))
{ {
auto strval{scm_to_utf8_string(new_value)}; auto strval{scm_to_utf8_string(new_value)};
auto val{qof_instance_from_string(strval, option.get _ui_type())}; auto val{qof_instance_from_string(strval, option.get _ui_type())};
option.set_default_value(val); option.set_default_value(val);
free (strval);
} }
else else
{ {
auto val{scm_to_value<const QofInstance*>(new_value) }; auto val{scm_to_value<const QofInstance*>(new_value) };
option.set_default_value(val); option.set_default_value(val);
} }
return; return;
} }
if constexpr (is_GncOwnerValue_v<decltype(option)>) if constexpr (is_GncOwnerValue_v<decltype(option)>)
{ {
if (scm_is_pair(new_value)) if (scm_is_pair(new_value))
{ {
GncOwner owner{}; GncOwner owner{};
owner.type = static_cast<GncOwnerType>(scm_to_int(sc m_car(new_value))); owner.type = static_cast<GncOwnerType>(scm_to_int(sc m_car(new_value)));
auto strval{scm_to_utf8_string(scm_cdr(new_value))}; auto strval{scm_to_utf8_string(scm_cdr(new_value))};
owner.owner.undefined = qof_instance_from_string(str val, option.get_ui_type()); owner.owner.undefined = qof_instance_from_string(str val, option.get_ui_type());
option.set_default_value(&owner); option.set_default_value(&owner);
free (strval);
} }
else else
{ {
auto val{scm_to_value<const GncOwner*>(new_value)}; auto val{scm_to_value<const GncOwner*>(new_value)};
option.set_default_value(val); option.set_default_value(val);
} }
return; return;
} }
if constexpr (is_QofQueryValue_v<decltype(option)>) if constexpr (is_QofQueryValue_v<decltype(option)>)
{ {
skipping to change at line 1572 skipping to change at line 1603
option.set_default_value(val); option.set_default_value(val);
} }
return; return;
} }
if constexpr (is_same_decayed_v<decltype(option), if constexpr (is_same_decayed_v<decltype(option),
GncOptionAccountSelValue>) GncOptionAccountSelValue>)
{ {
if (scm_is_string(new_value)) if (scm_is_string(new_value))
{ {
auto strval{scm_to_utf8_string(new_value)}; auto strval{scm_to_utf8_string(new_value)};
GncGUID guid; GncGUID guid{};
string_to_guid(strval, &guid); string_to_guid(strval, &guid);
auto book{get_current_book()}; auto book{get_current_book()};
option.set_default_value(xaccAccountLookup(&guid, bo ok)); option.set_default_value(xaccAccountLookup(&guid, bo ok));
free (strval);
} }
else else
{ {
auto val{scm_to_value<Account*>(new_value)}; auto val{scm_to_value<Account*>(new_value)};
option.set_default_value(val); option.set_default_value(val);
} }
return; return;
} }
auto value{scm_to_value<std::decay_t<decltype(option.get_val ue())>>(new_value)}; //Can't inline, set_value takes arg by reference. auto value{scm_to_value<std::decay_t<decltype(option.get_val ue())>>(new_value)}; //Can't inline, set_value takes arg by reference.
option.set_default_value(value); option.set_default_value(value);
 End of changes. 27 change blocks. 
35 lines changed or deleted 71 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)