GnuCash  4.8a-134-g214de30c7+
Public Types | Public Member Functions | Friends
KvpValue Struct Reference

Implements KvpValue using boost::variant. More...

#include <kvp-value.hpp>

Public Types

enum  Type {
  INVALID = -1, INT64 = 1, DOUBLE, NUMERIC,
  STRING, GUID, TIME64, PLACEHOLDER_DONT_USE,
  GLIST, FRAME, GDATE
}
 

Public Member Functions

 KvpValueImpl (KvpValueImpl const &) noexcept
 Performs a deep copy.
 
KvpValueImploperator= (const KvpValueImpl &) noexcept
 
 KvpValueImpl (KvpValueImpl &&b) noexcept
 Move. More...
 
KvpValueImploperator= (KvpValueImpl &&b) noexcept
 
template<typename T >
 KvpValueImpl (T) noexcept
 Create a KvpValue containing the passed in item. More...
 
 ~KvpValueImpl () noexcept
 Performs a deep delete. More...
 
KvpFrame * replace_frame_nc (KvpFrame *) noexcept
 Replaces the frame within this KvpValueImpl. More...
 
GList * replace_glist_nc (GList *) noexcept
 Replaces the glist within this KvpValueImpl. More...
 
KvpValueImpladd (KvpValueImpl *) noexcept
 Adds another value to this KvpValueImpl. More...
 
KvpValueImpl::Type get_type () const noexcept
 
std::string to_string () const noexcept
 
std::string to_string (std::string const &prefix) const noexcept
 
template<typename T >
get () const noexcept
 
template<typename T >
void set (T) noexcept
 

Friends

int compare (const KvpValueImpl &, const KvpValueImpl &) noexcept
 

Detailed Description

Implements KvpValue using boost::variant.

Capable of holding the following types:

Definition at line 57 of file kvp-value.hpp.

Member Enumeration Documentation

◆ Type

Enumerator
INT64 

QOF_TYPE_INT64 gint64.

DOUBLE 

QOF_TYPE_DOUBLE gdouble.

NUMERIC 

QOF_TYPE_NUMERIC.

STRING 

QOF_TYPE_STRING gchar*.

GUID 

QOF_TYPE_GUID.

TIME64 

QOF_TYPE_DATE.

GLIST 

no QOF equivalent.

FRAME 

no QOF equivalent.

GDATE 

no QOF equivalent.

Definition at line 60 of file kvp-value.hpp.

61  {
62  INVALID = -1,
63  INT64 = 1,
64  DOUBLE,
65  NUMERIC,
66  STRING,
67  GUID,
68  TIME64,
69  PLACEHOLDER_DONT_USE, /* Replaces KVP_TYPE_BINARY */
70  GLIST,
71  FRAME,
72  GDATE,
73  };
no QOF equivalent.
Definition: kvp-value.hpp:71
QOF_TYPE_STRING gchar*.
Definition: kvp-value.hpp:66
QOF_TYPE_DATE.
Definition: kvp-value.hpp:68
QOF_TYPE_NUMERIC.
Definition: kvp-value.hpp:65
QOF_TYPE_DOUBLE gdouble.
Definition: kvp-value.hpp:64
no QOF equivalent.
Definition: kvp-value.hpp:72
no QOF equivalent.
Definition: kvp-value.hpp:70
QOF_TYPE_GUID.
Definition: kvp-value.hpp:67
QOF_TYPE_INT64 gint64.
Definition: kvp-value.hpp:63

Constructor & Destructor Documentation

◆ KvpValueImpl() [1/2]

KvpValue::KvpValueImpl ( KvpValueImpl &&  b)
noexcept

Move.

The old object's datastore is set to int64_t 0.

Definition at line 44 of file kvp-value.cpp.

45 {
46  datastore = b.datastore;
47  b.datastore = INT64_C(0);
48 }

◆ KvpValueImpl() [2/2]

template<typename T >
KvpValue::KvpValueImpl ( newvalue)
noexcept

Create a KvpValue containing the passed in item.

Note that for pointer types const char*, KvpFrame*, GncGUID*, and GList* the KvpValue takes ownership of the object and will delete/free it when the KvpValue is destroyed. That means these objects must be allocated in the free store or heap as follows:

  • const char*: GLib string allocation, e.g. g_strdup()/
  • KvpFrame*: operator new
  • GncGUID*: guid_new() or guid_copy()
  • GList*: Uses g_list_free(), so it's up to classes using this to empty the list before destroying the KvpValue.

Definition at line 169 of file kvp-value.hpp.

169  :
170  datastore(newvalue)
171 {
172 }

◆ ~KvpValueImpl()

KvpValue::~KvpValueImpl ( )
noexcept

Performs a deep delete.

The contents of this KvpValueImpl are also deleted.

Definition at line 384 of file kvp-value.cpp.

385 {
386  delete_visitor d;
387  boost::apply_visitor(d, datastore);
388 }

Member Function Documentation

◆ add()

KvpValueImpl * KvpValue::add ( KvpValueImpl val)
noexcept

Adds another value to this KvpValueImpl.

If this KvpValueImpl represents a collection (GList), the new value is added to the collection and this is returned.

Otherwise, a new KvpValueImpl representing a collection is created, this and the new value are added to it, and it is returned.

Definition at line 58 of file kvp-value.cpp.

59 {
60  /* If already a glist here, just append */
61  if (this->datastore.type() == typeid(GList*))
62  {
63  GList * list = boost::get<GList*>(datastore);
64  datastore = g_list_append (list, val);
65  return this;
66  }
67  /* If some other value, convert it to a glist */
68  GList *list = nullptr;
69 
70  list = g_list_append (list, this);
71  list = g_list_append (list, val);
72  return new KvpValueImpl(list);
73 }
KvpValueImpl(KvpValueImpl const &) noexcept
Performs a deep copy.
Definition: kvp-value.cpp:32

◆ replace_frame_nc()

KvpFrame * KvpValue::replace_frame_nc ( KvpFrame *  new_value)
noexcept

Replaces the frame within this KvpValueImpl.

If this KvpValueImpl doesn't contain a KvpFrame, nullptr is returned. Otherwise, the old KvpFrame * is returned.

Definition at line 101 of file kvp-value.cpp.

102 {
103  if (datastore.type() != typeid(KvpFrame *))
104  return {};
105  auto ret = boost::get<KvpFrame *>(datastore);
106  datastore = new_value;
107  return ret;
108 }

◆ replace_glist_nc()

GList * KvpValue::replace_glist_nc ( GList *  new_value)
noexcept

Replaces the glist within this KvpValueImpl.

If this KvpValueImpl doesn't contain a GList, nullptr is returned. Otherwise, the old GList * is returned.

Definition at line 111 of file kvp-value.cpp.

112 {
113  if (datastore.type() != typeid(GList *))
114  return {};
115  auto ret = boost::get<GList *>(datastore);
116  datastore = new_value;
117  return ret;
118 }

The documentation for this struct was generated from the following files: