remove the pricedb from the book struct

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8521 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2003-06-10 03:02:59 +00:00
parent dc3ccd9e51
commit d0d53c0699
6 changed files with 47 additions and 48 deletions

View File

@ -24,7 +24,7 @@
* HISTORY:
* Created 2001 by Rob Browning
* Copyright (c) 2001 Rob Browning
* Copyright (c) 2001 Linas Vepstas <linas@linas.org>
* Copyright (c) 2001,2003 Linas Vepstas <linas@linas.org>
*/
#ifndef GNC_BOOK_P_H
@ -52,14 +52,8 @@ struct gnc_book_struct
*/
GNCEntityTable *entity_table;
/* Pointers to top-level data structures. */
GList *sched_xactions;
AccountGroup *template_group;
gboolean sx_notsaved; /* true if sched_xactions is changed */
gnc_commodity_table *commodity_table;
/* In order to store arbitrary data, for extensibility, add a table
* that will be used to hold arbitrary pointers.
*/
@ -94,7 +88,6 @@ struct gnc_book_struct
*/
void gnc_book_set_guid(GNCBook *book, GUID guid);
void gnc_book_set_group(GNCBook *book, AccountGroup *grp);
void gnc_book_set_pricedb(GNCBook *book, GNCPriceDB *db);
void gnc_book_set_schedxactions( GNCBook *book, GList *newList );
void gnc_book_set_template_group( GNCBook *book, AccountGroup *templateGroup );

View File

