QOF  0.8.7
Files | Data Structures | Macros | Typedefs | Enumerations | Functions
KVP: Key-Value Pairs

Files

file  kvpframe.h
 A key-value frame system.
 
file  kvputil-p.h
 Private KVP utilities for backends etc.
 
file  kvputil.h
 QOF KVP utility functions.
 

Data Structures

struct  GHashTableKVPair
 

Macros

#define QOF_MOD_KVP   "qof-kvp"
 

Typedefs

typedef struct _KvpFrame KvpFrame
 
typedef struct _KvpValue KvpValue
 

Enumerations

enum  KvpValueType {
  KVP_TYPE_GINT64 = 1, KVP_TYPE_DOUBLE, KVP_TYPE_NUMERIC, KVP_TYPE_STRING,
  KVP_TYPE_GUID, KVP_TYPE_TIME, KVP_TYPE_BINARY, KVP_TYPE_GLIST,
  KVP_TYPE_FRAME, KVP_TYPE_BOOLEAN
}
 possible types in the union KvpValue More...
 

Functions

gchar * kvp_value_to_bare_string (const KvpValue *val)
 General purpose function to convert any KvpValue to a string. More...
 
gchar * kvp_value_to_string (const KvpValue *val)
 Debug version. More...
 
gboolean kvp_value_binary_append (KvpValue *v, gpointer data, guint64 size)
 
KvpValueType qof_id_to_kvp_value_type (QofIdTypeConst type_string)
 Convert a QofIdType to a KvpValueType. More...
 
QofIdTypeConst kvp_value_type_to_qof_id (KvpValueType n)
 Convert a KvpValueType to a QofIdType. More...
 
gint kvp_frame_compare (const KvpFrame *fa, const KvpFrame *fb)
 
gchar * kvp_frame_to_string (const KvpFrame *frame)
 
gchar * binary_to_string (const void *data, guint32 size)
 
gchar * kvp_value_glist_to_string (const GList *list)
 
GHashTable * kvp_frame_get_hash (const KvpFrame *frame)
 

KvpFrame Constructors

KvpFramekvp_frame_new (void)
 
void kvp_frame_delete (KvpFrame *frame)
 
KvpFramekvp_frame_copy (const KvpFrame *frame)
 
gboolean kvp_frame_is_empty (KvpFrame *frame)
 

KvpFrame Basic Value Storing

void kvp_frame_set_gint64 (KvpFrame *frame, const gchar *path, gint64 ival)
 store the value of the gint64 at the indicated path. More...
 
void kvp_frame_set_double (KvpFrame *frame, const gchar *path, gdouble dval)
 store the value of the double at the indicated path. More...
 
void kvp_frame_set_numeric (KvpFrame *frame, const gchar *path, QofNumeric nval)
 store the value of the QofNumeric at the indicated path. More...
 
void kvp_frame_set_string (KvpFrame *frame, const gchar *path, const gchar *str)
 Store a copy of the string at the indicated path. More...
 
void kvp_frame_set_guid (KvpFrame *frame, const gchar *path, const GUID *guid)
 Store a copy of the GUID at the indicated path. More...
 
void kvp_frame_set_time (KvpFrame *frame, const gchar *path, QofTime *qt)
 Store a copy of the QofTime at the indicated path. More...
 
void kvp_frame_set_boolean (KvpFrame *frame, const gchar *path, gboolean val)
 Store the value of the boolean at the indicated path. More...
 
void kvp_frame_set_frame (KvpFrame *frame, const gchar *path, KvpFrame *chld)
 Store a copy of the KvpFrame at the indicated path. More...
 
void kvp_frame_set_frame_nc (KvpFrame *frame, const gchar *path, KvpFrame *chld)
 Store a KvpFrame at the indicated path without copying. More...
 
KvpFramekvp_frame_set_value (KvpFrame *frame, const gchar *path, const KvpValue *value)
 Copy the KvpValue into the frame. More...
 
KvpFramekvp_frame_set_value_nc (KvpFrame *frame, const gchar *path, KvpValue *value)
 Store the KvpValue in the frame without copying. More...
 
KvpValuekvp_frame_replace_value_nc (KvpFrame *frame, const gchar *slot, KvpValue *new_value)
 

KvpFrame Glist Bag Storing

void kvp_frame_add_gint64 (KvpFrame *frame, const gchar *path, gint64 ival)
 add the value of the gint64 to the glist bag More...
 
void kvp_frame_add_double (KvpFrame *frame, const gchar *path, gdouble dval)
 Add the value of the double to the glist bag. More...
 
void kvp_frame_add_numeric (KvpFrame *frame, const gchar *path, QofNumeric nval)
 Add the value of the QofNumeric to the glist bag. More...
 
void kvp_frame_add_time (KvpFrame *frame, const gchar *path, QofTime *qt)
 Add the value of the QofTime to the glist bag. More...
 
void kvp_frame_add_string (KvpFrame *frame, const gchar *path, const gchar *str)
 Copy the string to the glist bag at the indicated path. More...
 
void kvp_frame_add_boolean (KvpFrame *frame, const gchar *path, gboolean val)
 
void kvp_frame_add_guid (KvpFrame *frame, const gchar *path, const GUID *guid)
 Copy the GUID to the glist bag at the indicated path. More...
 
void kvp_frame_add_frame (KvpFrame *frame, const gchar *path, KvpFrame *chld)
 Copy the frame to the glist bag at the indicated path. More...
 
void kvp_frame_add_frame_nc (KvpFrame *frame, const gchar *path, KvpFrame *chld)
 Add the frame to the glist bag without copying. More...
 
KvpFramekvp_frame_add_value (KvpFrame *frame, const gchar *path, KvpValue *value)
 Add a copy of the value to the glist bag. More...
 
KvpFramekvp_frame_add_value_nc (KvpFrame *frame, const gchar *path, KvpValue *value)
 

KvpFrame Value Fetching

Value accessors. These all take a unix-style slash-separated path as an argument, and return the value stored at that location. If the object at the end of that path is not of the type that was asked for, then a NULL or a zero is returned. So, for example, asking for a string when the path stored an int will return a NULL. In some future date, this may be changed to a looser type system, such as perl's automatic re-typing (e.g. an integer value might be converted to a printed string representing that value).

If any part of the path does not exist, then NULL or zero will be returned.

The values returned for GUID, binary, GList, KvpFrame and string are "non-copying" – the returned item is the actual item stored. Do not delete this item unless you take the required care to avoid possible bad pointer derefrences (i.e. core dumps). Also, be careful hanging on to those references if you are also storing at the same path names: the referenced item will be freed during the store.

That is, if you get a string value (or guid, binary or frame), and then store something else at that path, the string that you've gotten will be freed during the store (internally, by the set_*() routines), and you will be left hanging onto an invalid pointer.

gint64 kvp_frame_get_gint64 (const KvpFrame *frame, const gchar *path)
 
gdouble kvp_frame_get_double (const KvpFrame *frame, const gchar *path)
 
QofNumeric kvp_frame_get_numeric (const KvpFrame *frame, const gchar *path)
 
gchar * kvp_frame_get_string (const KvpFrame *frame, const gchar *path)
 
GUIDkvp_frame_get_guid (const KvpFrame *frame, const gchar *path)
 
gpointer kvp_frame_get_binary (const KvpFrame *frame, const gchar *path, guint64 *size_return)
 
gboolean kvp_frame_get_boolean (const KvpFrame *frame, const gchar *path)
 
QofTimekvp_frame_get_time (const KvpFrame *frame, const gchar *path)
 
KvpValuekvp_frame_get_value (const KvpFrame *frame, const gchar *path)
 
KvpFramekvp_frame_get_frame (const KvpFrame *frame, const gchar *path)
 
KvpFramekvp_frame_get_frame_path (KvpFrame *frame, const gchar *,...)
 
KvpFramekvp_frame_get_frame_gslist (KvpFrame *frame, GSList *key_path)
 
KvpFramekvp_frame_get_frame_slash (KvpFrame *frame, const gchar *path)
 

KvpFrame KvpValue low-level storing routines.

You probably shouldn't be using these low-level routines

All of the kvp_frame_set_slot_*() routines set the slot values
"destructively", in that if there was an old value there, that
old value is destroyed (and the memory freed).  Thus, one 
should not hang on to value pointers, as these will get 
trashed if set_slot is called on the corresponding key.

If you want the old value, use kvp_frame_replace_slot().
KvpValuekvp_frame_replace_slot_nc (KvpFrame *frame, const gchar *slot, KvpValue *new_value)
 
void kvp_frame_set_slot (KvpFrame *frame, const gchar *key, const KvpValue *value)
 
void kvp_frame_set_slot_nc (KvpFrame *frame, const gchar *key, KvpValue *value)
 
void kvp_frame_set_slot_path (KvpFrame *frame, const KvpValue *value, const gchar *first_key,...)
 
void kvp_frame_set_slot_path_gslist (KvpFrame *frame, const KvpValue *value, GSList *key_path)
 

KvpFrame KvpValue Low-Level Retrieval Routines

You probably shouldn't be using these low-level routines

Returns the KvpValue in the given KvpFrame 'frame' that is associated with 'key'. If there is no key in the frame, NULL is returned. If the value associated with the key is NULL, NULL is returned.

Pointers passed as arguments into get_slot are the responsibility of the caller. Pointers returned by get_slot are owned by the kvp_frame. Make copies as needed.

KvpValuekvp_frame_get_slot (const KvpFrame *frame, const gchar *key)
 
KvpValuekvp_frame_get_slot_path (KvpFrame *frame, const gchar *first_key,...)
 
KvpValuekvp_frame_get_slot_path_gslist (KvpFrame *frame, GSList *key_path)
 
gint kvp_glist_compare (const GList *list1, const GList *list2)
 
GList * kvp_glist_copy (const GList *list)
 
void kvp_glist_delete (GList *list)
 

KvpValue Constructors

The following routines are constructors for kvp_value. Those with pointer arguments copy in the value. The *_nc() versions do not copy in their values, but use them directly.

KvpValuekvp_value_new_gint64 (gint64 value)
 
KvpValuekvp_value_new_double (double value)
 
KvpValuekvp_value_new_numeric (QofNumeric value)
 
KvpValuekvp_value_new_string (const gchar *value)
 
KvpValuekvp_value_new_guid (const GUID *guid)
 
KvpValuekvp_value_new_time (QofTime *value)
 
KvpValuekvp_value_new_boolean (gboolean value)
 
KvpValuekvp_value_new_binary (const void *data, guint64 datasize)
 
KvpValuekvp_value_new_frame (const KvpFrame *value)
 
KvpValuekvp_value_new_glist (const GList *value)
 
KvpValuekvp_value_new_binary_nc (void *data, guint64 datasize)
 
