commodities belong to books

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6471 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2002-01-02 04:28:32 +00:00
parent 1614997892
commit 9c12b44817
22 changed files with 94 additions and 64 deletions

View File

@ -190,7 +190,7 @@ account_commodity_handler (xmlNodePtr node, gpointer act_pdata)
struct account_pdata *pdata = act_pdata;
gnc_commodity *ref;
ref = dom_tree_to_commodity_ref_no_engine(node);
ref = dom_tree_to_commodity_ref_no_engine(node, pdata->book);
xaccAccountSetCommodity(pdata->account, ref);
return TRUE;
@ -214,7 +214,7 @@ account_currency_handler (xmlNodePtr node, gpointer act_pdata)
struct account_pdata *pdata = act_pdata;
gnc_commodity *ref;
ref = dom_tree_to_commodity_ref_no_engine(node);
ref = dom_tree_to_commodity_ref_no_engine(node, pdata->book);
DxaccAccountSetCurrency(pdata->account, ref, pdata->book);
return TRUE;
@ -238,7 +238,7 @@ account_security_handler (xmlNodePtr node, gpointer act_pdata)
struct account_pdata *pdata = act_pdata;
gnc_commodity *ref;
ref = dom_tree_to_commodity_ref_no_engine(node);
ref = dom_tree_to_commodity_ref_no_engine(node, pdata->book);
DxaccAccountSetSecurity(pdata->account, ref, pdata->book);
return TRUE;

View File

@ -178,7 +178,8 @@ gnc_commodity_end_handler(gpointer data_for_children,
g_return_val_if_fail(tree, FALSE);
com = gnc_commodity_new(NULL, NULL, NULL, NULL, 0);
com = gnc_commodity_new(NULL, NULL, NULL, NULL, 0,
(GNCBook *)gdata->bookdata);
for(achild = tree->xmlChildrenNode; achild; achild = achild->next)
{

View File

@ -580,7 +580,8 @@ tt_act_handler( xmlNodePtr node, gpointer data )
applies for
SchedXaction.c:xaccSchedXactionInit... */
com = gnc_commodity_new( "template", "template",
"template", "template", 1 );
"template", "template",
1, txd->book );
xaccAccountSetCommodity( acc, com );
}

View File

@ -437,7 +437,7 @@ trn_currency_handler(xmlNodePtr node, gpointer trans_pdata)
Transaction *trn = pdata->trans;
gnc_commodity *ref;
ref = dom_tree_to_commodity_ref_no_engine(node);
ref = dom_tree_to_commodity_ref_no_engine(node, pdata->book);
xaccTransSetCurrency(trn, ref);
return TRUE;

View File

@ -387,7 +387,7 @@ gnc_commodity_import_legacy(GNCBook *book, const char * currency_name)
if(!old) {
old = gnc_commodity_new(currency_name,
GNC_COMMODITY_NS_LEGACY, currency_name,
0, 100000);
0, 100000, book);
old = gnc_commodity_table_insert(table, old);
}
return old;

View File

