Skip to content

Commit

Permalink
[qofinstance.cpp] move qof_instance_set|get_path_kvp to qofinstance.cpp
Browse files Browse the repository at this point in the history
note these are overloaded functions
  • Loading branch information
christopherlam committed Oct 11, 2024
1 parent 51a8894 commit 1a945f0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
14 changes: 0 additions & 14 deletions libgnucash/engine/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2479,20 +2479,6 @@ xaccAccountSetDescription (Account *acc, const char *str)

using StrVec = std::vector<std::string>;

template <typename T> std::optional<T>
qof_instance_get_path_kvp (QofInstance* inst, StrVec path)
{
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, StrVec path, std::optional<T> value)
{
delete inst->kvp_data->set_path(path, value ? new KvpValue(*value) : nullptr);
qof_instance_set_dirty (inst);
}

static void
set_kvp_gnc_numeric_path (Account *acc, const std::vector<std::string>& path,
std::optional<gnc_numeric> value)
Expand Down
9 changes: 9 additions & 0 deletions libgnucash/engine/qofinstance-p.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#ifdef __cplusplus
#include "kvp-frame.hpp"
#include <string>
#include <optional>
extern "C"
{
#endif
Expand Down Expand Up @@ -165,6 +166,14 @@ 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 &);

using StrVec = std::vector<std::string>;

template <typename T> std::optional<T>
qof_instance_get_path_kvp (QofInstance*, const StrVec&);

template <typename T> void
qof_instance_set_path_kvp (QofInstance*, const StrVec&, std::optional<T>);

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 &);
Expand Down
14 changes: 14 additions & 0 deletions libgnucash/engine/qofinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,20 @@ 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 StrVec& path)
{
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, const StrVec& path, std::optional<T> value)
{
delete inst->kvp_data->set_path(path, value ? new KvpValue(*value) : nullptr);
qof_instance_set_dirty (inst);
}

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);
Expand Down

0 comments on commit 1a945f0

Please sign in to comment.