mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
more account-info stuff
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1537 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
4f34df719c
commit
275f8c844e
@ -23,6 +23,7 @@
|
||||
#include "AccInfo.h"
|
||||
#include "AccInfoP.h"
|
||||
#include "messages.h"
|
||||
#include "util.h"
|
||||
|
||||
/* =========================================================== */
|
||||
|
||||
@ -56,6 +57,38 @@ char * xaccAccountGetTypeStr (int type)
|
||||
|
||||
/* =========================================================== */
|
||||
|
||||
AccInfo *
|
||||
xaccMallocAccInfo (int typo)
|
||||
{
|
||||
AccInfo *u = NULL;
|
||||
if ((STOCK == typo) || (MUTUAL == typo)) {
|
||||
u = (AccInfo *) xaccMallocInvAcct ();
|
||||
u->inv_acct.type = typo;
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
void
|
||||
xaccFreeAccInfo (AccInfo *u)
|
||||
{
|
||||
if (!u) return;
|
||||
if ((STOCK == u->type) || (MUTUAL == u->type)) {
|
||||
xaccFreeInvAcct ( &(u->inv_acct));
|
||||
}
|
||||
}
|
||||
|
||||
InvAcct *
|
||||
xaccCastToInvAcct (AccInfo *u)
|
||||
{
|
||||
if (!u) return NULL;
|
||||
if ((STOCK == u->type) || (MUTUAL == u->type)) {
|
||||
return ( &(u->inv_acct));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* =========================================================== */
|
||||
|
||||
InvAcct *
|
||||
xaccMallocInvAcct (void)
|
||||
{
|
||||
@ -69,7 +102,7 @@ void
|
||||
xaccInitInvAcct (InvAcct *iacc)
|
||||
{
|
||||
if (!iacc) return;
|
||||
iacc->type = -1;
|
||||
iacc->type = STOCK;
|
||||
iacc->pricesrc = NULL;
|
||||
iacc->brokerid = NULL;
|
||||
iacc->acctid = NULL;
|
||||
@ -83,6 +116,10 @@ void
|
||||
xaccFreeInvAcct (InvAcct *iacc)
|
||||
{
|
||||
if (!iacc) return;
|
||||
|
||||
/* if the wrong type then a miscast. can't free. */
|
||||
assert ((STOCK == iacc->type) || (MUTUAL == iacc->type));
|
||||
|
||||
if (iacc->pricesrc) { free(iacc->pricesrc); iacc->pricesrc = NULL; }
|
||||
if (iacc->brokerid) { free(iacc->brokerid); iacc->brokerid = NULL; }
|
||||
if (iacc->acctid) { free(iacc->acctid); iacc->acctid = NULL; }
|
||||
|
@ -98,6 +98,17 @@ typedef struct _BankAcct BankAcct;
|
||||
typedef struct _InvAcct InvAcct;
|
||||
typedef union _AccInfo AccInfo;
|
||||
|
||||
|
||||
/* The AccInfo structure is just a union of the other account
|
||||
* auxilliary info types. The xaccCastToXXX() functions simply
|
||||
* provide a safe upcast mechanism (similar to that in C++ ...
|
||||
* returns the address if the cast is safe, otherwise returns NULL).
|
||||
*/
|
||||
AccInfo * xaccMallocAccInfo (int typo);
|
||||
void xaccFreeAccInfo (AccInfo *u);
|
||||
InvAcct * xaccCastToInvAcct (AccInfo *);
|
||||
|
||||
|
||||
InvAcct * xaccMallocInvAcct (void);
|
||||
void xaccInitInvAcct (InvAcct *iacc);
|
||||
void xaccFreeInvAcct (InvAcct *iacc);
|
||||
|
@ -124,16 +124,10 @@ xaccFreeAccount( Account *acc )
|
||||
|
||||
if (NULL == acc) return;
|
||||
|
||||
/* recursively free children */
|
||||
/* First, recursively free children */
|
||||
xaccFreeAccountGroup (acc->children);
|
||||
|
||||
if (acc->accountName) free (acc->accountName);
|
||||
if (acc->accountCode) free (acc->accountCode);
|
||||
if (acc->description) free (acc->description);
|
||||
if (acc->notes) free (acc->notes);
|
||||
if (acc->currency) free (acc->currency);
|
||||
if (acc->security) free (acc->security);
|
||||
|
||||
/* Next, clean up the splits */
|
||||
/* any split pointing at this account needs to be unmarked */
|
||||
for (i=0; i<acc->numSplits; i++) {
|
||||
s = acc->splits[i];
|
||||
@ -158,6 +152,17 @@ xaccFreeAccount( Account *acc )
|
||||
acc->splits = NULL;
|
||||
acc->numSplits = 0;
|
||||
|
||||
/* Finally, clean up the account info */
|
||||
if (acc->accInfo) xaccFreeAccInfo (acc->accInfo);
|
||||
acc->accInfo = NULL;
|
||||
|
||||
if (acc->accountName) free (acc->accountName);
|
||||
if (acc->accountCode) free (acc->accountCode);
|
||||
if (acc->description) free (acc->description);
|
||||
if (acc->notes) free (acc->notes);
|
||||
if (acc->currency) free (acc->currency);
|
||||
if (acc->security) free (acc->security);
|
||||
|
||||
/* zero out values, just in case stray
|
||||
* pointers are pointing here. */
|
||||
|
||||
@ -840,6 +845,10 @@ xaccAccountSetType (Account *acc, int tip)
|
||||
/* refuse invalid account types */
|
||||
if (NUM_ACCOUNT_TYPES <= tip) return;
|
||||
acc->type = tip;
|
||||
|
||||
/* initialize the auxilliary account info as well */
|
||||
if (acc->accInfo) xaccFreeAccInfo (acc->accInfo);
|
||||
acc->accInfo = xaccMallocAccountInfo (tip);
|
||||
}
|
||||
|
||||
void
|
||||
@ -945,6 +954,13 @@ xaccAccountSetSecurity (Account *acc, char *str)
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
AccInfo *
|
||||
xaccAccountGetAccInfo (Account *acc)
|
||||
{
|
||||
if (!acc) return NULL;
|
||||
return (acc->accInfo);
|
||||
}
|
||||
|
||||
AccountGroup *
|
||||
xaccAccountGetChildren (Account *acc)
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
/********************************************************************\
|
||||
* Account.h -- the Account data structure *
|
||||
* Copyright (C) 1997 Robin D. Clark *
|
||||
* Copyright (C) 1997, 1998 Linas Vepstas *
|
||||
* Copyright (C) 1997, 1998, 1999 Linas Vepstas *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
@ -139,6 +139,7 @@ char * xaccAccountGetCurrency (Account *);
|
||||
char * xaccAccountGetSecurity (Account *);
|
||||
AccountGroup * xaccAccountGetChildren (Account *);
|
||||
AccountGroup * xaccAccountGetParent (Account *);
|
||||
AccInfo * xaccAccountGetAccInfo (Account *);
|
||||
|
||||
double xaccAccountGetBalance (Account *);
|
||||
double xaccAccountGetClearedBalance (Account *);
|
||||
|
Loading…
Reference in New Issue
Block a user