From e15f0d6a7ba3d6a02a934f17678a32fabe0a9333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6hler?= Date: Tue, 26 Sep 2006 22:07:55 +0000 Subject: [PATCH] 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 --- src/engine/Account.c | 81 +++++++++++++++++++++++--------------------- src/engine/Account.h | 3 ++ 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/engine/Account.c b/src/engine/Account.c index 72ab252ec9..ddc8836a11 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -2179,49 +2179,52 @@ xaccAccountGetTypeFromStr (const gchar *str) /********************************************************************\ \********************************************************************/ +guint32 +xaccAccountTypesCompatibleWith (GNCAccountType type) +{ + switch (type) { + case ACCT_TYPE_BANK: + case ACCT_TYPE_CASH: + case ACCT_TYPE_ASSET: + case ACCT_TYPE_STOCK: + case ACCT_TYPE_MUTUAL: + case ACCT_TYPE_CURRENCY: + case ACCT_TYPE_CREDIT: + case ACCT_TYPE_LIABILITY: + case ACCT_TYPE_RECEIVABLE: + case ACCT_TYPE_PAYABLE: + return + (1 << ACCT_TYPE_BANK) | + (1 << ACCT_TYPE_CASH) | + (1 << ACCT_TYPE_ASSET) | + (1 << ACCT_TYPE_STOCK) | + (1 << ACCT_TYPE_MUTUAL) | + (1 << ACCT_TYPE_CURRENCY) | + (1 << ACCT_TYPE_CREDIT) | + (1 << ACCT_TYPE_LIABILITY) | + (1 << ACCT_TYPE_RECEIVABLE) | + (1 << ACCT_TYPE_PAYABLE); + case ACCT_TYPE_INCOME: + case ACCT_TYPE_EXPENSE: + return + (1 << ACCT_TYPE_INCOME) | + (1 << ACCT_TYPE_EXPENSE); + case ACCT_TYPE_EQUITY: + return + (1 << ACCT_TYPE_EQUITY); + default: + PERR("bad account type: %d", type); + return 0; + } +} + gboolean xaccAccountTypesCompatible (GNCAccountType parent_type, GNCAccountType child_type) { - gboolean compatible = FALSE; - - switch(parent_type) - { - case ACCT_TYPE_BANK: - case ACCT_TYPE_CASH: - case ACCT_TYPE_ASSET: - case ACCT_TYPE_STOCK: - case ACCT_TYPE_MUTUAL: - case ACCT_TYPE_CURRENCY: - case ACCT_TYPE_CREDIT: - case ACCT_TYPE_LIABILITY: - case ACCT_TYPE_RECEIVABLE: - case ACCT_TYPE_PAYABLE: - compatible = ((child_type == ACCT_TYPE_BANK) || - (child_type == ACCT_TYPE_CASH) || - (child_type == ACCT_TYPE_ASSET) || - (child_type == ACCT_TYPE_STOCK) || - (child_type == ACCT_TYPE_MUTUAL) || - (child_type == ACCT_TYPE_CURRENCY) || - (child_type == ACCT_TYPE_CREDIT) || - (child_type == ACCT_TYPE_LIABILITY)|| - (child_type == ACCT_TYPE_RECEIVABLE)|| - (child_type == ACCT_TYPE_PAYABLE)); - break; - case ACCT_TYPE_INCOME: - case ACCT_TYPE_EXPENSE: - compatible = ((child_type == ACCT_TYPE_INCOME) || - (child_type == ACCT_TYPE_EXPENSE)); - break; - case ACCT_TYPE_EQUITY: - compatible = (child_type == ACCT_TYPE_EQUITY); - break; - default: - PERR("bad account type: %d", parent_type); - break; - } - - return compatible; + return ((xaccAccountTypesCompatibleWith (parent_type) & + (1 << child_type)) + != 0); } guint32 diff --git a/src/engine/Account.h b/src/engine/Account.h index 4ce5db02ad..f5f2c8b7be 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -523,6 +523,9 @@ const char * xaccAccountGetTypeStr (GNCAccountType type); * to the local language. */ 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 * of type child_type as children. */ gboolean xaccAccountTypesCompatible (GNCAccountType parent_type,