c++options: Implement serialization for GncOwner.

pull/1191/head
John Ralls 4 years ago
parent 0ce841d4ce
commit 66f9fc81c7

@ -27,7 +27,7 @@
#include <guid.hpp>
#include <cassert>
#include <charconv>
#include <sstream>
extern "C"
{
#include "gnc-accounting-period.h"
@ -440,6 +440,16 @@ GncOptionValue<ValueType>::serialize() const noexcept
static const std::string no_value{"No Value"};
if constexpr(std::is_same_v<ValueType, const QofInstance*>)
return m_value ? qof_instance_to_string(m_value) : no_value;
if constexpr(std::is_same_v<ValueType, const GncOwner*>)
{
if (!m_value)
return no_value;
auto guid{qof_instance_to_string(qofOwnerGetOwner(m_value))};
auto type{qofOwnerGetType(m_value)};
std::ostringstream ostr{};
ostr << type << " " << guid;
return ostr.str();
}
else if constexpr(is_same_decayed_v<ValueType, std::string>)
return m_value;
else if constexpr(is_same_decayed_v<ValueType, bool>)
@ -455,6 +465,14 @@ GncOptionValue<ValueType>::deserialize(const std::string& str) noexcept
{
if constexpr(std::is_same_v<ValueType, const QofInstance*>)
set_value(qof_instance_from_string(str, get_ui_type()));
if constexpr(std::is_same_v<ValueType, const GncOwner*>)
{
std::istringstream istr{str};
std::string type, guid;
istr >> type >> guid;
auto inst{qof_instance_from_string(guid, get_ui_type())};
qofOwnerSetEntity(const_cast<GncOwner*>(m_value), inst);
}
else if constexpr(is_same_decayed_v<ValueType, std::string>)
set_value(str);
else if constexpr(is_same_decayed_v<ValueType, bool>)

@ -1069,7 +1069,11 @@ inline SCM return_scm_value(ValueType value)
if constexpr (is_same_decayed_v<decltype(option),
GncOptionValue<const GncOwner*>>)
{
return scm_from_utf8_string("Not Yet Implemented");
auto value{option.get_value()};
auto guid{scm_from_utf8_string(qof_instance_to_string(qofOwnerGetOwner(value)).c_str())};
auto type{scm_from_long(gncOwnerGetType(value))};
return scm_simple_format(SCM_BOOL_F, ticked_format_str,
scm_list_1(scm_cons(type, guid)));
}
if constexpr (is_QofQueryValue_v<decltype(option)>)
{

Loading…
Cancel
Save