@ -1961,7 +1961,8 @@ commodity_restore_end_handler(gpointer data_for_children,
cpi->space,
cpi->id,
cpi->xcode,
cpi->fraction);
cpi->fraction,
pstatus->book);
if(comm)
{
gnc_commodity_table *ctab;

View File

@ -659,7 +659,7 @@ failure:
gnc_commodity *
dom_tree_to_commodity_ref_no_engine(xmlNodePtr node)
dom_tree_to_commodity_ref_no_engine(xmlNodePtr node, GNCBook *book)
{
/* Turn something like this
@ -714,7 +714,7 @@ dom_tree_to_commodity_ref_no_engine(xmlNodePtr node)
} else {
g_strstrip(space_str);
g_strstrip(id_str);
c = gnc_commodity_new(NULL, space_str, id_str, NULL, 0);
c = gnc_commodity_new(NULL, space_str, id_str, NULL, 0, book);
}
g_free(space_str);
@ -730,7 +730,7 @@ dom_tree_to_commodity_ref(xmlNodePtr node, GNCBook *book)
gnc_commodity *ret;
gnc_commodity_table *table;
daref = dom_tree_to_commodity_ref_no_engine(node);
daref = dom_tree_to_commodity_ref_no_engine(node, book);
table = gnc_book_get_commodity_table (book);

View File

@ -42,7 +42,7 @@
GUID* dom_tree_to_guid(xmlNodePtr node);
gnc_commodity* dom_tree_to_commodity_ref(xmlNodePtr node, GNCBook *book);
gnc_commodity *dom_tree_to_commodity_ref_no_engine(xmlNodePtr node);
gnc_commodity *dom_tree_to_commodity_ref_no_engine(xmlNodePtr node, GNCBook *);
FreqSpec* dom_tree_to_freqSpec( xmlNodePtr node, GNCBook *book);

View File

@ -35,10 +35,10 @@ test_dom_tree_to_commodity_ref(void)
test_str1 = get_random_string();
test_str2 = get_random_string();
test_com1 = gnc_commodity_new(NULL, test_str1, test_str2, NULL, 0);
test_com1 = gnc_commodity_new(NULL, test_str1, test_str2, NULL, 0, NULL);
test_node = commodity_ref_to_dom_tree("test-com", test_com1);
test_com2 = dom_tree_to_commodity_ref_no_engine(test_node);
test_com2 = dom_tree_to_commodity_ref_no_engine(test_node, NULL);
do_test(gnc_commodity_equiv(test_com1, test_com2),
"dom_tree_to_commodity_ref_no_engine");

View File

@ -181,14 +181,14 @@ equals_node_val_vs_guid(xmlNodePtr node, const GUID *id)
}
gboolean
equals_node_val_vs_commodity(xmlNodePtr node, const gnc_commodity *com)
equals_node_val_vs_commodity(xmlNodePtr node, const gnc_commodity *com, GNCBook *book)
{
gnc_commodity *cmpcom;
g_return_val_if_fail(node, FALSE);
g_return_val_if_fail(com, FALSE);
cmpcom = dom_tree_to_commodity_ref_no_engine(node);
cmpcom = dom_tree_to_commodity_ref_no_engine(node, book);
g_return_val_if_fail(cmpcom, FALSE);

View File

@ -34,7 +34,7 @@ gboolean check_dom_tree_version(xmlNodePtr node, gchar *verstr);
gboolean equals_node_val_vs_string(xmlNodePtr node, const gchar* str);
gboolean equals_node_val_vs_guid(xmlNodePtr node, const GUID *id);
gboolean equals_node_val_vs_commodity(xmlNodePtr node,
const gnc_commodity *com);
const gnc_commodity *com, GNCBook *);
gboolean equals_node_val_vs_kvp_frame(xmlNodePtr node, const kvp_frame *frm);
gboolean equals_node_val_vs_date(xmlNodePtr node, const Timespec tm);
gboolean equals_node_val_vs_int(xmlNodePtr node, gint64 val);

View File

@ -93,7 +93,7 @@ node_and_account_equal(xmlNodePtr node, Account *act)
else if(safe_strcmp(mark->name, "act:commodity") == 0)
{
if(!equals_node_val_vs_commodity(
mark, xaccAccountGetCommodity(act)))
mark, xaccAccountGetCommodity(act), xaccAccountGetBook(act)))
{
return g_strdup("commodities differ");
}
@ -101,7 +101,7 @@ node_and_account_equal(xmlNodePtr node, Account *act)
else if(safe_strcmp(mark->name, "act:currency") == 0)
{
if(!equals_node_val_vs_commodity(
mark, DxaccAccountGetCurrency(act, book)))
mark, DxaccAccountGetCurrency(act, book), xaccAccountGetBook(act)))
{
return g_strdup("currencies differ");
}
@ -124,7 +124,7 @@ node_and_account_equal(xmlNodePtr node, Account *act)
else if(safe_strcmp(mark->name, "act:security") == 0)
{
if(!equals_node_val_vs_commodity(
mark, DxaccAccountGetSecurity(act, book)))
mark, DxaccAccountGetSecurity(act, book), xaccAccountGetBook(act)))
{
return g_strdup("securities differ");
}

View File

@ -194,6 +194,14 @@ equals_node_val_vs_splits(xmlNodePtr node, const Transaction *trn)
return TRUE;
}
static GNCBook *
xaccTransGetBook (Transaction *trn)
{
Split *s = xaccTransGetSplit (trn, 0);
Account *acc = xaccSplitGetAccount(s);
return xaccAccountGetBook (acc);
}
static gchar*
node_and_transaction_equal(xmlNodePtr node, Transaction *trn)
{
@ -227,7 +235,7 @@ node_and_transaction_equal(xmlNodePtr node, Transaction *trn)
else if(safe_strcmp(mark->name, "trn:currency") == 0)
{
if(!equals_node_val_vs_commodity(
mark, xaccTransGetCurrency(trn)))
mark, xaccTransGetCurrency(trn), xaccTransGetBook(trn)))
{
return g_strdup("currencies differ");
}

View File

@ -80,7 +80,7 @@ xaccSchedXactionInit( SchedXaction *sx, GNCBook *book)
xaccAccountSetCommodity
(sx->template_acct,
gnc_commodity_new( "template", "template",
"template", "template", 1 ) );
"template", "template", 1, book ) );
g_free( name );
xaccAccountSetType( sx->template_acct, BANK );
ag = gnc_book_get_template_group( book );

View File

@ -86,7 +86,7 @@ gnc_book_init (GNCBook *book)
if(book->commodity_table)
{
if(!gnc_commodity_table_add_default_data(book->commodity_table))
if(!gnc_commodity_table_add_default_data(book->commodity_table, book))
PWARN("unable to initialize book's commodity_table");
}

View File

@ -42,26 +42,27 @@ static short module = MOD_ENGINE;
* of the smallest-transactional-units of the currency are there
* in a 'unitname' unit. */
struct _gnc_commodity {
char * fullname;
char * namespace;
char * mnemonic;
char * printname;
char * exchange_code; /* CUSIP or other identifying code */
int fraction;
char * unique_name;
gint16 mark; /* user-defined mark, handy for traversals */
struct gnc_commodity_s {
GNCBook * book;
char * fullname;
char * namespace;
char * mnemonic;
char * printname;
char * exchange_code; /* CUSIP or other identifying code */
int fraction;
char * unique_name;
gint16 mark; /* user-defined mark, handy for traversals */
};
struct _gnc_commodity_namespace {
struct gnc_commodity_namespace_s {
GHashTable * table;
};
struct _gnc_commodity_table {
struct gnc_commodity_table_s {
GHashTable * table;
};
typedef struct _gnc_commodity_namespace gnc_commodity_namespace;
typedef struct gnc_commodity_namespace_s gnc_commodity_namespace;
/********************************************************************
* gnc_commodity_new
@ -89,10 +90,11 @@ gnc_commodity *
gnc_commodity_new(const char * fullname,
const char * namespace, const char * mnemonic,
const char * exchange_code,
int fraction)
int fraction, GNCBook *book)
{
gnc_commodity * retval = g_new0(gnc_commodity, 1);
retval->book = book;
retval->fullname = g_strdup(fullname);
retval->namespace = g_strdup(namespace);
retval->mnemonic = g_strdup(mnemonic);
@ -145,7 +147,8 @@ gnc_commodity_destroy(gnc_commodity * cm)
********************************************************************/
const char *
gnc_commodity_get_mnemonic(const gnc_commodity * cm) {
gnc_commodity_get_mnemonic(const gnc_commodity * cm)
{
if(!cm) return NULL;
return cm->mnemonic;
}
@ -155,7 +158,8 @@ gnc_commodity_get_mnemonic(const gnc_commodity * cm) {
********************************************************************/
const char *
gnc_commodity_get_printname(const gnc_commodity * cm) {
gnc_commodity_get_printname(const gnc_commodity * cm)
{
if(!cm) return NULL;
return cm->printname;
}
@ -166,7 +170,8 @@ gnc_commodity_get_printname(const gnc_commodity * cm) {
********************************************************************/
const char *
gnc_commodity_get_namespace(const gnc_commodity * cm) {
gnc_commodity_get_namespace(const gnc_commodity * cm)
{
if(!cm) return NULL;
return cm->namespace;
}
@ -177,7 +182,8 @@ gnc_commodity_get_namespace(const gnc_commodity * cm) {
********************************************************************/
const char *
gnc_commodity_get_fullname(const gnc_commodity * cm) {
gnc_commodity_get_fullname(const gnc_commodity * cm)
{
if(!cm) return NULL;
return cm->fullname;
}
@ -188,7 +194,8 @@ gnc_commodity_get_fullname(const gnc_commodity * cm) {
********************************************************************/
const char *
gnc_commodity_get_unique_name(const gnc_commodity * cm) {
gnc_commodity_get_unique_name(const gnc_commodity * cm)
{
if(!cm) return NULL;
return cm->unique_name;
}
@ -199,7 +206,8 @@ gnc_commodity_get_unique_name(const gnc_commodity * cm) {
********************************************************************/
const char *
gnc_commodity_get_exchange_code(const gnc_commodity * cm) {
gnc_commodity_get_exchange_code(const gnc_commodity * cm)
{
if(!cm) return NULL;
return cm->exchange_code;
}
@ -209,7 +217,8 @@ gnc_commodity_get_exchange_code(const gnc_commodity * cm) {
********************************************************************/
int
gnc_commodity_get_fraction(const gnc_commodity * cm) {
gnc_commodity_get_fraction(const gnc_commodity * cm)
{
if(!cm) return 0;
return cm->fraction;
}
@ -219,11 +228,19 @@ gnc_commodity_get_fraction(const gnc_commodity * cm) {
********************************************************************/
gint16
gnc_commodity_get_mark(const gnc_commodity * cm) {
gnc_commodity_get_mark(const gnc_commodity * cm)
{
if(!cm) return 0;
return cm->mark;
}
GNCBook *
gnc_commodity_get_book(const gnc_commodity * cm)
{
if(!cm) return NULL;
return cm->book;
}
/********************************************************************
* gnc_commodity_set_mnemonic
********************************************************************/
@ -859,7 +876,8 @@ gnc_commodity_table_equal(gnc_commodity_table *t_1,
********************************************************************/
gboolean
gnc_commodity_table_add_default_data(gnc_commodity_table *table)
gnc_commodity_table_add_default_data(gnc_commodity_table *table,
GNCBook *book)
{
#include "./iso-4217-currencies.c"

View File

@ -25,9 +25,7 @@
#define GNC_COMMODITY_H
#include <glib.h>
typedef struct _gnc_commodity gnc_commodity;
typedef struct _gnc_commodity_table gnc_commodity_table;
#include "gnc-engine.h"
#define GNC_COMMODITY_NS_LEGACY "GNC_LEGACY_CURRENCIES"
#define GNC_COMMODITY_NS_ISO "ISO4217"
@ -43,7 +41,8 @@ gnc_commodity * gnc_commodity_new(const char * fullname,
const char * namespace,
const char * mnemonic,
const char * exchange_code,
int fraction);
int fraction,
GNCBook *);
void gnc_commodity_destroy(gnc_commodity * cm);
@ -55,6 +54,7 @@ const char * gnc_commodity_get_exchange_code(const gnc_commodity * cm);
const char * gnc_commodity_get_unique_name(const gnc_commodity * cm);
int gnc_commodity_get_fraction(const gnc_commodity * cm);
gint16 gnc_commodity_get_mark(const gnc_commodity * cm);
GNCBook * gnc_commodity_get_book(const gnc_commodity * cm);
void gnc_commodity_set_mnemonic(gnc_commodity * cm, const char * mnemonic);
void gnc_commodity_set_namespace(gnc_commodity * cm, const char * namespace);
@ -117,6 +117,6 @@ gboolean gnc_commodity_table_foreach_commodity(gnc_commodity_table * table,
gpointer user_data),
gpointer user_data);
gboolean gnc_commodity_table_add_default_data(gnc_commodity_table *table);
gboolean gnc_commodity_table_add_default_data(gnc_commodity_table *table, GNCBook*);
#endif

View File

@ -27,16 +27,16 @@
#include <glib.h>
#include "gnc-commodity.h"
/** TYPES **********************************************************/
typedef struct account_s Account;
typedef struct account_group_s AccountGroup;
typedef struct split_s Split;
typedef struct transaction_s Transaction;
typedef struct gnc_book_struct GNCBook;
typedef struct gnc_session_struct GNCSession;
typedef struct account_s Account;
typedef struct account_group_s AccountGroup;
typedef struct split_s Split;
typedef struct transaction_s Transaction;
typedef struct gnc_book_struct GNCBook;
typedef struct gnc_session_struct GNCSession;
typedef struct gnc_commodity_s gnc_commodity;
typedef struct gnc_commodity_table_s gnc_commodity_table;
typedef GList AccountList;
typedef GList SplitList;

View File

@ -2143,7 +2143,8 @@ of having a parent transaction with which one is working...")
((<gw:m-chars-caller-owned> gw:const) namespace)
((<gw:m-chars-caller-owned> gw:const) mnemonic)
((<gw:m-chars-caller-owned> gw:const) exchange-code)
(<gw:int> smallest-fraction))
(<gw:int> smallest-fraction)
(<gnc:Book*> book))
"Create a new gnc_commodity object.")
(gw:wrap-function

View File

@ -37,7 +37,7 @@ exec guile -s $0 "$@"
~S,
~S,
~S,
~S);\n
~S, book);\n
if(!c) {
PWARN(\"failed to create commodity for currency %s\", fullname);
} else {

View File

@ -1128,7 +1128,7 @@ get_random_commodity (GNCBook *book)
xcode = get_random_string();
ran_int = get_random_int_in_range(1, 100000);
ret = gnc_commodity_new (name, space, mn, xcode, ran_int);
ret = gnc_commodity_new (name, space, mn, xcode, ran_int, book);
g_free(mn);
g_free(name);

View File

@ -16,7 +16,7 @@ test_commodity(void)
gnc_commodity *com;
{
com = gnc_commodity_new(NULL, NULL, NULL, NULL, 0);
com = gnc_commodity_new(NULL, NULL, NULL, NULL, 0, NULL);
gnc_commodity_destroy(com);
@ -38,7 +38,7 @@ test_commodity(void)
fraction = get_random_int_in_range(0, 10000);
com = gnc_commodity_new(fullname, namespace, mnemonic,
exchange_code, fraction);
exchange_code, fraction, NULL);
do_test(
com != NULL, "commodity with data new and destroy");
@ -94,7 +94,7 @@ test_commodity(void)
"reset fraction code equal test");
com2 = gnc_commodity_new(fullname, namespace, mnemonic,
exchange_code, fraction);
exchange_code, fraction, NULL);
do_test(
gnc_commodity_equiv(com, com2), "commodity equiv");