From a26a6c4a6f9effe3dc6a42d067c9bf54b1c2c945 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 13 Oct 2024 08:23:16 +0800 Subject: [PATCH] [qofinstance.cpp] add overloaded qof_instance_set|get_path_kvp these overloaded functions to kvp slots do not require GValue --- libgnucash/engine/qofinstance-p.h | 7 +++++++ libgnucash/engine/qofinstance.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/libgnucash/engine/qofinstance-p.h b/libgnucash/engine/qofinstance-p.h index 45d4eeb68d..cf4c676bb5 100644 --- a/libgnucash/engine/qofinstance-p.h +++ b/libgnucash/engine/qofinstance-p.h @@ -36,6 +36,7 @@ #ifdef __cplusplus #include "kvp-frame.hpp" #include +#include extern "C" { #endif @@ -165,6 +166,12 @@ void qof_instance_get_path_kvp (QofInstance *, GValue *, std::vector const &); +template std::optional +qof_instance_get_path_kvp (QofInstance*, const Path&); + +template void +qof_instance_set_path_kvp (QofInstance*, std::optional, const Path&); + bool qof_instance_has_path_slot (QofInstance const *, std::vector const &); void qof_instance_slot_path_delete (QofInstance const *, std::vector const &); diff --git a/libgnucash/engine/qofinstance.cpp b/libgnucash/engine/qofinstance.cpp index 11df55c1e8..eec178a02e 100644 --- a/libgnucash/engine/qofinstance.cpp +++ b/libgnucash/engine/qofinstance.cpp @@ -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 std::optional +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(kvp_value->get()) : std::nullopt; +} + +template void +qof_instance_set_path_kvp (QofInstance* inst, std::optional 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 qof_instance_get_path_kvp (QofInstance*, const Path&); +template std::optional qof_instance_get_path_kvp (QofInstance*, const Path&); +template std::optional qof_instance_get_path_kvp (QofInstance*, const Path&); +template std::optional qof_instance_get_path_kvp (QofInstance*, const Path&); + +template void qof_instance_set_path_kvp (QofInstance*, std::optional, const Path& path); +template void qof_instance_set_path_kvp (QofInstance*, std::optional, const Path& path); +template void qof_instance_set_path_kvp (QofInstance*, std::optional, const Path& path); +template void qof_instance_set_path_kvp (QofInstance*, std::optional, const Path& path); + void qof_instance_get_path_kvp (QofInstance * inst, GValue * value, std::vector const & path) { gvalue_from_kvp_value (inst->kvp_data->get_slot (path), value);