GnuCash  5.6-150-g038405b370+
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...
 
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 >
const T * get_ptr () 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 51 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 54 of file kvp-value.hpp.

55  {
56  INVALID = -1,
57  INT64 = 1,
58  DOUBLE,
59  NUMERIC,
60  STRING,
61  GUID,
62  TIME64,
63  PLACEHOLDER_DONT_USE, /* Replaces KVP_TYPE_BINARY */
64  GLIST,
65  FRAME,
66  GDATE,
67  };
no QOF equivalent.
Definition: kvp-value.hpp:65
QOF_TYPE_STRING gchar*.
Definition: kvp-value.hpp:60
QOF_TYPE_DATE.
Definition: kvp-value.hpp:62
QOF_TYPE_NUMERIC.
Definition: kvp-value.hpp:59
QOF_TYPE_DOUBLE gdouble.
Definition: kvp-value.hpp:58
no QOF equivalent.
Definition: kvp-value.hpp:66
no QOF equivalent.
Definition: kvp-value.hpp:64
QOF_TYPE_GUID.
Definition: kvp-value.hpp:61
QOF_TYPE_INT64 gint64.
Definition: kvp-value.hpp:57

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 46 of file kvp-value.cpp.

47 {
48  datastore = b.datastore;
49  b.datastore = INT64_C(0);
50 }

◆ 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 149 of file kvp-value.hpp.

149  :
150  datastore(newvalue)
151 {
152 }

◆ ~KvpValueImpl()

KvpValue::~KvpValueImpl ( )
noexcept

Performs a deep delete.

The contents of this KvpValueImpl are also deleted.

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

367 {
368  delete_visitor d;
369  boost::apply_visitor(d, datastore);
370 }

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 60 of file kvp-value.cpp.

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

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