mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Merge branch 'better-c++' into stable #1965
This commit is contained in:
commit
f2f5e2c52d
File diff suppressed because it is too large
Load Diff
@ -112,10 +112,6 @@ typedef struct AccountPrivate
|
||||
gnc_numeric noclosing_balance;
|
||||
gnc_numeric cleared_balance;
|
||||
gnc_numeric reconciled_balance;
|
||||
|
||||
std::optional<gnc_numeric> higher_balance_limit;
|
||||
std::optional<gnc_numeric> lower_balance_limit;
|
||||
std::optional<bool> include_sub_account_balances;
|
||||
|
||||
gboolean balance_dirty; /* balances in splits incorrect */
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
#ifdef __cplusplus
|
||||
#include "kvp-frame.hpp"
|
||||
#include <string>
|
||||
#include <optional>
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
@ -165,6 +166,12 @@ void qof_instance_get_path_kvp (QofInstance *, GValue *, std::vector<std::string
|
||||
|
||||
void qof_instance_set_path_kvp (QofInstance *, GValue const *, std::vector<std::string> const &);
|
||||
|
||||
template <typename T> std::optional<T>
|
||||
qof_instance_get_path_kvp (QofInstance*, const Path&);
|
||||
|
||||
template <typename T> void
|
||||
qof_instance_set_path_kvp (QofInstance*, std::optional<T>, const Path&);
|
||||
|
||||
bool qof_instance_has_path_slot (QofInstance const *, std::vector<std::string> const &);
|
||||
|
||||
void qof_instance_slot_path_delete (QofInstance const *, std::vector<std::string> const &);
|
||||
|
@ -1063,6 +1063,32 @@ qof_instance_set_kvp (QofInstance * inst, GValue const * value, unsigned count,
|
||||
delete inst->kvp_data->set_path (path, kvp_value_from_gvalue (value));
|
||||
}
|
||||
|
||||
template <typename T> std::optional<T>
|
||||
qof_instance_get_path_kvp (QofInstance* inst, const Path& path)
|
||||
{
|
||||
g_return_val_if_fail (QOF_IS_INSTANCE(inst), std::nullopt);
|
||||
auto kvp_value{inst->kvp_data->get_slot(path)};
|
||||
return kvp_value ? std::make_optional<T>(kvp_value->get<T>()) : std::nullopt;
|
||||
}
|
||||
|
||||
template <typename T> void
|
||||
qof_instance_set_path_kvp (QofInstance* inst, std::optional<T> value, const Path& path)
|
||||
{
|
||||
g_return_if_fail (QOF_IS_INSTANCE(inst));
|
||||
delete inst->kvp_data->set_path(path, value ? new KvpValue(*value) : nullptr);
|
||||
qof_instance_set_dirty (inst);
|
||||
}
|
||||
|
||||
template std::optional<const char*> qof_instance_get_path_kvp <const char*> (QofInstance*, const Path&);
|
||||
template std::optional<gnc_numeric> qof_instance_get_path_kvp <gnc_numeric> (QofInstance*, const Path&);
|
||||
template std::optional<GncGUID*> qof_instance_get_path_kvp <GncGUID*> (QofInstance*, const Path&);
|
||||
template std::optional<int64_t> qof_instance_get_path_kvp <int64_t> (QofInstance*, const Path&);
|
||||
|
||||
template void qof_instance_set_path_kvp <const char*> (QofInstance*, std::optional<const char*>, const Path& path);
|
||||
template void qof_instance_set_path_kvp <gnc_numeric> (QofInstance*, std::optional<gnc_numeric>, const Path& path);
|
||||
template void qof_instance_set_path_kvp <GncGUID*> (QofInstance*, std::optional<GncGUID*>, const Path& path);
|
||||
template void qof_instance_set_path_kvp <int64_t> (QofInstance*, std::optional<int64_t>, const Path& path);
|
||||
|
||||
void qof_instance_get_path_kvp (QofInstance * inst, GValue * value, std::vector<std::string> const & path)
|
||||
{
|
||||
gvalue_from_kvp_value (inst->kvp_data->get_slot (path), value);
|
||||
@ -1316,17 +1342,16 @@ struct wrap_param
|
||||
static void
|
||||
wrap_gvalue_function (const char* key, KvpValue *val, wrap_param & param)
|
||||
{
|
||||
GValue *gv;
|
||||
gv = g_slice_new0 (GValue);
|
||||
GValue gv;
|
||||
if (val->get_type() != KvpValue::Type::FRAME)
|
||||
gvalue_from_kvp_value(val, gv);
|
||||
gvalue_from_kvp_value(val, &gv);
|
||||
else
|
||||
{
|
||||
g_value_init (gv, G_TYPE_STRING);
|
||||
g_value_set_string (gv, nullptr);
|
||||
g_value_init (&gv, G_TYPE_STRING);
|
||||
g_value_set_string (&gv, nullptr);
|
||||
}
|
||||
param.proc(key, gv, param.user_data);
|
||||
g_slice_free (GValue, gv);
|
||||
param.proc(key, &gv, param.user_data);
|
||||
g_value_unset (&gv);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1107,7 +1107,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (xaccAccountGetLastNum (account), ==, "red");
|
||||
|
||||
xaccAccountSetLastNum (account, "");
|
||||
g_assert_cmpstr (xaccAccountGetLastNum (account), ==, "");
|
||||
g_assert_cmpstr (xaccAccountGetLastNum (account), ==, nullptr);
|
||||
|
||||
xaccAccountSetLastNum (account, " ");
|
||||
g_assert_cmpstr (xaccAccountGetLastNum (account), ==, " ");
|
||||
|
Loading…
Reference in New Issue
Block a user