mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Remove kvp-utils.
No longer required.
This commit is contained in:
parent
c941a52a9f
commit
cadd1976df
@ -469,7 +469,6 @@ src/libqof/qof/gnc-numeric.cpp
|
||||
src/libqof/qof/gnc-rational.cpp
|
||||
src/libqof/qof/guid.cpp
|
||||
src/libqof/qof/kvp_frame.cpp
|
||||
src/libqof/qof/kvp-util.cpp
|
||||
src/libqof/qof/kvp-value.cpp
|
||||
src/libqof/qof/qofbackend.cpp
|
||||
src/libqof/qof/qofbook.cpp
|
||||
|
@ -283,11 +283,6 @@ Plan A has been implemented in the engine. To quickly summarize:
|
||||
it with the appropriate keys, markup, etc. and to carry balances
|
||||
forward, etc.
|
||||
|
||||
- src/engine/kvp-util.[ch]
|
||||
Gemini code: code which allows 'linked lists' to be created, using
|
||||
nothing but kvp trees and guid's. These links are used to identify
|
||||
peer accounts/ peer transactions, etc.
|
||||
|
||||
- src/engine/gnc-lot.[ch]
|
||||
Implements accounting Lots.
|
||||
|
||||
|
@ -15,7 +15,6 @@ SET (libgnc_qof_SOURCES
|
||||
qof/gnc-numeric.cpp
|
||||
qof/gnc-rational.cpp
|
||||
qof/guid.cpp
|
||||
qof/kvp-util.cpp
|
||||
qof/kvp_frame.cpp
|
||||
qof/kvp-value.cpp
|
||||
qof/qofbackend.cpp
|
||||
@ -51,8 +50,6 @@ SET (libgnc_qof_HEADERS
|
||||
qof/gnc-date.h
|
||||
qof/gnc-numeric.h
|
||||
qof/guid.h
|
||||
qof/kvp-util-p.h
|
||||
qof/kvp-util.h
|
||||
qof/kvp_frame.h
|
||||
qof/qof.h
|
||||
qof/qofbackend-p.h
|
||||
|
@ -30,7 +30,6 @@ libgnc_qof_la_SOURCES = \
|
||||
gnc-timezone.cpp \
|
||||
gnc-datetime.cpp \
|
||||
guid.cpp \
|
||||
kvp-util.cpp \
|
||||
kvp_frame.cpp \
|
||||
kvp-value.cpp \
|
||||
qofbackend.cpp \
|
||||
@ -58,8 +57,6 @@ qofinclude_HEADERS = \
|
||||
gnc-timezone.hpp \
|
||||
gnc-datetime.hpp \
|
||||
guid.h \
|
||||
kvp-util-p.h \
|
||||
kvp-util.h \
|
||||
kvp_frame.h \
|
||||
kvp_frame.hpp \
|
||||
kvp-value.hpp \
|
||||
|
@ -1,115 +0,0 @@
|
||||
/********************************************************************\
|
||||
* kvp-util-p.h -- misc odd-job kvp utils (private file) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
#ifndef XACC_KVP_UTIL_P_H
|
||||
#define XACC_KVP_UTIL_P_H
|
||||
|
||||
#include "guid.h"
|
||||
#include "kvp_frame.h"
|
||||
|
||||
/** @addtogroup KVP
|
||||
@{
|
||||
*/
|
||||
/** @file kvp-util-p.h
|
||||
* @brief misc odd-job kvp utils engine-private routines
|
||||
* @author Copyright (C) 2001, 2003 Linas Vepstas <linas@linas.org> *
|
||||
*/
|
||||
/** @name KvpBag Bags of GncGUID Pointers
|
||||
@{
|
||||
*/
|
||||
|
||||
/** The gnc_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 GncGUID.
|
||||
* 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 GncGUID pointer (const GncGUID *). 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:
|
||||
*
|
||||
* gnc_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.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
KvpFrame * gnc_kvp_bag_add (KvpFrame *kvp_root, const char *path, time64 secs,
|
||||
const char *first_name, ...);
|
||||
|
||||
|
||||
/** The gnc_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.
|
||||
*/
|
||||
void gnc_kvp_bag_merge (KvpFrame *kvp_into, const char *intopath,
|
||||
KvpFrame *kvp_from, const char *frompath);
|
||||
|
||||
/** The gnc_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.
|
||||
*/
|
||||
|
||||
KvpFrame * gnc_kvp_bag_find_by_guid (KvpFrame *root, const char * path,
|
||||
const char *guid_name, const GncGUID *desired_guid);
|
||||
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
|
||||
void gnc_kvp_bag_remove_frame (KvpFrame *root, const char *path,
|
||||
KvpFrame *fr);
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* XACC_KVP_UTIL_P_H */
|
@ -1,244 +0,0 @@
|
||||
/********************************************************************\
|
||||
* kvp_util.cpp -- misc odd-job kvp utils *
|
||||
* Copyright (C) 2001 Linas Vepstas <linas@linas.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "kvp_frame.h"
|
||||
#include "kvp-util.h"
|
||||
#include "kvp-util-p.h"
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
static KvpFrame *
|
||||
gnc_kvp_array_va (KvpFrame *kvp_root, const char * path,
|
||||
time64 secs, const char * first_name, va_list ap)
|
||||
{
|
||||
KvpFrame *cwd;
|
||||
Timespec ts;
|
||||
const char *name;
|
||||
|
||||
if (!kvp_root) return NULL;
|
||||
if (!first_name) return NULL;
|
||||
|
||||
/* Create subdirectory and put the actual data */
|
||||
cwd = kvp_frame_new();
|
||||
|
||||
/* Record the time */
|
||||
ts.tv_sec = secs;
|
||||
ts.tv_nsec = 0;
|
||||
kvp_frame_set_timespec (cwd, "date", ts);
|
||||
|
||||
/* Loop over the args */
|
||||
name = first_name;
|
||||
while (name)
|
||||
{
|
||||
const GncGUID *guid;
|
||||
guid = va_arg (ap, const GncGUID *);
|
||||
|
||||
kvp_frame_set_guid (cwd, name, guid);
|
||||
|
||||
name = va_arg (ap, const char *);
|
||||
}
|
||||
|
||||
/* Attach cwd into the array */
|
||||
kvp_frame_add_frame_nc (kvp_root, path, cwd);
|
||||
return cwd;
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
KvpFrame *
|
||||
gnc_kvp_bag_add (KvpFrame *pwd, const char * path,
|
||||
time64 secs, const char *first_name, ...)
|
||||
{
|
||||
KvpFrame *cwd;
|
||||
va_list ap;
|
||||
va_start (ap, first_name);
|
||||
cwd = gnc_kvp_array_va (pwd, path, secs, first_name, ap);
|
||||
va_end (ap);
|
||||
return cwd;
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
#define MATCH_GUID(elt) { \
|
||||
KvpFrame *fr = kvp_value_get_frame (elt); \
|
||||
if (fr) { \
|
||||
GncGUID *guid = kvp_frame_get_guid (fr, guid_name); \
|
||||
if (guid && guid_equal (desired_guid, guid)) return fr; \
|
||||
} \
|
||||
}
|
||||
|
||||
KvpFrame *
|
||||
gnc_kvp_bag_find_by_guid (KvpFrame *root, const char * path,
|
||||
const char *guid_name, const GncGUID *desired_guid)
|
||||
{
|
||||
KvpValue *arr;
|
||||
KvpValueType valtype;
|
||||
GList *node;
|
||||
|
||||
arr = kvp_frame_get_value (root, path);
|
||||
valtype = kvp_value_get_type (arr);
|
||||
if (KVP_TYPE_FRAME == valtype)
|
||||
{
|
||||
MATCH_GUID (arr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Its gotta be a single isolated frame, or a list of them. */
|
||||
if (KVP_TYPE_GLIST != valtype) return NULL;
|
||||
|
||||
for (node = kvp_value_get_glist(arr); node; node = node->next)
|
||||
{
|
||||
KvpValue *va = static_cast<KvpValue*>(node->data);
|
||||
MATCH_GUID (va);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
void
|
||||
gnc_kvp_bag_remove_frame (KvpFrame *root, const char *path, KvpFrame *fr)
|
||||
{
|
||||
KvpValue *arr;
|
||||
KvpValueType valtype;
|
||||
GList *node, *listhead;
|
||||
|
||||
arr = kvp_frame_get_value (root, path);
|
||||
valtype = kvp_value_get_type (arr);
|
||||
if (KVP_TYPE_FRAME == valtype)
|
||||
{
|
||||
if (fr == kvp_value_get_frame (arr))
|
||||
{
|
||||
KvpValue *old_val = kvp_frame_replace_value_nc (root, path, NULL);
|
||||
kvp_value_replace_frame_nc (old_val, NULL);
|
||||
kvp_value_delete (old_val);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Its gotta be a single isolated frame, or a list of them. */
|
||||
if (KVP_TYPE_GLIST != valtype) return;
|
||||
|
||||
listhead = kvp_value_get_glist(arr);
|
||||
for (node = listhead; node; node = node->next)
|
||||
{
|
||||
KvpValue *va = static_cast<KvpValue*>(node->data);
|
||||
if (fr == kvp_value_get_frame (va))
|
||||
{
|
||||
listhead = g_list_remove_link (listhead, node);
|
||||
g_list_free_1 (node);
|
||||
kvp_value_replace_glist_nc (arr, listhead);
|
||||
kvp_value_replace_frame_nc (va, NULL);
|
||||
kvp_value_delete (va);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
static KvpFrame *
|
||||
gnc_kvp_bag_get_first (KvpFrame *root, const char * path)
|
||||
{
|
||||
KvpValue *arr, *va;
|
||||
KvpValueType valtype;
|
||||
GList *node;
|
||||
|
||||
arr = kvp_frame_get_value (root, path);
|
||||
valtype = kvp_value_get_type (arr);
|
||||
if (KVP_TYPE_FRAME == valtype)
|
||||
{
|
||||
return kvp_value_get_frame(arr);
|
||||
}
|
||||
|
||||
/* Its gotta be a single isolated frame, or a list of them. */
|
||||
if (KVP_TYPE_GLIST != valtype) return NULL;
|
||||
|
||||
node = kvp_value_get_glist(arr);
|
||||
if (NULL == node) return NULL;
|
||||
|
||||
va = static_cast<KvpValue*>(node->data);
|
||||
return kvp_value_get_frame(va);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_kvp_bag_merge (KvpFrame *kvp_into, const char *intopath,
|
||||
KvpFrame *kvp_from, const char *frompath)
|
||||
{
|
||||
KvpFrame *fr;
|
||||
|
||||
fr = gnc_kvp_bag_get_first (kvp_from, frompath);
|
||||
while (fr)
|
||||
{
|
||||
gnc_kvp_bag_remove_frame (kvp_from, frompath, fr);
|
||||
kvp_frame_add_frame_nc (kvp_into, intopath, fr);
|
||||
fr = gnc_kvp_bag_get_first (kvp_from, frompath);
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
/*
|
||||
* See header for docs.
|
||||
*/
|
||||
|
||||
static void
|
||||
kv_pair_helper(gpointer key, gpointer val, gpointer user_data)
|
||||
{
|
||||
GSList **result = (GSList **) user_data;
|
||||
GHashTableKVPair *kvp = g_new(GHashTableKVPair, 1);
|
||||
|
||||
kvp->key = key;
|
||||
kvp->value = val;
|
||||
*result = g_slist_prepend(*result, kvp);
|
||||
}
|
||||
|
||||
GSList *
|
||||
g_hash_table_key_value_pairs(GHashTable *table)
|
||||
{
|
||||
GSList *result_list = NULL;
|
||||
g_hash_table_foreach(table, kv_pair_helper, &result_list);
|
||||
return result_list;
|
||||
}
|
||||
|
||||
void
|
||||
g_hash_table_kv_pair_free_gfunc(gpointer data, G_GNUC_UNUSED gpointer user_data)
|
||||
{
|
||||
GHashTableKVPair *kvp = (GHashTableKVPair *) data;
|
||||
g_free(kvp);
|
||||
}
|
||||
|
||||
/*======================== END OF FILE =============================*/
|
@ -1,72 +0,0 @@
|
||||
/********************************************************************\
|
||||
* kvp-util.h -- misc KVP utilities *
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
|
||||
/** @addtogroup KVP
|
||||
@{
|
||||
*/
|
||||
/** @file kvp-util.h
|
||||
@brief QOF KVP utility functions
|
||||
*/
|
||||
/** @name Hash Utilities
|
||||
@{
|
||||
*/
|
||||
|
||||
#ifndef GNC_KVP_UTIL_H
|
||||
#define GNC_KVP_UTIL_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gpointer key;
|
||||
gpointer value;
|
||||
} GHashTableKVPair;
|
||||
|
||||
/**
|
||||
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);
|
||||
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
GSList *g_hash_table_key_value_pairs(GHashTable *table);
|
||||
void g_hash_table_kv_pair_free_gfunc(gpointer data, gpointer user_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
#endif /* GNC_KVP_UTIL_H */
|
@ -80,8 +80,6 @@
|
||||
#include "qofutil.h"
|
||||
#include "guid.h"
|
||||
#include "kvp_frame.h"
|
||||
#include "kvp-util.h"
|
||||
#include "kvp-util-p.h"
|
||||
#include "qofbackend.h"
|
||||
#include "qofid-p.h"
|
||||
#include "qofbook.h"
|
||||
|
Loading…
Reference in New Issue
Block a user