GnuCash  2.6.99
kvp-value.hpp
1 /********************************************************************\
2  * kvp-value.hpp -- Implements a key-value frame system *
3  * Copyright (C) 2014 Aaron Laws *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA gnu@gnu.org *
21  * *
22 \********************************************************************/
23 
24 #ifndef GNC_KVP_VALUE_TYPE
25 #define GNC_KVP_VALUE_TYPE
26 
27 extern "C"
28 {
29 #include "config.h"
30 #include "qof.h"
31 }
32 #include <boost/version.hpp>
33 #if BOOST_VERSION == 105600
34 #include <boost/type_traits/is_nothrow_move_assignable.hpp>
35 #endif
36 #include <boost/variant.hpp>
37 
38 //Must be a struct because it's exposed to C so that it can in turn be
39 //translated to/from Scheme.
58 {
59  public:
60  enum Type
61  {
62  INVALID = -1,
63  INT64 = 1,
67  GUID,
69  PLACEHOLDER_DONT_USE, /* Replaces KVP_TYPE_BINARY */
73  };
74 
78  KvpValueImpl(KvpValueImpl const &) noexcept;
79  KvpValueImpl& operator=(const KvpValueImpl&) noexcept;
80 
84  KvpValueImpl(KvpValueImpl && b) noexcept;
85  KvpValueImpl& operator=(KvpValueImpl && b) noexcept;
86 
99  template <typename T>
100  KvpValueImpl(T) noexcept;
101 
107  ~KvpValueImpl() noexcept;
108 
115  KvpFrame * replace_frame_nc (KvpFrame *) noexcept;
116 
123  GList * replace_glist_nc (GList *) noexcept;
124 
136  KvpValueImpl * add (KvpValueImpl *) noexcept;
137 
138  KvpValueImpl::Type get_type() const noexcept;
139 
140  char * to_string() const noexcept;
141 
142  template <typename T>
143  T get() const noexcept;
144 
145  template <typename T>
146  void set(T) noexcept;
147 
148  friend int compare(const KvpValueImpl &, const KvpValueImpl &) noexcept;
149 
150  private:
151  void duplicate(const KvpValueImpl&) noexcept;
152  boost::variant<
153  int64_t,
154  double,
155  gnc_numeric,
156  const char*,
157  GncGUID *,
158  Timespec,
159  GList *,
160  KvpFrame *,
161  GDate> datastore;
162 };
163 
164 int
165 compare(const KvpValueImpl *, const KvpValue *) noexcept;
167 template <typename T>
168 KvpValueImpl::KvpValueImpl(T newvalue) noexcept:
169  datastore(newvalue)
170 {
171 }
172 
173 template <typename T> T
174 KvpValueImpl::get() const noexcept
175 {
176  if (this->datastore.type() != typeid(T)) return {};
177  return boost::get<T>(datastore);
178 }
179 
180 template <typename T> void
181 KvpValueImpl::set(T val) noexcept
182 {
183  this->datastore = val;
184 }
192 GValue* gvalue_from_kvp_value (const KvpValue *kval);
193 
198 KvpValue* kvp_value_from_gvalue (const GValue *gval);
199 
205 void gnc_gvalue_free (GValue *value);
208 extern "C" GType gnc_value_list_get_type (void);
209 #define GNC_TYPE_VALUE_LIST (gnc_value_list_get_type ())
210 
211 #endif
no QOF equivalent.
Definition: kvp-value.hpp:71
KvpFrame * replace_frame_nc(KvpFrame *) noexcept
Replaces the frame within this KvpValueImpl.
Definition: kvp-value.cpp:101
KvpValue * kvp_value_from_gvalue(const GValue *gval)
Convert a gvalue into a kvpvalue.
Definition: kvp_frame.cpp:382
QOF_TYPE_STRING gchar*.
Definition: kvp-value.hpp:66
void gnc_gvalue_free(GValue *value)
Convenience function to release the value in a GValue acquired by kvp_frame_get_gvalue and to free th...
Definition: kvp_frame.cpp:447
QOF_TYPE_NUMERIC.
Definition: kvp-value.hpp:65
QOF_TYPE_DOUBLE gdouble.
Definition: kvp-value.hpp:64
QOF_TYPE_DATE.
Definition: kvp-value.hpp:68
KvpValueImpl * add(KvpValueImpl *) noexcept
Adds another value to this KvpValueImpl.
Definition: kvp-value.cpp:58
Implements KvpValue using boost::variant.
Definition: kvp-value.hpp:57
KvpValueImpl(KvpValueImpl const &) noexcept
Performs a deep copy.
Definition: kvp-value.cpp:32
no QOF equivalent.
Definition: kvp-value.hpp:72
no QOF equivalent.
Definition: kvp-value.hpp:70
~KvpValueImpl() noexcept
Performs a deep delete.
Definition: kvp-value.cpp:380
QOF_TYPE_GUID.
Definition: kvp-value.hpp:67
GList * replace_glist_nc(GList *) noexcept
Replaces the glist within this KvpValueImpl.
Definition: kvp-value.cpp:111
GValue * gvalue_from_kvp_value(const KvpValue *kval)
Convert a kvp_value into a GValue.
Definition: kvp_frame.cpp:315
The type used to store guids in C.
Definition: guid.h:75
QOF_TYPE_INT64 gint64.
Definition: kvp-value.hpp:63