KvpValuekvp_value_new_glist_nc (GList *lst)
 
KvpValuekvp_value_new_frame_nc (KvpFrame *value)
 
void kvp_value_delete (KvpValue *value)
 
KvpValuekvp_value_copy (const KvpValue *value)
 
KvpFramekvp_value_replace_frame_nc (KvpValue *value, KvpFrame *newframe)
 
GList * kvp_value_replace_glist_nc (KvpValue *value, GList *newlist)
 

KvpValue Value access

KvpValueType kvp_value_get_type (const KvpValue *value)
 
gint64 kvp_value_get_gint64 (const KvpValue *value)
 
gdouble kvp_value_get_double (const KvpValue *value)
 
QofNumeric kvp_value_get_numeric (const KvpValue *value)
 
gchar * kvp_value_get_string (const KvpValue *value)
 
GUIDkvp_value_get_guid (const KvpValue *value)
 
gpointer kvp_value_get_binary (const KvpValue *value, guint64 *size_return)
 
GList * kvp_value_get_glist (const KvpValue *value)
 
KvpFramekvp_value_get_frame (const KvpValue *value)
 
gboolean kvp_value_get_boolean (const KvpValue *value)
 
QofTimekvp_value_get_time (const KvpValue *value)
 
gint kvp_value_compare (const KvpValue *va, const KvpValue *vb)
 

Iterators

typedef void(* KvpValueForeachCB) (const gchar *key, KvpValue *value, gpointer data)
 
void kvp_frame_for_each_slot (KvpFrame *f, KvpValueForeachCB, gpointer data)
 

Hash Utilities

GSList * g_hash_table_key_value_pairs (GHashTable *table)
 
void g_hash_table_kv_pair_free_gfunc (gpointer data, gpointer user_data)
 

KvpFrame URL handling

void kvp_frame_add_url_encoding (KvpFrame *frame, const gchar *enc)
 

KvpBag Bags of GUID Pointers

KvpFrameqof_kvp_bag_add (KvpFrame *kvp_root, const gchar *path, QofTime *qt, const gchar *first_name,...)
 
void qof_kvp_bag_merge (KvpFrame *kvp_into, const gchar *intopath, KvpFrame *kvp_from, const gchar *frompath)
 
KvpFrameqof_kvp_bag_find_by_guid (KvpFrame *root, const gchar *path, const gchar *guid_name, GUID *desired_guid)
 
void qof_kvp_bag_remove_frame (KvpFrame *root, const gchar *path, KvpFrame *fr)
 

Detailed Description

A KvpFrame is a set of associations between character strings (keys) and KvpValue structures. A KvpValue is a union with possible types enumerated in the KvpValueType enum, and includes, among other things, ints, doubles, strings, guid's, lists, time and numeric values. KvpValues may also be other frames, so KVP is inherently hierarchical.

Values are stored in a 'slot' associated with a key. Pointers passed as arguments into set_slot and get_slot are the responsibility of the caller. Pointers returned by get_slot are owned by the kvp_frame. Make copies as needed.

A 'path' is a sequence of keys that can be followed to a value. Paths may be specified as varargs (variable number of arguments to a subrutine, NULL-terminated), as a GSList, or as a standard URL-like path name. The later is parsed and treated in the same way as file paths would be: / separates keys, /./ is treated as / and /../ means backup one level. Repeated slashes are treated as one slash.

Note that although, in principle, keys may contain the / and . and .. characters, doing so may lead to confusion, and will make path-string parsing routines fail. In other words, don't use a key such as 'some/key' or 'some/./other/../key' because you may get unexpected results.

To set a value into a frame, you will want to use one of the kvp_frame_set_xxx() routines. Most of the other routines provide only low-level access that you probably shouldn't use.

Typedef Documentation

typedef struct _KvpFrame KvpFrame

Opaque frame structure

Definition at line 74 of file kvpframe.h.

typedef struct _KvpValue KvpValue

A KvpValue is a union with possible types enumerated in the KvpValueType enum.

Definition at line 78 of file kvpframe.h.

typedef void(* KvpValueForeachCB) (const gchar *key, KvpValue *value, gpointer data)
Since
0.7.2

Definition at line 766 of file kvpframe.h.

Enumeration Type Documentation

possible types in the union KvpValue

Todo:
In the long run, this could be synchronised with the core QOF types, which in turn may or may not be synced to the GValue types in GLib. The QOF types currently unsupported are KVP_TYPE_GLIST and KVP_TYPE_BINARY.
Enumerator
KVP_TYPE_GINT64 

64bit integer

  • QofType : QOF_TYPE_INT64
  • GType : G_TYPE_INT64
  • GLib type : gint64
KVP_TYPE_DOUBLE 

standard C double type

  • QofType : QOF_TYPE_DOUBLE
  • GType : G_TYPE_DOUBLE
  • GLib type : gdouble
KVP_TYPE_NUMERIC 

128bit denominator/numerator maths.

  • QofType : QOF_TYPE_NUMERIC
  • GType : no direct equivalent, consider QOF_TYPE_DOUBLE
  • GLib type : no direct equivalent, consider QOF_TYPE_DOUBLE
KVP_TYPE_STRING 

standard C string

  • QofType : QOF_TYPE_STRING
  • GType : G_TYPE_STRING
  • GLib type : gchar*
KVP_TYPE_GUID 

Unique identifier.

  • QofType : QOF_TYPE_GUID
  • GType : no direct equivalent, can be stored as QOF_TYPE_STRING
  • GLib : no direct equivalent, can be stored as QOF_TYPE_STRING
KVP_TYPE_TIME 

64bit time/date handling.

  • QofType : QOF_TYPE_TIME
  • GType : No equivalent.
  • GLib type : GDate (not fully equivalent, see QofTime)
KVP_TYPE_BINARY 

no QofType/GType/GLib equivalent.

KVP_TYPE_GLIST 

no QofType/GType equivalent.

KVP_TYPE_FRAME 

no QofType/GType/GLib equivalent.

KVP_TYPE_BOOLEAN 

Simple boolean type.

  • QofType : QOF_TYPE_BOOLEAN
  • GType : G_TYPE_BOOLEAN
  • GLib type : gboolean

Definition at line 87 of file kvpframe.h.

88 {
94  KVP_TYPE_GINT64 = 1,
137 } KvpValueType;
KvpValueType
possible types in the union KvpValue
Definition: kvpframe.h:87
Unique identifier.
Definition: kvpframe.h:118
128bit denominator/numerator maths.
Definition: kvpframe.h:106
64bit integer
Definition: kvpframe.h:94
Simple boolean type.
Definition: kvpframe.h:136
standard C string
Definition: kvpframe.h:112
standard C double type
Definition: kvpframe.h:100
64bit time/date handling.
Definition: kvpframe.h:124

Function Documentation

GSList* g_hash_table_key_value_pairs ( GHashTable *  table)

Returns a GSList* of all the keys and values in a given hash table. Data elements of lists are actual hash elements, so be careful, and deallocation of the GHashTableKVPairs in the result list are the caller's responsibility. A typical sequence might look like this:

GSList *kvps = g_hash_table_key_value_pairs(hash); ... use kvps->data->key and kvps->data->val, etc. here ... g_slist_foreach(kvps, g_hash_table_kv_pair_free_gfunc, NULL); g_slist_free(kvps);

Definition at line 212 of file kvputil.c.

213 {
214  GSList *result_list = NULL;
215  g_hash_table_foreach (table, kv_pair_helper, &result_list);
216  return result_list;
217 }
void kvp_frame_add_double ( KvpFrame frame,
const gchar *  path,
gdouble  dval 
)

Add the value of the double to the glist bag.

If not all frame components of the path exist, they are created. If the value previously stored at this path was not a glist bag, then a bag will be formed there, the old value placed in the bag, and the new value added to the bag.

Definition at line 598 of file kvpframe.c.