@ -117,31 +117,12 @@ gnc_book_set_group (GNCBook *book, AccountGroup *grp)
/* ====================================================================== */
#define GNC_PRICEDB "gnc_pricedb"
GNCPriceDB *
gnc_book_get_pricedb(GNCBook *book)
{
if (!book) return NULL;
printf ("duude get pricedb\n");
return gnc_book_get_data (book, GNC_PRICEDB);
}
void
gnc_book_set_pricedb(GNCBook *book, GNCPriceDB *db)
{
if(!book) return;
gnc_book_set_data (book, GNC_PRICEDB, db);
if (db) db->book = book;
}
/* ====================================================================== */
#define GNC_SCHEDXACTIONS "gnc_schedxactions"
GList *
gnc_book_get_schedxactions( GNCBook *book )
{
if ( book == NULL ) return NULL;
return book->sched_xactions;
return gnc_book_get_data (book, GNC_SCHEDXACTIONS);
}
void
@ -149,17 +130,18 @@ gnc_book_set_schedxactions( GNCBook *book, GList *newList )
{
if ( book == NULL ) return;
book->sched_xactions = newList;
gnc_book_set_data (book, GNC_SCHEDXACTIONS, newList);
book->sx_notsaved = TRUE;
}
/* ====================================================================== */
#define GNC_TEMPLATE_GROUP "gnc_template_group"
AccountGroup *
gnc_book_get_template_group( GNCBook *book )
{
if (!book) return NULL;
return book->template_group;
return gnc_book_get_data (book, GNC_TEMPLATE_GROUP);
}
void
@ -167,16 +149,13 @@ gnc_book_set_template_group (GNCBook *book, AccountGroup *templateGroup)
{
if (!book) return;
if (book->template_group == templateGroup)
return;
if (templateGroup->book != book)
if (templateGroup && templateGroup->book != book)
{
PERR ("cannot mix and match books freely!");
return;
}
book->template_group = templateGroup;
gnc_book_set_data (book, GNC_TEMPLATE_GROUP, templateGroup);
}
/* ====================================================================== */
@ -207,9 +186,9 @@ book_sxlist_notsaved(GNCBook *book)
SchedXaction *sx;
if(book->sx_notsaved
||
xaccGroupNotSaved(book->template_group)) return TRUE;
xaccGroupNotSaved(gnc_book_get_template_group(book))) return TRUE;
for(sxlist = book->sched_xactions;
for(sxlist = gnc_book_get_schedxactions(book);
sxlist != NULL;
sxlist = g_list_next(sxlist))
{
@ -229,7 +208,7 @@ gnc_book_mark_saved(GNCBook *book)
book->dirty = FALSE;
xaccGroupMarkSaved(gnc_book_get_group(book));
gnc_pricedb_mark_clean(gnc_book_get_pricedb(book));
gnc_pricedb_mark_clean(gnc_pricedb_get_db(book));
xaccGroupMarkSaved(gnc_book_get_template_group(book));
book_sxns_mark_saved(book);
@ -254,11 +233,11 @@ gnc_book_populate (GNCBook *book)
gnc_book_set_group (book, xaccMallocAccountGroup(book));
gnc_book_set_pricedb (book, gnc_pricedb_create(book));
gnc_pricedb_set_db (book, gnc_pricedb_create(book));
book->sched_xactions = NULL;
gnc_book_set_schedxactions (book,NULL);
book->sx_notsaved = FALSE;
book->template_group = xaccMallocAccountGroup(book);
gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
}
@ -269,14 +248,16 @@ gnc_book_depopulate (GNCBook *book)
gnc_commodity_table *ct;
GNCPriceDB *db;
/* unhook the top-level group */
grp = gnc_book_get_group (book);
xaccAccountGroupBeginEdit (grp);
xaccAccountGroupDestroy (grp);
gnc_book_set_group (book, NULL);
/* unhook the prices */
db = gnc_book_get_pricedb (book);
gnc_pricedb_destroy (db);
gnc_book_set_pricedb (book, NULL);
gnc_pricedb_set_db (book, NULL);
ct = gnc_book_get_commodity_table (book);
gnc_commodity_table_destroy (ct);

View File

@ -26,7 +26,7 @@
*
* HISTORY:
* Created by Linas Vepstas December 1998
* @author Copyright (c) 1998, 1999, 2001 Linas Vepstas <linas@linas.org>
* @author Copyright (c) 1998, 1999, 2001, 2003 Linas Vepstas <linas@linas.org>
* @author Copyright (c) 2000 Dave Peticolas
*/
@ -58,9 +58,6 @@ kvp_frame * gnc_book_get_slots (GNCBook *book);
/** \return The top-level group in the book.*/
AccountGroup * gnc_book_get_group (GNCBook *book);
/** \return The pricedb of the book. */
GNCPriceDB * gnc_book_get_pricedb (GNCBook *book);
/** \return The commodity table of the book. */
gnc_commodity_table * gnc_book_get_commodity_table(GNCBook *book);

View File

@ -94,6 +94,7 @@ typedef struct gnc_price_lookup_helper_s
Timespec time;
} GNCPriceLookupHelper;
void gnc_pricedb_set_db(GNCBook *book, GNCPriceDB *db);
void gnc_pricedb_mark_clean(GNCPriceDB *db);
void gnc_pricedb_substitute_commodity(GNCPriceDB *db,
@ -101,4 +102,5 @@ void gnc_pricedb_substitute_commodity(GNCPriceDB *db,
gnc_commodity *new_c);
void gnc_price_set_guid (GNCPrice *p, const GUID *guid);
#endif

View File

@ -1,6 +1,7 @@
/********************************************************************
* gnc-pricedb.c -- a simple price database for gnucash. *
* Copyright (C) 2001 Rob Browning, Linas Vepstas *
* Copyright (C) 2001 Rob Browning *
* Copyright (C) 2001,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 *
@ -687,6 +688,25 @@ gnc_pricedb_destroy(GNCPriceDB *db)
/* ==================================================================== */
#define GNC_PRICEDB "gnc_pricedb"
GNCPriceDB *
gnc_pricedb_get_db(GNCBook *book)
{
if (!book) return NULL;
return gnc_book_get_data (book, GNC_PRICEDB);
}
void
gnc_pricedb_set_db(GNCBook *book, GNCPriceDB *db)
{
if(!book) return;
gnc_book_set_data (book, GNC_PRICEDB, db);
if (db) db->book = book;
}
/* ==================================================================== */
gboolean
gnc_pricedb_dirty(GNCPriceDB *p)
{

View File

@ -227,9 +227,15 @@ typedef struct gnc_price_db_s GNCPriceDB;
/** gnc_pricedb_create - create a new pricedb. Normally you won't need
this; you will get the pricedb via gnc_book_get_pricedb. */
this; you will get the pricedb via gnc_pricedb_get_db. */
GNCPriceDB * gnc_pricedb_create(GNCBook *book);
/* XXX backwards-compat defines, remove these someday */
#define gnc_book_get_pricedb gnc_pricedb_get_db
/** return the pricedb associated with the book */
GNCPriceDB * gnc_pricedb_get_db(GNCBook *book);
/** gnc_pricedb_destroy - destroy the given pricedb and unref all of
the prices it contains. This may not deallocate all of those
prices. Other code may still be holding references to them. */