mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
refactor the 'gemini' kvp utilities to make them more generally useful.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9175 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
1700ebf387
commit
c4badc0128
@ -36,7 +36,8 @@
|
||||
* outside of the engine.
|
||||
*/
|
||||
|
||||
/** This routine is used to create a 'pointer' to an object in a kvp tree.
|
||||
/** The gnc_kvp_array() routine is used to maintain a list 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
|
||||
@ -46,17 +47,21 @@
|
||||
* the corresponding GUID pointer (const GUID *). Terminate the varargs
|
||||
* with a NULL as the last string argument.
|
||||
*
|
||||
* The actual 'pointer' is stored in an array in the subdirectory
|
||||
* '/gemini'. The size of the array is in /gemini/ncopies. The
|
||||
* pointer is stored in /gemini/<n>/<name> where <n> = ncopies -1,
|
||||
* <name> was passed as an argument. In addition, the date is
|
||||
* logged. Thus, for example:
|
||||
* gnc_kvp_gemini (kvp, secs, "acct_guid", aguid, "book_guid", bguid, NULL);
|
||||
* will increment /gemini/ncopies, and will store aguid in
|
||||
* /gemini/<n>/acct_guid and bguid in /gemini/<n>/book_guid, where
|
||||
* <n> = ncopies-1
|
||||
* The actual 'pointer' is stored in an array in a subdirectory
|
||||
* of the directory 'path'.
|
||||
* The size of the array is in /ncopies. The pointer is stored in
|
||||
* /<n>/<name> where <n> = ncopies -1, <name> was passed as an argument.
|
||||
* In addition, the date is logged. Thus, for example:
|
||||
* gnc_kvp_array (kvp, "foo", secs, "acct_guid", aguid,
|
||||
* "book_guid", bguid, NULL);
|
||||
* will increment /foo/ncopies, and will store aguid in
|
||||
* /foo/<n>/acct_guid and bguid in /foo/<n>/book_guid, where <n> = ncopies-1
|
||||
*/
|
||||
|
||||
void gnc_kvp_array (KvpFrame *kvp_root, const char *path, time_t secs,
|
||||
const char *first_name, ...);
|
||||
|
||||
/* Equivalent to gnc_kvp_array(kvp_root, "gemini", secs, firstname, ...); */
|
||||
void gnc_kvp_gemini (KvpFrame *kvp_root, time_t secs,
|
||||
const char *first_name, ...);
|
||||
|
||||
|
@ -33,10 +33,10 @@
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
void
|
||||
gnc_kvp_gemini (KvpFrame *kvp_root, time_t secs, const char *first_name, ...)
|
||||
static void
|
||||
gnc_kvp_array_va (KvpFrame *kvp_root, const char * path,
|
||||
time_t secs, const char * first_name, va_list ap)
|
||||
{
|
||||
va_list ap;
|
||||
char buff[80];
|
||||
KvpFrame *cwd, *pwd;
|
||||
KvpValue *v_ncopies;
|
||||
@ -44,12 +44,18 @@ gnc_kvp_gemini (KvpFrame *kvp_root, time_t secs, const char *first_name, ...)
|
||||
Timespec ts;
|
||||
const char *name;
|
||||
|
||||
if (!kvp_root) return;
|
||||
if (!kvp_root) return;
|
||||
if (!first_name) return;
|
||||
|
||||
/* cwd == 'current working directory' */
|
||||
pwd = kvp_frame_get_frame (kvp_root, "gemini", NULL);
|
||||
if (!pwd) return; /* error: can't ever happen */
|
||||
|
||||
if (!path)
|
||||
{
|
||||
pwd = kvp_root;
|
||||
}
|
||||
else
|
||||
{
|
||||
pwd = kvp_frame_get_frame_slash (kvp_root, path);
|
||||
if (!pwd) return; /* error: can't ever happen */
|
||||
}
|
||||
|
||||
/* Find, increment, store number of copies */
|
||||
v_ncopies = kvp_frame_get_slot (pwd, "ncopies");
|
||||
@ -64,6 +70,7 @@ gnc_kvp_gemini (KvpFrame *kvp_root, time_t secs, const char *first_name, ...)
|
||||
/* OK, now create subdirectory and put the actual data */
|
||||
--ncopies;
|
||||
sprintf (buff, GNC_SCANF_LLD, (long long int) ncopies);
|
||||
|
||||
cwd = kvp_frame_new();
|
||||
kvp_frame_set_slot_nc(pwd, buff, kvp_value_new_frame_nc(cwd));
|
||||
|
||||
@ -73,7 +80,6 @@ gnc_kvp_gemini (KvpFrame *kvp_root, time_t secs, const char *first_name, ...)
|
||||
kvp_frame_set_timespec (cwd, "date", ts);
|
||||
|
||||
/* Loop over the args */
|
||||
va_start (ap, first_name);
|
||||
name = first_name;
|
||||
|
||||
while (name)
|
||||
@ -85,7 +91,28 @@ gnc_kvp_gemini (KvpFrame *kvp_root, time_t secs, const char *first_name, ...)
|
||||
|
||||
name = va_arg (ap, const char *);
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
void
|
||||
gnc_kvp_array (KvpFrame *pwd, const char * path,
|
||||
time_t secs, const char *first_name, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, first_name);
|
||||
gnc_kvp_array_va (pwd, path, secs, first_name, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
void
|
||||
gnc_kvp_gemini (KvpFrame *kvp_root, time_t secs, const char *first_name, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, first_name);
|
||||
gnc_kvp_array_va (kvp_root, "gemini", secs, first_name, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user