599 {
600  KvpValue *value;
601  value = kvp_value_new_double (dval);
602  frame = kvp_frame_add_value_nc (frame, path, value);
603  if (!frame)
604  kvp_value_delete (value);
605 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_add_frame ( KvpFrame frame,
const gchar *  path,
KvpFrame chld 
)

Copy the frame to the glist bag at the indicated path.

If not all frame components of the path exist, they are created. If there was another item previously stored at that path, then the path is converted to a bag, and the old value, along with the new value, is added to the bag.

Definition at line 659 of file kvpframe.c.

660 {
661  KvpValue *value;
662  value = kvp_value_new_frame (fr);
663  frame = kvp_frame_add_value_nc (frame, path, value);
664  if (!frame)
665  kvp_value_delete (value);
666 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_add_frame_nc ( KvpFrame frame,
const gchar *  path,
KvpFrame chld 
)

Add the frame to the glist bag without copying.

If not all frame components of the path exist, they are created. If there was another item previously stored at that path, then the path is converted to a bag, and the old value, along with the new value, is added to the bag.

Definition at line 669 of file kvpframe.c.

670 {
671  KvpValue *value;
672  value = kvp_value_new_frame_nc (fr);
673  frame = kvp_frame_add_value_nc (frame, path, value);
674  if (!frame)
675  kvp_value_delete (value);
676 }
KvpValue * kvp_value_new_frame_nc(KvpFrame *value)
Definition: kvpframe.c:1345
struct _KvpValue KvpValue
Definition: kvpframe.h:78
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_add_gint64 ( KvpFrame frame,
const gchar *  path,
gint64  ival 
)

add the value of the gint64 to the glist bag

If not all frame components of the path exist, they are created. If the value previously stored at this path was not a glist bag, then a bag will be formed there, the old value placed in the bag, and the new value added to the bag.

Definition at line 588 of file kvpframe.c.

589 {
590  KvpValue *value;
591  value = kvp_value_new_gint64 (ival);
592  frame = kvp_frame_add_value_nc (frame, path, value);
593  if (!frame)
594  kvp_value_delete (value);
595 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_add_guid ( KvpFrame frame,
const gchar *  path,
const GUID guid 
)

Copy the GUID to the glist bag at the indicated path.

If not all frame components of the path exist, they are created. If there was another item previously stored at that path, then the path is converted to a bag, and the old value, along with the new value, is added to the bag.

Definition at line 649 of file kvpframe.c.

650 {
651  KvpValue *value;
652  value = kvp_value_new_guid (guid);
653  frame = kvp_frame_add_value_nc (frame, path, value);
654  if (!frame)
655  kvp_value_delete (value);
656 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_add_numeric ( KvpFrame frame,
const gchar *  path,
QofNumeric  nval 
)

Add the value of the QofNumeric to the glist bag.

If not all frame components of the path exist, they are created. If the value previously stored at this path was not a glist bag, then a bag will be formed there, the old value placed in the bag, and the new value added to the bag.

Definition at line 608 of file kvpframe.c.

610 {
611  KvpValue *value;
612  value = kvp_value_new_numeric (nval);
613  frame = kvp_frame_add_value_nc (frame, path, value);
614  if (!frame)
615  kvp_value_delete (value);
616 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_add_string ( KvpFrame frame,
const gchar *  path,
const gchar *  str 
)

Copy the string to the glist bag at the indicated path.

If not all frame components of the path exist, they are created. If there was another item previously stored at that path, then the path is converted to a bag, and the old value, along with the new value, is added to the bag.

Definition at line 639 of file kvpframe.c.

640 {
641  KvpValue *value;
642  value = kvp_value_new_string (str);
643  frame = kvp_frame_add_value_nc (frame, path, value);
644  if (!frame)
645  kvp_value_delete (value);
646 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_add_time ( KvpFrame frame,
const gchar *  path,
QofTime qt 
)

Add the value of the QofTime to the glist bag.

If not all frame components of the path exist, they are created. If the value previously stored at this path was not a glist bag, then a bag will be formed there, the old value placed in the bag, and the new value added to the bag.

Definition at line 619 of file kvpframe.c.

620 {
621  KvpValue *value;
622  value = kvp_value_new_time (qt);
623  frame = kvp_frame_add_value_nc (frame, path, value);
624  if (!frame)
625  kvp_value_delete (value);
626 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_add_url_encoding ( KvpFrame frame,
const gchar *  enc 
)

The kvp_frame_add_url_encoding() routine will parse the value string, assuming it to be URL-encoded in the standard way, turning it into a set of key-value pairs, and adding those to the indicated frame. URL-encoded strings are the things that are returned by web browsers when a form is filled out. For example, 'start-date=June&end-date=November' consists of two keys, 'start-date' and 'end-date', which have the values 'June' and 'November', respectively. This routine also handles % encoding.

This routine treats all values as strings; it does not attempt to perform any type-conversion.

Definition at line 877 of file kvpframe.c.

878 {
879  gchar *buff, *p;
880  if (!frame || !enc)
881  return;
882 
883  /* Loop over all key-value pairs in the encoded string */
884  buff = g_strdup (enc);
885  p = buff;
886  while (*p)
887  {
888  gchar *n, *v;
889  n = strchr (p, '&'); /* n = next key-value */
890  if (n)
891  *n = 0x0;
892 
893  v = strchr (p, '='); /* v = pointer to value */
894  if (!v)
895  break;
896  *v = 0x0;
897  v++;
898 
899  decode (p);
900  decode (v);
901  kvp_frame_set_slot_nc (frame, p, kvp_value_new_string (v));
902 
903  if (!n)
904  break; /* no next key, we are done */
905  p = ++n;
906  }
907 
908  g_free (buff);
909 }
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *slot, KvpValue *value)
Definition: kvpframe.c:697
KvpFrame* kvp_frame_add_value ( KvpFrame frame,
const gchar *  path,
KvpValue value 
)

Add a copy of the value to the glist bag.

If not all frame components of the path exist, they are created. If there was another item previously stored at that path, then the path is converted to a bag, and the old value, along with the new value, is added to the bag. This routine returns the pointer to the last frame (the actual frame to which the value was added), or NULL if there was an error of any sort (typically, a parse error in the path).

Definition at line 578 of file kvpframe.c.

579 {
580  value = kvp_value_copy (value);
581  frame = kvp_frame_add_value_nc (frame, path, value);
582  if (!frame)
583  kvp_value_delete (value);
584  return frame;
585 }
KvpValue * kvp_value_copy(const KvpValue *value)
Definition: kvpframe.c:1598
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
gint kvp_frame_compare ( const KvpFrame fa,
const KvpFrame fb 
)

Similar returns as strcmp.

Definition at line 1743 of file kvpframe.c.

1744 {
1745  KvpFrameCompare status;
1746 
1747  if (fa == fb)
1748  return 0;
1749  /* nothing is always less than something */
1750  if (!fa && fb)
1751  return -1;
1752  if (fa && !fb)
1753  return 1;
1754 
1755  /* nothing is always less than something */
1756  if (!fa->hash && fb->hash)
1757  return -1;
1758  if (fa->hash && !fb->hash)
1759  return 1;
1760 
1761  status.compare = 0;
1762  status.other_frame = (KvpFrame *) fb;
1763 
1764  kvp_frame_for_each_slot ((KvpFrame *) fa, kvp_frame_compare_helper,
1765  &status);
1766 
1767  if (status.compare != 0)
1768  return status.compare;
1769 
1770  status.other_frame = (KvpFrame *) fa;
1771 
1772  kvp_frame_for_each_slot ((KvpFrame *) fb, kvp_frame_compare_helper,
1773  &status);
1774 
1775  return (-status.compare);
1776 }
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
void kvp_frame_for_each_slot(KvpFrame *f, KvpValueForeachCB proc, gpointer data)
Definition: kvpframe.c:1642
KvpFrame* kvp_frame_copy ( const KvpFrame frame)

Perform a deep (recursive) value copy, copying the frame, subframes, and the values as well.

Definition at line 153 of file kvpframe.c.

154 {
155  KvpFrame *retval = kvp_frame_new ();
156 
157  if (!frame)
158  return retval;
159 
160  if (frame->hash)
161  {
162  if (!init_frame_body_if_needed (retval))
163  return (NULL);
164  g_hash_table_foreach (frame->hash,
165  &kvp_frame_copy_worker, (gpointer) retval);
166  }
167  return retval;
168 }
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
KvpFrame * kvp_frame_new(void)
Definition: kvpframe.c:97
void kvp_frame_delete ( KvpFrame frame)

Perform a deep (recursive) delete of the frame and any subframes.

Definition at line 115 of file kvpframe.c.

116 {
117  if (!frame)
118  return;
119 
120  if (frame->hash)
121  {
122  /* free any allocated resource for frame or its children */
123  g_hash_table_foreach (frame->hash, &kvp_frame_delete_worker,
124  (gpointer) frame);
125 
126  /* delete the hash table */
127  g_hash_table_destroy (frame->hash);
128  frame->hash = NULL;
129  }
130  g_free (frame);
131 }
void kvp_frame_for_each_slot ( KvpFrame f,
KvpValueForeachCB  ,
gpointer  data 
)

Traverse all of the slots in the given kvp_frame. This function does not descend recursively to traverse any kvp_frames stored as slot values. You must handle that in proc, with a suitable recursive call if desired.

Definition at line 1642 of file kvpframe.c.

1643 {
1644  if (!f)
1645  return;
1646  if (!proc)
1647  return;
1648  if (!(f->hash))
1649  return;
1650  g_hash_table_foreach (f->hash, (GHFunc) proc, data);
1651 }
KvpFrame* kvp_frame_get_frame ( const KvpFrame frame,
const gchar *  path 
)

Value accessor. Takes a unix-style slash-separated path as an argument, and return the KvpFrame stored at that location. If the KvpFrame does not exist, then a NULL is returned.

Returns
The KvpFrame at the specified path, or NULL if it doesn't exist.

Definition at line 981 of file kvpframe.c.

982 {
983  gchar *key = NULL;
984  frame = get_trailer_or_null (frame, path, &key);
985  return kvp_value_get_frame (kvp_frame_get_slot (frame, key));
986 }
KvpFrame * kvp_value_get_frame(const KvpValue *value)
Definition: kvpframe.c:1546
KvpFrame* kvp_frame_get_frame_gslist ( KvpFrame frame,
GSList *  key_path 
)

This routine returns the last frame of the path. If the frame path doesn't exist, it is created. Note that this is VERY DIFFERENT FROM kvp_frame_get_frame()

Definition at line 999 of file kvpframe.c.

1000 {
1001  if (!frame)
1002  return frame;
1003 
1004  while (key_path)
1005  {
1006  const gchar *key = key_path->data;
1007 
1008  if (!key)
1009  return frame; /* an unusual but valid exit for this routine. */
1010 
1011  frame = get_or_make (frame, key);
1012  if (!frame)
1013  return frame; /* this should never happen */
1014 
1015  key_path = key_path->next;
1016  }
1017  return frame; /* this is the normal exit for this func */
1018 }
KvpFrame* kvp_frame_get_frame_path ( KvpFrame frame,
const gchar *  ,
  ... 
)

This routine returns the last frame of the path. If the frame path doesn't exist, it is created. Note that this is VERY DIFFERENT FROM kvp_frame_get_frame()

Definition at line 1021 of file kvpframe.c.

1022 {
1023  va_list ap;
1024  if (!frame || !key)
1025  return frame;
1026 
1027  va_start (ap, key);
1028 
1029  while (key)
1030  {
1031  frame = get_or_make (frame, key);
1032  if (!frame)
1033  break; /* error, should never occur */
1034  key = va_arg (ap, const char *);
1035  }
1036 
1037  va_end (ap);
1038  return frame;
1039 }
KvpFrame* kvp_frame_get_frame_slash ( KvpFrame frame,
const gchar *  path 
)

This routine returns the last frame of the path. If the frame path doesn't exist, it is created. Note that this is VERY DIFFERENT FROM kvp_frame_get_frame()

The kvp_frame_get_frame_slash() routine takes a single string where the keys are separated by slashes; thus, for example: /this/is/a/valid/path and///so//is////this/ Multiple slashes are compresed. Leading slash is optional. The pointers . and .. are not currently followed/obeyed. (This is a bug that needs fixing).

Definition at line 1042 of file kvpframe.c.

1043 {
1044  gchar *root;
1045  if (!frame || !key_path)
1046  return frame;
1047 
1048  root = g_strdup (key_path);
1049  frame = kvp_frame_get_frame_slash_trash (frame, root);
1050  g_free (root);
1051  return frame;
1052 }
KvpValue* kvp_frame_get_slot_path ( KvpFrame frame,
const gchar *  first_key,
  ... 
)

This routine return the value at the end of the path, or NULL if any portion of the path doesn't exist.

Definition at line 1057 of file kvpframe.c.

1058 {
1059  va_list ap;
1060  KvpValue *value;
1061  const gchar *key;
1062 
1063  if (!frame || !first_key)
1064  return NULL;
1065 
1066  va_start (ap, first_key);
1067 
1068  key = first_key;
1069  value = NULL;
1070 
1071  while (TRUE)
1072  {
1073  value = kvp_frame_get_slot (frame, key);
1074  if (!value)
1075  break;
1076 
1077  key = va_arg (ap, const gchar *);
1078  if (!key)
1079  break;
1080 
1081  frame = kvp_value_get_frame (value);
1082  if (!frame)
1083  {
1084  value = NULL;
1085  break;
1086  }
1087  }
1088 
1089  va_end (ap);
1090 
1091  return value;
1092 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame * kvp_value_get_frame(const KvpValue *value)
Definition: kvpframe.c:1546
KvpValue* kvp_frame_get_slot_path_gslist ( KvpFrame frame,
GSList *  key_path 
)

This routine return the value at the end of the path, or NULL if any portion of the path doesn't exist.

Definition at line 1095 of file kvpframe.c.

1096 {
1097  if (!frame || !key_path)
1098  return NULL;
1099 
1100  while (TRUE)
1101  {
1102  const gchar *key = key_path->data;
1103  KvpValue *value;
1104 
1105  if (!key)
1106  return NULL;
1107 
1108  value = kvp_frame_get_slot (frame, key);
1109  if (!value)
1110  return NULL;
1111 
1112  key_path = key_path->next;
1113  if (!key_path)
1114  return value;
1115 
1116  frame = kvp_value_get_frame (value);
1117  if (!frame)
1118  return NULL;
1119  }
1120 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame * kvp_value_get_frame(const KvpValue *value)
Definition: kvpframe.c:1546
gboolean kvp_frame_is_empty ( KvpFrame frame)

Return TRUE if the KvpFrame is empty

Definition at line 134 of file kvpframe.c.

135 {
136  if (!frame)
137  return TRUE;
138  if (!frame->hash)
139  return TRUE;
140  return FALSE;
141 }
KvpFrame* kvp_frame_new ( void  )

Return a new empty instance of KvpFrame

Definition at line 97 of file kvpframe.c.

98 {
99  KvpFrame *retval = g_new0 (KvpFrame, 1);
100 
101  /* Save space until the frame is actually used */
102  retval->hash = NULL;
103  return retval;
104 }
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
KvpValue* kvp_frame_replace_slot_nc ( KvpFrame frame,
const gchar *  slot,
KvpValue new_value 
)

The kvp_frame_replace_slot_nc() routine places the new value into the indicated frame, for the given key. It returns the old value, if any. It returns NULL if the slot doesn't exist, if there was some other an error, or if there was no old value. Passing in a NULL new_value has the effect of deleting that slot.

Definition at line 175 of file kvpframe.c.

177 {
178  gpointer orig_key;
179  gpointer orig_value = NULL;
180  int key_exists;
181 
182  if (!frame || !slot)
183  return NULL;
184  if (!init_frame_body_if_needed (frame))
185  return NULL; /* Error ... */
186 
187  key_exists = g_hash_table_lookup_extended (frame->hash, slot,
188  &orig_key, &orig_value);
189  if (key_exists)
190  {
191  g_hash_table_remove (frame->hash, slot);
192  qof_util_string_cache_remove (orig_key);
193  }
194  else
195  orig_value = NULL;
196  if (new_value)
197  g_hash_table_insert (frame->hash,
198  qof_util_string_cache_insert ((gpointer) slot), new_value);
199  return (KvpValue *) orig_value;
200 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
gpointer qof_util_string_cache_insert(gconstpointer key)
Definition: qofutil.c:456
void qof_util_string_cache_remove(gconstpointer key)
Definition: qofutil.c:450
KvpValue* kvp_frame_replace_value_nc ( KvpFrame frame,
const gchar *  slot,
KvpValue new_value 
)

The kvp_frame_replace_value_nc() routine places the new value at the indicated path. It returns the old value, if any. It returns NULL if there was an error, or if there was no old value. If the path doesn't exist, it is created, unless new_value is NULL. Passing in a NULL new_value has the effect of deleting the trailing slot (i.e. the trailing path element).

Definition at line 513 of file kvpframe.c.

515 {
516  KvpValue *old_value;
517  gchar *last_key;
518 
519  last_key = NULL;
520  if (new_value)
521  frame = get_trailer_make (frame, key_path, &last_key);
522  else
523  frame =
524  (KvpFrame *) get_trailer_or_null (frame, key_path, &last_key);
525  if (!frame)
526  return NULL;
527 
528  old_value = kvp_frame_replace_slot_nc (frame, last_key, new_value);
529  return old_value;
530 }
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpValue * kvp_frame_replace_slot_nc(KvpFrame *frame, const gchar *slot, KvpValue *new_value)
Definition: kvpframe.c:175
void kvp_frame_set_boolean ( KvpFrame frame,
const gchar *  path,
gboolean  val 
)

Store the value of the boolean at the indicated path.

If not all frame components of the path exist, they are created.

Definition at line 428 of file kvpframe.c.

430 {
431  KvpValue * value;
432  value = kvp_value_new_boolean (val);
433  frame = kvp_frame_set_value_nc (frame, path, value);
434  if (!frame)
435  kvp_value_delete (value);
436 }
KvpValue * kvp_value_new_boolean(gboolean value)
Definition: kvpframe.c:1223
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame * kvp_frame_set_value_nc(KvpFrame *frame, const gchar *key_path, KvpValue *value)
Store the KvpValue in the frame without copying.
Definition: kvpframe.c:483
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_set_double ( KvpFrame frame,
const gchar *  path,
gdouble  dval 
)

store the value of the double at the indicated path.

If not all frame components of the path exist, they are created.

Definition at line 397 of file kvpframe.c.

398 {
399  KvpValue *value;
400  value = kvp_value_new_double (dval);
401  frame = kvp_frame_set_value_nc (frame, path, value);
402  if (!frame)
403  kvp_value_delete (value);
404 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame * kvp_frame_set_value_nc(KvpFrame *frame, const gchar *key_path, KvpValue *value)
Store the KvpValue in the frame without copying.
Definition: kvpframe.c:483
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_set_frame ( KvpFrame frame,
const gchar *  path,
KvpFrame chld 
)

Store a copy of the KvpFrame at the indicated path.

If not all frame components of the path exist, they are created. If there was another QofTime previously stored at that path, the old frame is deleted.

Definition at line 461 of file kvpframe.c.

462 {
463  KvpValue *value;
464  value = kvp_value_new_frame (fr);
465  frame = kvp_frame_set_value_nc (frame, path, value);
466  if (!frame)
467  kvp_value_delete (value);
468 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame * kvp_frame_set_value_nc(KvpFrame *frame, const gchar *key_path, KvpValue *value)
Store the KvpValue in the frame without copying.
Definition: kvpframe.c:483
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_set_frame_nc ( KvpFrame frame,
const gchar *  path,
KvpFrame chld 
)

Store a KvpFrame at the indicated path without copying.

If not all frame components of the path exist, they are created. If there was another QofTime previously stored at that path, the old frame is deleted.

Definition at line 471 of file kvpframe.c.

472 {
473  KvpValue *value;
474  value = kvp_value_new_frame_nc (fr);
475  frame = kvp_frame_set_value_nc (frame, path, value);
476  if (!frame)
477  kvp_value_delete (value);
478 }
KvpValue * kvp_value_new_frame_nc(KvpFrame *value)
Definition: kvpframe.c:1345
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame * kvp_frame_set_value_nc(KvpFrame *frame, const gchar *key_path, KvpValue *value)
Store the KvpValue in the frame without copying.
Definition: kvpframe.c:483
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_set_gint64 ( KvpFrame frame,
const gchar *  path,
gint64  ival 
)

store the value of the gint64 at the indicated path.

If not all frame components of the path exist, they are created.

Definition at line 387 of file kvpframe.c.

388 {
389  KvpValue *value;
390  value = kvp_value_new_gint64 (ival);
391  frame = kvp_frame_set_value_nc (frame, path, value);
392  if (!frame)
393  kvp_value_delete (value);
394 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame * kvp_frame_set_value_nc(KvpFrame *frame, const gchar *key_path, KvpValue *value)
Store the KvpValue in the frame without copying.
Definition: kvpframe.c:483
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_set_guid ( KvpFrame frame,
const gchar *  path,
const GUID guid 
)

Store a copy of the GUID at the indicated path.

If not all frame components of the path exist, they are created. If there was another GUID previously stored at that path, the old copy is deleted.

Definition at line 450 of file kvpframe.c.

452 {
453  KvpValue *value;
454  value = kvp_value_new_guid (guid);
455  frame = kvp_frame_set_value_nc (frame, path, value);
456  if (!frame)
457  kvp_value_delete (value);
458 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame * kvp_frame_set_value_nc(KvpFrame *frame, const gchar *key_path, KvpValue *value)
Store the KvpValue in the frame without copying.
Definition: kvpframe.c:483
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_set_numeric ( KvpFrame frame,
const gchar *  path,
QofNumeric  nval 
)

store the value of the QofNumeric at the indicated path.

If not all frame components of the path exist, they are created.

Definition at line 417 of file kvpframe.c.

419 {
420  KvpValue *value;
421  value = kvp_value_new_numeric (nval);
422  frame = kvp_frame_set_value_nc (frame, path, value);
423  if (!frame)
424  kvp_value_delete (value);
425 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame * kvp_frame_set_value_nc(KvpFrame *frame, const gchar *key_path, KvpValue *value)
Store the KvpValue in the frame without copying.
Definition: kvpframe.c:483
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_set_slot ( KvpFrame frame,
const gchar *  key,
const KvpValue value 
)

The kvp_frame_set_slot() routine copies the value into the frame, associating it with a copy of 'key'. Pointers passed as arguments into kvp_frame_set_slot are the responsibility of the caller; the pointers are not taken over or managed. The old value at this location, if any, is destroyed.

Definition at line 681 of file kvpframe.c.

683 {
684  KvpValue *new_value = NULL;
685 
686  if (!frame)
687  return;
688 
689  g_return_if_fail (slot && *slot != '\0');
690 
691  if (value)
692  new_value = kvp_value_copy (value);
693  kvp_frame_set_slot_destructively (frame, slot, new_value);
694 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpValue * kvp_value_copy(const KvpValue *value)
Definition: kvpframe.c:1598
void kvp_frame_set_slot_nc ( KvpFrame frame,
const gchar *  key,
KvpValue value 
)

The kvp_frame_set_slot_nc() routine puts the value (without copying it) into the frame, associating it with a copy of 'key'. This routine is handy for avoiding excess memory allocations & frees. Note that because the KvpValue was grabbed, you can't just delete unless you remove the key as well (or unless you replace the value). The old value at this location, if any, is destroyed.

Definition at line 697 of file kvpframe.c.

699 {
700  if (!frame)
701  return;
702 
703  g_return_if_fail (slot && *slot != '\0');
704 
705  kvp_frame_set_slot_destructively (frame, slot, value);
706 }
void kvp_frame_set_slot_path ( KvpFrame frame,
const KvpValue value,
const gchar *  first_key,
  ... 
)

The kvp_frame_set_slot_path() routine walks the hierarchy, using the key values to pick each branch. When the terminal node is reached, the value is copied into it. The old value at this location, if any, is destroyed.

Definition at line 723 of file kvpframe.c.

725 {
726  va_list ap;
727  const gchar *key;
728 
729  if (!frame)
730  return;
731 
732  g_return_if_fail (first_key && *first_key != '\0');
733 
734  va_start (ap, first_key);
735 
736  key = first_key;
737 
738  while (TRUE)
739  {
740  KvpValue *value;
741  const gchar *next_key;
742 
743  next_key = va_arg (ap, const gchar *);
744  if (!next_key)
745  {
746  kvp_frame_set_slot (frame, key, new_value);
747  break;
748  }
749 
750  g_return_if_fail (*next_key != '\0');
751 
752  value = kvp_frame_get_slot (frame, key);
753  if (!value)
754  {
755  KvpFrame *new_frame = kvp_frame_new ();
756  KvpValue *frame_value = kvp_value_new_frame (new_frame);
757 
758  kvp_frame_set_slot_nc (frame, key, frame_value);
759 
760  value = kvp_frame_get_slot (frame, key);
761  if (!value)
762  break;
763  }
764 
765  frame = kvp_value_get_frame (value);
766  if (!frame)
767  break;
768 
769  key = next_key;
770  }
771 
772  va_end (ap);
773 }
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
struct _KvpValue KvpValue
Definition: kvpframe.h:78
void kvp_frame_set_slot(KvpFrame *frame, const gchar *slot, const KvpValue *value)
Definition: kvpframe.c:681
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *slot, KvpValue *value)
Definition: kvpframe.c:697
KvpFrame * kvp_frame_new(void)
Definition: kvpframe.c:97
KvpFrame * kvp_value_get_frame(const KvpValue *value)
Definition: kvpframe.c:1546
void kvp_frame_set_slot_path_gslist ( KvpFrame frame,
const KvpValue value,
GSList *  key_path 
)

The kvp_frame_set_slot_path_gslist() routine walks the hierarchy, using the key values to pick each branch. When the terminal node is reached, the value is copied into it. The old value at this location, if any, is destroyed.

Definition at line 776 of file kvpframe.c.

778 {
779  if (!frame || !key_path)
780  return;
781 
782  while (TRUE)
783  {
784  const gchar *key = key_path->data;
785  KvpValue *value;
786 
787  if (!key)
788  return;
789 
790  g_return_if_fail (*key != '\0');
791 
792  key_path = key_path->next;
793  if (!key_path)
794  {
795  kvp_frame_set_slot (frame, key, new_value);
796  return;
797  }
798 
799  value = kvp_frame_get_slot (frame, key);
800  if (!value)
801  {
802  KvpFrame *new_frame = kvp_frame_new ();
803  KvpValue *frame_value = kvp_value_new_frame (new_frame);
804 
805  kvp_frame_set_slot_nc (frame, key, frame_value);
806 
807  value = kvp_frame_get_slot (frame, key);
808  if (!value)
809  return;
810  }
811 
812  frame = kvp_value_get_frame (value);
813  if (!frame)
814  return;
815  }
816 }
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
struct _KvpValue KvpValue
Definition: kvpframe.h:78
void kvp_frame_set_slot(KvpFrame *frame, const gchar *slot, const KvpValue *value)
Definition: kvpframe.c:681
void kvp_frame_set_slot_nc(KvpFrame *frame, const gchar *slot, KvpValue *value)
Definition: kvpframe.c:697
KvpFrame * kvp_frame_new(void)
Definition: kvpframe.c:97
KvpFrame * kvp_value_get_frame(const KvpValue *value)
Definition: kvpframe.c:1546
void kvp_frame_set_string ( KvpFrame frame,
const gchar *  path,
const gchar *  str 
)

Store a copy of the string at the indicated path.

If not all frame components of the path exist, they are created. If there was another string previously stored at that path, the old copy is deleted.

Definition at line 439 of file kvpframe.c.

441 {
442  KvpValue *value;
443  value = kvp_value_new_string (str);
444  frame = kvp_frame_set_value_nc (frame, path, value);
445  if (!frame)
446  kvp_value_delete (value);
447 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame * kvp_frame_set_value_nc(KvpFrame *frame, const gchar *key_path, KvpValue *value)
Store the KvpValue in the frame without copying.
Definition: kvpframe.c:483
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
void kvp_frame_set_time ( KvpFrame frame,
const gchar *  path,
QofTime qt 
)

Store a copy of the QofTime at the indicated path.

If not all frame components of the path exist, they are created. If there was another QofTime previously stored at that path, the old copy is deleted.

Definition at line 407 of file kvpframe.c.

408 {
409  KvpValue *value;
410  value = kvp_value_new_time (qt);
411  frame = kvp_frame_set_value_nc (frame, path, value);
412  if (!frame)
413  kvp_value_delete (value);
414 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame * kvp_frame_set_value_nc(KvpFrame *frame, const gchar *key_path, KvpValue *value)
Store the KvpValue in the frame without copying.
Definition: kvpframe.c:483
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
KvpFrame* kvp_frame_set_value ( KvpFrame frame,
const gchar *  path,
const KvpValue value 
)

Copy the KvpValue into the frame.

If the path contains slashes '/', these are assumed to represent a sequence of keys. The old value at this location, if any, is destroyed.

Pointers passed as arguments into this routine remain the responsibility of the caller.

Parameters
frameThe frame to hold the copied value.
pathThe location of the value in the frame.
valueThe value to be copied.
Returns
a pointer to the actual frame into which the value was inserted or NULL if the frame could not be found.

Definition at line 496 of file kvpframe.c.

498 {
499  KvpValue *new_value = NULL;
500  gchar *last_key;
501 
502  frame = get_trailer_make (frame, key_path, &last_key);
503  if (!frame)
504  return NULL;
505 
506  if (value)
507  new_value = kvp_value_copy (value);
508  kvp_frame_set_slot_destructively (frame, last_key, new_value);
509  return frame;
510 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpValue * kvp_value_copy(const KvpValue *value)
Definition: kvpframe.c:1598
KvpFrame* kvp_frame_set_value_nc ( KvpFrame frame,
const gchar *  path,
KvpValue value 
)

Store the KvpValue in the frame without copying.

If the path contains slashes '/', these are assumed to represent a sequence of keys.

 The returned value is a pointer to the actual frame into which the value 
  was inserted; it is NULL if the frame couldn't be found (and thus the 
  value wasn't inserted).  The old value at this location, if any,
  is destroyed.

  This routine is handy for avoiding excess memory allocations & frees.
  Note that because the KvpValue was grabbed, you can't just delete 
  unless you remove the key as well (or unless you replace the value).

Definition at line 483 of file kvpframe.c.

485 {
486  gchar *last_key;
487 
488  frame = get_trailer_make (frame, key_path, &last_key);
489  if (!frame)
490  return NULL;
491  kvp_frame_set_slot_destructively (frame, last_key, value);
492  return frame;
493 }
gint kvp_glist_compare ( const GList *  list1,
const GList *  list2 
)

kvp_glist_compare() compares GLists of KvpValue values (not to be confused with GLists of something else): it iterates over the list elements, performing a kvp_value_compare on each.

Definition at line 1167 of file kvpframe.c.

1168 {
1169  const GList *lp1;
1170  const GList *lp2;
1171 
1172  if (list1 == list2)
1173  return 0;
1174 
1175  /* Nothing is always less than something */
1176  if (!list1 && list2)
1177  return -1;
1178  if (list1 && !list2)
1179  return 1;
1180 
1181  lp1 = list1;
1182  lp2 = list2;
1183  while (lp1 && lp2)
1184  {
1185  KvpValue *v1 = (KvpValue *) lp1->data;
1186  KvpValue *v2 = (KvpValue *) lp2->data;
1187  gint vcmp = kvp_value_compare (v1, v2);
1188  if (vcmp != 0)
1189  return vcmp;
1190  lp1 = lp1->next;
1191  lp2 = lp2->next;
1192  }
1193  if (!lp1 && lp2)
1194  return -1;
1195  if (!lp2 && lp1)
1196  return 1;
1197  return 0;
1198 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
gint kvp_value_compare(const KvpValue *kva, const KvpValue *kvb)
Definition: kvpframe.c:1654
GList* kvp_glist_copy ( const GList *  list)

kvp_glist_copy() performs a deep copy of a GList of kvp_values (not to be confused with GLists of something else): same as mapping kvp_value_copy() over the elements and then copying the spine.

Definition at line 1145 of file kvpframe.c.

1146 {
1147  GList *retval = NULL;
1148  GList *lptr;
1149 
1150  if (!list)
1151  return retval;
1152 
1153  /* Duplicate the backbone of the list (this duplicates the POINTERS
1154  * to the values; we need to deep-copy the values separately) */
1155  retval = g_list_copy ((GList *) list);
1156 
1157  /* This step deep-copies the values */
1158  for (lptr = retval; lptr; lptr = lptr->next)
1159  {
1160  lptr->data = kvp_value_copy (lptr->data);
1161  }
1162 
1163  return retval;
1164 }
KvpValue * kvp_value_copy(const KvpValue *value)
Definition: kvpframe.c:1598
void kvp_glist_delete ( GList *  list)

kvp_glist_delete() performs a deep delete of a GList of kvp_values (not to be confused with GLists of something else): same as mapping * kvp_value_delete() over the elements and then deleting the GList.

Definition at line 1127 of file kvpframe.c.

1128 {
1129  GList *node;
1130  if (!list)
1131  return;
1132 
1133  /* Delete the data in the list */
1134  for (node = list; node; node = node->next)
1135  {
1136  KvpValue *val = node->data;
1137  kvp_value_delete (val);
1138  }
1139 
1140  /* Free the backbone */
1141  g_list_free (list);
1142 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358
gboolean kvp_value_binary_append ( KvpValue v,
gpointer  data,
guint64  size 
)

Manipulator:

copying - but more efficient than creating a new KvpValue manually.

gint kvp_value_compare ( const KvpValue va,
const KvpValue vb 
)

Similar returns as strcmp.

Definition at line 1654 of file kvpframe.c.

1655 {
1656  if (kva == kvb)
1657  return 0;
1658  /* nothing is always less than something */
1659  if (!kva && kvb)
1660  return -1;
1661  if (kva && !kvb)
1662  return 1;
1663 
1664  if (kva->type < kvb->type)
1665  return -1;
1666  if (kva->type > kvb->type)
1667  return 1;
1668 
1669  switch (kva->type)
1670  {
1671  case KVP_TYPE_GINT64:
1672  if (kva->value.int64 < kvb->value.int64)
1673  return -1;
1674  if (kva->value.int64 > kvb->value.int64)
1675  return 1;
1676  return 0;
1677  break;
1678  case KVP_TYPE_DOUBLE:
1679  return qof_util_double_compare (kva->value.dbl, kvb->value.dbl);
1680  break;
1681  case KVP_TYPE_NUMERIC:
1682  return qof_numeric_compare (kva->value.numeric,
1683  kvb->value.numeric);
1684  break;
1685  case KVP_TYPE_STRING:
1686  return strcmp (kva->value.str, kvb->value.str);
1687  break;
1688  case KVP_TYPE_GUID:
1689  return guid_compare (kva->value.guid, kvb->value.guid);
1690  break;
1691  case KVP_TYPE_BOOLEAN:
1692  {
1693  /* true > false */
1694  if (kva->value.gbool != kvb->value.gbool)
1695  return (kva->value.gbool) ? 1 : -1;
1696  return 0;
1697  break;
1698  }
1699  case KVP_TYPE_TIME :
1700  return qof_time_cmp (kva->value.qt, kvb->value.qt);
1701  break;
1702  case KVP_TYPE_BINARY:
1703  if (kva->value.binary.datasize < kvb->value.binary.datasize)
1704  return -1;
1705  if (kva->value.binary.datasize > kvb->value.binary.datasize)
1706  return 1;
1707  return memcmp (kva->value.binary.data,
1708  kvb->value.binary.data, kva->value.binary.datasize);
1709  break;
1710  case KVP_TYPE_GLIST:
1711  return kvp_glist_compare (kva->value.list, kvb->value.list);
1712  break;
1713  case KVP_TYPE_FRAME:
1714  return kvp_frame_compare (kva->value.frame, kvb->value.frame);
1715  break;
1716  }
1717  return 0;
1718 }
gint qof_numeric_compare(QofNumeric a, QofNumeric b)
Definition: qofnumeric.c:169
Unique identifier.
Definition: kvpframe.h:118
gint kvp_frame_compare(const KvpFrame *fa, const KvpFrame *fb)
Definition: kvpframe.c:1743
gint kvp_glist_compare(const GList *list1, const GList *list2)
Definition: kvpframe.c:1167
128bit denominator/numerator maths.
Definition: kvpframe.h:106
gint qof_time_cmp(const QofTime *ta, const QofTime *tb)
Definition: qoftime.c:165
64bit integer
Definition: kvpframe.h:94
Simple boolean type.
Definition: kvpframe.h:136
gint qof_util_double_compare(gdouble d1, gdouble d2)
Compare two gdouble values.
Definition: qofutil.c:182
standard C string
Definition: kvpframe.h:112
standard C double type
Definition: kvpframe.h:100
64bit time/date handling.
Definition: kvpframe.h:124
KvpValue* kvp_value_copy ( const KvpValue value)

This is a deep value copy.

Definition at line 1598 of file kvpframe.c.

1599 {
1600  if (!value)
1601  return NULL;
1602 
1603  switch (value->type)
1604  {
1605  case KVP_TYPE_GINT64:
1606  return kvp_value_new_gint64 (value->value.int64);
1607  break;
1608  case KVP_TYPE_DOUBLE:
1609  return kvp_value_new_double (value->value.dbl);
1610  break;
1611  case KVP_TYPE_NUMERIC:
1612  return kvp_value_new_numeric (value->value.numeric);
1613  break;
1614  case KVP_TYPE_STRING:
1615  return kvp_value_new_string (value->value.str);
1616  break;
1617  case KVP_TYPE_GUID:
1618  return kvp_value_new_guid (value->value.guid);
1619  break;
1620  case KVP_TYPE_BOOLEAN:
1621  return NULL;
1622  return kvp_value_new_boolean (value->value.gbool);
1623  break;
1624  case KVP_TYPE_TIME :
1625  return kvp_value_new_time (value->value.qt);
1626  break;
1627  case KVP_TYPE_BINARY:
1628  return kvp_value_new_binary (value->value.binary.data,
1629  value->value.binary.datasize);
1630  break;
1631  case KVP_TYPE_GLIST:
1632  return kvp_value_new_glist (value->value.list);
1633  break;
1634  case KVP_TYPE_FRAME:
1635  return kvp_value_new_frame (value->value.frame);
1636  break;
1637  }
1638  return NULL;
1639 }
Unique identifier.
Definition: kvpframe.h:118
KvpValue * kvp_value_new_boolean(gboolean value)
Definition: kvpframe.c:1223
128bit denominator/numerator maths.
Definition: kvpframe.h:106
64bit integer
Definition: kvpframe.h:94
KvpValue * kvp_value_new_glist(const GList *value)
Definition: kvpframe.c:1306
Simple boolean type.
Definition: kvpframe.h:136
standard C string
Definition: kvpframe.h:112
standard C double type
Definition: kvpframe.h:100
64bit time/date handling.
Definition: kvpframe.h:124
void kvp_value_delete ( KvpValue value)

This is a deep (recursive) delete.

Definition at line 1358 of file kvpframe.c.

1359 {
1360  if (!value)
1361  return;
1362 
1363  switch (value->type)
1364  {
1365  case KVP_TYPE_STRING:
1366  g_free (value->value.str);
1367  break;
1368  case KVP_TYPE_GUID:
1369  g_free (value->value.guid);
1370  break;
1371  case KVP_TYPE_BINARY:
1372  g_free (value->value.binary.data);
1373  break;
1374  case KVP_TYPE_GLIST:
1375  kvp_glist_delete (value->value.list);
1376  break;
1377  case KVP_TYPE_FRAME:
1378  kvp_frame_delete (value->value.frame);
1379  break;
1380  case KVP_TYPE_BOOLEAN:
1381  case KVP_TYPE_GINT64:
1382  case KVP_TYPE_DOUBLE:
1383  case KVP_TYPE_NUMERIC:
1384  default:
1385  break;
1386  }
1387  g_free (value);
1388 }
Unique identifier.
Definition: kvpframe.h:118
128bit denominator/numerator maths.
Definition: kvpframe.h:106
void kvp_frame_delete(KvpFrame *frame)
Definition: kvpframe.c:115
64bit integer
Definition: kvpframe.h:94
void kvp_glist_delete(GList *list)
Definition: kvpframe.c:1127
Simple boolean type.
Definition: kvpframe.h:136
standard C string
Definition: kvpframe.h:112
standard C double type
Definition: kvpframe.h:100
gpointer kvp_value_get_binary ( const KvpValue value,
guint64 *  size_return 
)

Value accessor. This one is non-copying – the caller can modify the value directly.

Definition at line 1504 of file kvpframe.c.

1505 {
1506  if (!value)
1507  {
1508  if (size_return)
1509  *size_return = 0;
1510  PERR (" no size specified");
1511  return NULL;
1512  }
1513 
1514  if (value->type == KVP_TYPE_BINARY)
1515  {
1516  if (size_return)
1517  *size_return = value->value.binary.datasize;
1518  return value->value.binary.data;
1519  }
1520  else
1521  {
1522  if (size_return)
1523  *size_return = 0;
1524  PERR (" value type %d does not match KVP_TYPE_BINARY",
1525  value->type);
1526  return NULL;
1527  }
1528 }
#define PERR(format, args...)
Definition: qoflog.h:183
KvpFrame* kvp_value_get_frame ( const KvpValue value)

Value accessor. This one is non-copying – the caller can modify the value directly.

Definition at line 1546 of file kvpframe.c.

1547 {
1548  if (!value)
1549  return NULL;
1550  if (value->type == KVP_TYPE_FRAME)
1551  return value->value.frame;
1552  else
1553  {
1554  PERR (" value type %d does not match KVP_TYPE_FRAME",
1555  value->type);
1556  return NULL;
1557  }
1558 }
#define PERR(format, args...)
Definition: qoflog.h:183
gint64 kvp_value_get_gint64 ( const KvpValue value)

Value accessors. Those for GUID, binary, GList, KvpFrame and string are non-copying – the caller can modify the value directly. Just don't free it, or you screw up everything. Note that if another value is stored at the key location that this value came from, then this value will be uncermoniously deleted, and you will be left pointing to garbage. So don't store values at the same time you are examining their contents.

Todo:
kvp_value_get_ functions need to set QofError so that users can check that a NULL or zero value is actually a real value and not an error result.

Definition at line 1399 of file kvpframe.c.

1400 {
1401  if (!value)
1402  return 0;
1403  if (value->type == KVP_TYPE_GINT64)
1404  return value->value.int64;
1405  else
1406  {
1407  PERR (" value type %d does not match KVP_TYPE_GINT64",
1408  value->type);
1409  return 0;
1410  }
1411 }
#define PERR(format, args...)
Definition: qoflog.h:183
64bit integer
Definition: kvpframe.h:94
GList* kvp_value_get_glist ( const KvpValue value)

Returns the GList of kvp_frame's (not to be confused with GList's of something else!) from the given kvp_frame. This one is non-copying – the caller can modify the value directly.

Definition at line 1531 of file kvpframe.c.

1532 {
1533  if (!value)
1534  return NULL;
1535  if (value->type == KVP_TYPE_GLIST)
1536  return value->value.list;
1537  else
1538  {
1539  PERR (" value type %d does not match KVP_TYPE_GLIST",
1540  value->type);
1541  return NULL;
1542  }
1543 }
#define PERR(format, args...)
Definition: qoflog.h:183
GUID* kvp_value_get_guid ( const KvpValue value)

Value accessor. This one is non-copying – the caller can modify the value directly.

Definition at line 1474 of file kvpframe.c.

1475 {
1476  if (!value)
1477  return NULL;
1478  if (value->type == KVP_TYPE_GUID)
1479  return value->value.guid;
1480  else
1481  {
1482  PERR (" value type %d does not match KVP_TYPE_GUID",
1483  value->type);
1484  return NULL;
1485  }
1486 }
#define PERR(format, args...)
Definition: qoflog.h:183
Unique identifier.
Definition: kvpframe.h:118
gchar* kvp_value_get_string ( const KvpValue value)

Value accessor. This one is non-copying – the caller can modify the value directly.

Definition at line 1444 of file kvpframe.c.

1445 {
1446  if (!value)
1447  return NULL;
1448  if (value->type == KVP_TYPE_STRING)
1449  return value->value.str;
1450  else
1451  {
1452  PERR (" value type %d does not match KVP_TYPE_STRING",
1453  value->type);
1454  return NULL;
1455  }
1456 }
#define PERR(format, args...)
Definition: qoflog.h:183
standard C string
Definition: kvpframe.h:112
KvpValue* kvp_value_new_binary_nc ( void *  data,
guint64  datasize 
)

value constructors (non-copying - KvpValue takes pointer ownership) values must have been allocated via glib allocators! (gnew, etc.)

KvpValue* kvp_value_new_boolean ( gboolean  value)
Since
0.7.2

Definition at line 1223 of file kvpframe.c.

1224 {
1225  KvpValue * retval = g_new0 (KvpValue, 1);
1226  retval->type = KVP_TYPE_BOOLEAN;
1227  retval->value.gbool = value;
1228  return retval;
1229 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
Simple boolean type.
Definition: kvpframe.h:136
KvpValue* kvp_value_new_frame_nc ( KvpFrame value)

value constructors (non-copying - KvpValue takes pointer ownership) values must have been allocated via glib allocators! (gnew, etc.)

Definition at line 1345 of file kvpframe.c.

1346 {
1347  KvpValue *retval;
1348  if (!value)
1349  return NULL;
1350 
1351  retval = g_new0 (KvpValue, 1);
1352  retval->type = KVP_TYPE_FRAME;
1353  retval->value.frame = value;
1354  return retval;
1355 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpValue* kvp_value_new_glist ( const GList *  value)

Creates a KvpValue from a GList of kvp_value's! (Not to be confused with GList's of something else!)

Definition at line 1306 of file kvpframe.c.

1307 {
1308  KvpValue *retval;
1309  if (!value)
1310  return NULL;
1311 
1312  retval = g_new0 (KvpValue, 1);
1313  retval->type = KVP_TYPE_GLIST;
1314  retval->value.list = kvp_glist_copy (value);
1315  return retval;
1316 }
GList * kvp_glist_copy(const GList *list)
Definition: kvpframe.c:1145
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpValue* kvp_value_new_glist_nc ( GList *  lst)

Creates a KvpValue from a GList of kvp_value's! (Not to be confused with GList's of something else!)

This value constructor is non-copying (KvpValue takes pointer ownership). The values must have been allocated via glib allocators! (gnew, etc.)

Definition at line 1319 of file kvpframe.c.

1320 {
1321  KvpValue *retval;
1322  if (!value)
1323  return NULL;
1324 
1325  retval = g_new0 (KvpValue, 1);
1326  retval->type = KVP_TYPE_GLIST;
1327  retval->value.list = value;
1328  return retval;
1329 }
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpFrame* kvp_value_replace_frame_nc ( KvpValue value,
KvpFrame newframe 
)

Replace old frame value with new, return old frame

Definition at line 1561 of file kvpframe.c.

1562 {
1563  KvpFrame *oldframe;
1564  if (!value)
1565  return NULL;
1566  if (KVP_TYPE_FRAME != value->type)
1567  {
1568  PERR (" value type %d does not match KVP_TYPE_FRAME",
1569  value->type);
1570  return NULL;
1571  }
1572  oldframe = value->value.frame;
1573  value->value.frame = newframe;
1574  return oldframe;
1575 }
#define PERR(format, args...)
Definition: qoflog.h:183
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
GList* kvp_value_replace_glist_nc ( KvpValue value,
GList *  newlist 
)

Replace old glist value with new, return old glist

Definition at line 1578 of file kvpframe.c.

1579 {
1580  GList *oldlist;
1581  if (!value)
1582  return NULL;
1583  if (KVP_TYPE_GLIST != value->type)
1584  {
1585  PERR (" value type %d does not match KVP_TYPE_GLIST",
1586  value->type);
1587  return NULL;
1588  }
1589 
1590  oldlist = value->value.list;
1591  value->value.list = newlist;
1592  return oldlist;
1593 }
#define PERR(format, args...)
Definition: qoflog.h:183
gchar* kvp_value_to_bare_string ( const KvpValue val)

General purpose function to convert any KvpValue to a string.

Only the bare string is returned, there is no debugging information.

Definition at line 1834 of file kvpframe.c.

1835 {
1836  gchar *tmp1;
1837  gchar *tmp2;
1838  const gchar *ctmp;
1839 
1840  g_return_val_if_fail (val, NULL);
1841  tmp1 = g_strdup ("");
1842  switch (kvp_value_get_type (val))
1843  {
1844  case KVP_TYPE_GINT64:
1845  {
1846  return g_strdup_printf ("%" G_GINT64_FORMAT,
1847  kvp_value_get_gint64 (val));
1848  break;
1849  }
1850  case KVP_TYPE_DOUBLE:
1851  {
1852  return g_strdup_printf ("(%g)", kvp_value_get_double (val));
1853  break;
1854  }
1855  case KVP_TYPE_NUMERIC:
1856  {
1857  tmp1 = qof_numeric_to_string (kvp_value_get_numeric (val));
1858  tmp2 = g_strdup_printf ("%s", tmp1 ? tmp1 : "");
1859  g_free (tmp1);
1860  return tmp2;
1861  break;
1862  }
1863  case KVP_TYPE_STRING:
1864  {
1865  tmp1 = kvp_value_get_string (val);
1866  return g_strdup_printf ("%s", tmp1 ? tmp1 : "");
1867  break;
1868  }
1869  case KVP_TYPE_GUID:
1870  {
1871  ctmp = guid_to_string (kvp_value_get_guid (val));
1872  tmp2 = g_strdup_printf ("%s", ctmp ? ctmp : "");
1873  return tmp2;
1874  break;
1875  }
1876  case KVP_TYPE_BOOLEAN :
1877  return (kvp_value_get_boolean (val)) ? "TRUE" : "FALSE";
1878  case KVP_TYPE_BINARY:
1879  {
1880  guint64 len;
1881  gpointer data;
1882  data = kvp_value_get_binary (val, &len);
1883  tmp1 = binary_to_string (data, len);
1884  return g_strdup_printf ("%s", tmp1 ? tmp1 : "");
1885  break;
1886  }
1887  case KVP_TYPE_GLIST:
1888  /* borked. kvp_value_glist_to_string is a debug fcn */
1889  {
1890  tmp1 = kvp_value_glist_to_string (kvp_value_get_glist (val));
1891  tmp2 = g_strdup_printf ("%s", tmp1 ? tmp1 : "");
1892  g_free (tmp1);
1893  return tmp2;
1894  break;
1895  }
1896  case KVP_TYPE_FRAME:
1897  {
1898  KvpFrame *frame;
1899 
1900  frame = kvp_value_get_frame (val);
1901  if (frame->hash)
1902  {
1903  tmp1 = g_strdup ("");
1904  g_hash_table_foreach (frame->hash,
1905  kvp_frame_to_bare_string_helper, &tmp1);
1906  }
1907  return tmp1;
1908  break;
1909  }
1910  default:
1911  return g_strdup_printf (" ");
1912  break;
1913  }
1914 }
GUID * kvp_value_get_guid(const KvpValue *value)
Definition: kvpframe.c:1474
Unique identifier.
Definition: kvpframe.h:118
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
void * kvp_value_get_binary(const KvpValue *value, guint64 *size_return)
Definition: kvpframe.c:1504
128bit denominator/numerator maths.
Definition: kvpframe.h:106
gint64 kvp_value_get_gint64(const KvpValue *value)
Definition: kvpframe.c:1399
const char * guid_to_string(const GUID *guid)
Definition: guid.c:568
64bit integer
Definition: kvpframe.h:94
GList * kvp_value_get_glist(const KvpValue *value)
Definition: kvpframe.c:1531
gchar * kvp_value_get_string(const KvpValue *value)
Definition: kvpframe.c:1444
gchar * qof_numeric_to_string(QofNumeric n)
Definition: qofnumeric.c:1084
Simple boolean type.
Definition: kvpframe.h:136
standard C string
Definition: kvpframe.h:112
KvpFrame * kvp_value_get_frame(const KvpValue *value)
Definition: kvpframe.c:1546
standard C double type
Definition: kvpframe.h:100
gchar* kvp_value_to_string ( const KvpValue val)

Debug version.

This version is used only by ::qof_query_printValueForParam, itself a debugging and development utility function.

Definition at line 1917 of file kvpframe.c.

1918 {
1919  gchar *tmp1;
1920  gchar *tmp2;
1921  const gchar *ctmp;
1922 
1923  g_return_val_if_fail (val, NULL);
1924 
1925  switch (kvp_value_get_type (val))
1926  {
1927  case KVP_TYPE_GINT64:
1928  {
1929  return g_strdup_printf ("KVP_VALUE_GINT64(%" G_GINT64_FORMAT ")",
1930  kvp_value_get_gint64 (val));
1931  break;
1932  }
1933  case KVP_TYPE_DOUBLE:
1934  {
1935  return g_strdup_printf ("KVP_VALUE_DOUBLE(%g)",
1936  kvp_value_get_double (val));
1937  break;
1938  }
1939  case KVP_TYPE_NUMERIC:
1940  {
1941  tmp1 = qof_numeric_to_string (kvp_value_get_numeric (val));
1942  tmp2 = g_strdup_printf ("KVP_VALUE_NUMERIC(%s)", tmp1 ? tmp1 : "");
1943  g_free (tmp1);
1944  return tmp2;
1945  break;
1946  }
1947  case KVP_TYPE_STRING:
1948  {
1949  tmp1 = kvp_value_get_string (val);
1950  return g_strdup_printf ("KVP_VALUE_STRING(%s)", tmp1 ? tmp1 : "");
1951  break;
1952  }
1953  case KVP_TYPE_GUID:
1954  {
1955  /* THREAD-UNSAFE */
1956  ctmp = guid_to_string (kvp_value_get_guid (val));
1957  tmp2 = g_strdup_printf ("KVP_VALUE_GUID(%s)", ctmp ? ctmp : "");
1958  return tmp2;
1959  break;
1960  }
1961  case KVP_TYPE_BINARY:
1962  {
1963  guint64 len;
1964  gpointer data;
1965  data = kvp_value_get_binary (val, &len);
1966  tmp1 = binary_to_string (data, len);
1967  return g_strdup_printf ("KVP_VALUE_BINARY(%s)",
1968  tmp1 ? tmp1 : "");
1969  break;
1970  }
1971  case KVP_TYPE_GLIST:
1972  {
1973  tmp1 = kvp_value_glist_to_string (kvp_value_get_glist (val));
1974  tmp2 = g_strdup_printf ("KVP_VALUE_GLIST(%s)", tmp1 ? tmp1 : "");
1975  g_free (tmp1);
1976  return tmp2;
1977  break;
1978  }
1979  case KVP_TYPE_FRAME:
1980  {
1981  tmp1 = kvp_frame_to_string (kvp_value_get_frame (val));
1982  tmp2 = g_strdup_printf ("KVP_VALUE_FRAME(%s)", tmp1 ? tmp1 : "");
1983  g_free (tmp1);
1984  return tmp2;
1985  break;
1986  }
1987  default:
1988  return g_strdup_printf (" ");
1989  break;
1990  }
1991 }
GUID * kvp_value_get_guid(const KvpValue *value)
Definition: kvpframe.c:1474
Unique identifier.
Definition: kvpframe.h:118
void * kvp_value_get_binary(const KvpValue *value, guint64 *size_return)
Definition: kvpframe.c:1504
128bit denominator/numerator maths.
Definition: kvpframe.h:106
gint64 kvp_value_get_gint64(const KvpValue *value)
Definition: kvpframe.c:1399
const char * guid_to_string(const GUID *guid)
Definition: guid.c:568
64bit integer
Definition: kvpframe.h:94
GList * kvp_value_get_glist(const KvpValue *value)
Definition: kvpframe.c:1531
gchar * kvp_value_get_string(const KvpValue *value)
Definition: kvpframe.c:1444
gchar * qof_numeric_to_string(QofNumeric n)
Definition: qofnumeric.c:1084
standard C string
Definition: kvpframe.h:112
KvpFrame * kvp_value_get_frame(const KvpValue *value)
Definition: kvpframe.c:1546
standard C double type
Definition: kvpframe.h:100
QofIdTypeConst kvp_value_type_to_qof_id ( KvpValueType  n)

Convert a KvpValueType to a QofIdType.

Used by various backends to convert QofParam into SQL structures.

Note
Not all KvpValueType types can be converted to QofIdTypeConst, in particular KVP_TYPE_BINARY, KVP_TYPE_GLIST and KVP_TYPE_FRAME
Returns
The QofIdTypeConst or NULL if the type cannot be converted.

Definition at line 246 of file kvputil.c.

247 {
248  switch (n)
249  {
250  case KVP_TYPE_GINT64:
251  {
252  return QOF_TYPE_INT64;
253  break;
254  }
255  case KVP_TYPE_DOUBLE:
256  {
257  return QOF_TYPE_DOUBLE;
258  break;
259  }
260  case KVP_TYPE_NUMERIC:
261  {
262  return QOF_TYPE_NUMERIC;
263  break;
264  }
265  case KVP_TYPE_STRING:
266  {
267  return QOF_TYPE_STRING;
268  break;
269  }
270  case KVP_TYPE_GUID:
271  {
272  return QOF_TYPE_GUID;
273  break;
274  }
275  case KVP_TYPE_BOOLEAN :
276  {
277  return QOF_TYPE_BOOLEAN;
278  break;
279  }
280  case KVP_TYPE_TIME :
281  {
282  return QOF_TYPE_TIME;
283  break;
284  }
285  default:
286  {
287  return NULL;
288  }
289  }
290 }
Unique identifier.
Definition: kvpframe.h:118
128bit denominator/numerator maths.
Definition: kvpframe.h:106
64bit integer
Definition: kvpframe.h:94
Simple boolean type.
Definition: kvpframe.h:136
standard C string
Definition: kvpframe.h:112
standard C double type
Definition: kvpframe.h:100
64bit time/date handling.
Definition: kvpframe.h:124
KvpValueType qof_id_to_kvp_value_type ( QofIdTypeConst  type_string)

Convert a QofIdType to a KvpValueType.

Used by various backends to convert QofParam into SQL structures.

Note
Not all KvpValueType types can be converted to QofIdTypeConst, in particular KVP_TYPE_BINARY, KVP_TYPE_GLIST and KVP_TYPE_FRAME
Returns
The KvpValueType or zero if the type cannot be converted.

Definition at line 228 of file kvputil.c.

229 {
230  if (0 == safe_strcmp (QOF_TYPE_INT64, type_string))
231  return KVP_TYPE_GINT64;
232  if (0 == safe_strcmp (QOF_TYPE_DOUBLE, type_string))
233  return KVP_TYPE_DOUBLE;
234  if (0 == safe_strcmp (QOF_TYPE_NUMERIC, type_string))
235  return KVP_TYPE_NUMERIC;
236  if (0 == safe_strcmp (QOF_TYPE_STRING, type_string))
237  return KVP_TYPE_STRING;
238  if (0 == safe_strcmp (QOF_TYPE_GUID, type_string))
239  return KVP_TYPE_GUID;
240  if (0 == safe_strcmp (QOF_TYPE_TIME, type_string))
241  return KVP_TYPE_TIME;
242  return 0;
243 }
Unique identifier.
Definition: kvpframe.h:118
128bit denominator/numerator maths.
Definition: kvpframe.h:106
64bit integer
Definition: kvpframe.h:94
standard C string
Definition: kvpframe.h:112
gint safe_strcmp(const gchar *da, const gchar *db)
Definition: qofutil.c:75
standard C double type
Definition: kvpframe.h:100
64bit time/date handling.
Definition: kvpframe.h:124
KvpFrame* qof_kvp_bag_add ( KvpFrame kvp_root,
const gchar *  path,
QofTime qt,
const gchar *  first_name,
  ... 
)

The qof_kvp_bag_add() routine is used to maintain a collection of pointers in a kvp tree.

The thing being pointed at is uniquely identified by its GUID. This routine is typically used to create a linked list, and/or a collection of pointers to objects that are 'related' to each other in some way.

The var-args should be pairs of strings (const char *) followed by the corresponding GUID pointer (const GUID *). Terminate the varargs with a NULL as the last string argument.

The actual 'pointer' is stored in a subdirectory in a bag located at the node directory 'path'. A 'bag' is merely a collection of (unamed) values. The name of our bag is 'path'. A bag can contain any kind of values, including frames. This routine will create a frame, and put it in the bag. The frame will contain named data from the subroutine arguments. Thus, for example:

qof_kvp_array (kvp, "foo", secs, "acct_guid", aguid, "book_guid", bguid, NULL);

will create a frame containing "/acct_guid" and "/book_guid", whose values are aguid and bguid respecitvely. The frame will also contain "/date", whose value will be secs. This frame will be placed into the bag located at "foo".

This routine returns a pointer to the frame that was created, or NULL if an error occured.

Definition at line 67 of file kvputil.c.

69 {
70  KvpFrame *cwd;
71  va_list ap;
72  va_start (ap, first_name);
73  cwd = qof_kvp_array_va (pwd, path, qt, first_name, ap);
74  va_end (ap);
75  return cwd;
76 }
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
KvpFrame* qof_kvp_bag_find_by_guid ( KvpFrame root,
const gchar *  path,
const gchar *  guid_name,
GUID desired_guid 
)

The qof_kvp_bag_find_by_guid() routine examines the bag pointed located at root. It looks for a frame in that bag that has the guid value of "desired_guid" filed under the key name "guid_name". If it finds that matching guid, then it returns a pointer to the KVP frame that contains it. If it is not found, or if there is any other error, NULL is returned.

Definition at line 89 of file kvputil.c.

91 {
92  KvpValue *arr;
93  KvpValueType valtype;
94  GList *node;
95 
96  arr = kvp_frame_get_value (root, path);
97  valtype = kvp_value_get_type (arr);
98  if (KVP_TYPE_FRAME == valtype)
99  {
100  MATCH_GUID (arr);
101  return NULL;
102  }
103 
104  /* Its got to be a single isolated frame, or a list of them. */
105  if (KVP_TYPE_GLIST != valtype)
106  return NULL;
107 
108  for (node = kvp_value_get_glist (arr); node; node = node->next)
109  {
110  KvpValue *va = node->data;
111  MATCH_GUID (va);
112  }
113  return NULL;
114 }
KvpValueType
possible types in the union KvpValue
Definition: kvpframe.h:87
struct _KvpValue KvpValue
Definition: kvpframe.h:78
GList * kvp_value_get_glist(const KvpValue *value)
Definition: kvpframe.c:1531
void qof_kvp_bag_merge ( KvpFrame kvp_into,
const gchar *  intopath,
KvpFrame kvp_from,
const gchar *  frompath 
)

The qof_kvp_bag_merge() routine will move the bag contents from the 'kvp_from', to the 'into' bag. It will then delete the 'from' bag from the kvp tree.

Definition at line 186 of file kvputil.c.

188 {
189  KvpFrame *fr;
190 
191  fr = qof_kvp_bag_get_first (kvp_from, frompath);
192  while (fr)
193  {
194  qof_kvp_bag_remove_frame (kvp_from, frompath, fr);
195  kvp_frame_add_frame_nc (kvp_into, intopath, fr);
196  fr = qof_kvp_bag_get_first (kvp_from, frompath);
197  }
198 }
void kvp_frame_add_frame_nc(KvpFrame *frame, const gchar *path, KvpFrame *fr)
Add the frame to the glist bag without copying.
Definition: kvpframe.c:669
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
void qof_kvp_bag_remove_frame(KvpFrame *root, const gchar *path, KvpFrame *fr)
Definition: kvputil.c:119
void qof_kvp_bag_remove_frame ( KvpFrame root,
const gchar *  path,
KvpFrame fr 
)

Remove the given frame from the bag. The frame is removed, however, it is not deleted. Note that the frame pointer must be a pointer to the actual frame (for example, as returned by gnc_kvp_bag_find_by_guid() for by gnc_kvp_bag_add()), and not some copy of the frame.

Definition at line 119 of file kvputil.c.

120 {
121  KvpValue *arr;
122  KvpValueType valtype;
123  GList *node, *listhead;
124 
125  arr = kvp_frame_get_value (root, path);
126  valtype = kvp_value_get_type (arr);
127  if (KVP_TYPE_FRAME == valtype)
128  {
129  if (fr == kvp_value_get_frame (arr))
130  {
131  KvpValue *old_val =
132  kvp_frame_replace_value_nc (root, path, NULL);
133  kvp_value_replace_frame_nc (old_val, NULL);
134  kvp_value_delete (old_val);
135  }
136  return;
137  }
138 
139  /* Its got to be a single isolated frame, or a list of them. */
140  if (KVP_TYPE_GLIST != valtype)
141  return;
142 
143  listhead = kvp_value_get_glist (arr);
144  for (node = listhead; node; node = node->next)
145  {
146  KvpValue *va = node->data;
147  if (fr == kvp_value_get_frame (va))
148  {
149  listhead = g_list_remove_link (listhead, node);
150  g_list_free_1 (node);
151  kvp_value_replace_glist_nc (arr, listhead);
152  kvp_value_replace_frame_nc (va, NULL);
153  kvp_value_delete (va);
154  return;
155  }
156  }
157 }
GList * kvp_value_replace_glist_nc(KvpValue *value, GList *newlist)
Definition: kvpframe.c:1578
KvpValueType
possible types in the union KvpValue
Definition: kvpframe.h:87
KvpValue * kvp_frame_replace_value_nc(KvpFrame *frame, const gchar *key_path, KvpValue *new_value)
Definition: kvpframe.c:513
struct _KvpValue KvpValue
Definition: kvpframe.h:78
GList * kvp_value_get_glist(const KvpValue *value)
Definition: kvpframe.c:1531
KvpFrame * kvp_value_replace_frame_nc(KvpValue *value, KvpFrame *newframe)
Definition: kvpframe.c:1561
KvpFrame * kvp_value_get_frame(const KvpValue *value)
Definition: kvpframe.c:1546
void kvp_value_delete(KvpValue *value)
Definition: kvpframe.c:1358