GnuCash  4.11-517-g41de4cefce
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 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 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 386 of file kvp-value.cpp.

387 {
388  delete_visitor d;
389  boost::apply_visitor(d, datastore);
390 }

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

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

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

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

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

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