Add xaccAccountTypesCompatibleWith and change xaccAccountTypesCompatible

to use that.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@14894 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Andreas Köhler 2006-09-26 22:07:55 +00:00
parent c77679c601
commit e15f0d6a7b
2 changed files with 45 additions and 39 deletions

View File

@ -2179,14 +2179,10 @@ xaccAccountGetTypeFromStr (const gchar *str)
/********************************************************************\ /********************************************************************\
\********************************************************************/ \********************************************************************/
gboolean guint32
xaccAccountTypesCompatible (GNCAccountType parent_type, xaccAccountTypesCompatibleWith (GNCAccountType type)
GNCAccountType child_type)
{ {
gboolean compatible = FALSE; switch (type) {
switch(parent_type)
{
case ACCT_TYPE_BANK: case ACCT_TYPE_BANK:
case ACCT_TYPE_CASH: case ACCT_TYPE_CASH:
case ACCT_TYPE_ASSET: case ACCT_TYPE_ASSET:
@ -2197,31 +2193,38 @@ xaccAccountTypesCompatible (GNCAccountType parent_type,
case ACCT_TYPE_LIABILITY: case ACCT_TYPE_LIABILITY:
case ACCT_TYPE_RECEIVABLE: case ACCT_TYPE_RECEIVABLE:
case ACCT_TYPE_PAYABLE: case ACCT_TYPE_PAYABLE:
compatible = ((child_type == ACCT_TYPE_BANK) || return
(child_type == ACCT_TYPE_CASH) || (1 << ACCT_TYPE_BANK) |
(child_type == ACCT_TYPE_ASSET) || (1 << ACCT_TYPE_CASH) |
(child_type == ACCT_TYPE_STOCK) || (1 << ACCT_TYPE_ASSET) |
(child_type == ACCT_TYPE_MUTUAL) || (1 << ACCT_TYPE_STOCK) |
(child_type == ACCT_TYPE_CURRENCY) || (1 << ACCT_TYPE_MUTUAL) |
(child_type == ACCT_TYPE_CREDIT) || (1 << ACCT_TYPE_CURRENCY) |
(child_type == ACCT_TYPE_LIABILITY)|| (1 << ACCT_TYPE_CREDIT) |
(child_type == ACCT_TYPE_RECEIVABLE)|| (1 << ACCT_TYPE_LIABILITY) |
(child_type == ACCT_TYPE_PAYABLE)); (1 << ACCT_TYPE_RECEIVABLE) |
break; (1 << ACCT_TYPE_PAYABLE);
case ACCT_TYPE_INCOME: case ACCT_TYPE_INCOME:
case ACCT_TYPE_EXPENSE: case ACCT_TYPE_EXPENSE:
compatible = ((child_type == ACCT_TYPE_INCOME) || return
(child_type == ACCT_TYPE_EXPENSE)); (1 << ACCT_TYPE_INCOME) |
break; (1 << ACCT_TYPE_EXPENSE);
case ACCT_TYPE_EQUITY: case ACCT_TYPE_EQUITY:
compatible = (child_type == ACCT_TYPE_EQUITY); return
break; (1 << ACCT_TYPE_EQUITY);
default: default:
PERR("bad account type: %d", parent_type); PERR("bad account type: %d", type);
break; return 0;
} }
}
return compatible; gboolean
xaccAccountTypesCompatible (GNCAccountType parent_type,
GNCAccountType child_type)
{
return ((xaccAccountTypesCompatibleWith (parent_type) &
(1 << child_type))
!= 0);
} }
guint32 guint32

View File

@ -523,6 +523,9 @@ const char * xaccAccountGetTypeStr (GNCAccountType type);
* to the local language. */ * to the local language. */
GNCAccountType xaccAccountGetTypeFromStr (const gchar *str); GNCAccountType xaccAccountGetTypeFromStr (const gchar *str);
/** Return the bitmask of account types compatible with a given type. */
guint32 xaccAccountTypesCompatibleWith (GNCAccountType type);
/** Return TRUE if accounts of type parent_type can have accounts /** Return TRUE if accounts of type parent_type can have accounts
* of type child_type as children. */ * of type child_type as children. */
gboolean xaccAccountTypesCompatible (GNCAccountType parent_type, gboolean xaccAccountTypesCompatible (GNCAccountType parent_type,