r14894 - gnucash/trunk - Add xaccAccountTypesCompatibleWith and change xaccAccountTypesCompatible

Andreas Köhler andi5 at cvs.gnucash.org
Tue Sep 26 18:07:56 EDT 2006


Author: andi5
Date: 2006-09-26 18:07:55 -0400 (Tue, 26 Sep 2006)
New Revision: 14894
Trac: http://svn.gnucash.org/trac/changeset/14894

Modified:
   gnucash/trunk/
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/Account.h
Log:
Add xaccAccountTypesCompatibleWith and change xaccAccountTypesCompatible
to use that.



Property changes on: gnucash/trunk
___________________________________________________________________
Name: svk:merge
   - 3889ce50-311e-0410-a464-f059747ec5d1:/local/gnucash/trunk:638
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk:13351
   + 3889ce50-311e-0410-a464-f059747ec5d1:/local/gnucash/trunk:639
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk:13351

Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2006-09-26 22:07:42 UTC (rev 14893)
+++ gnucash/trunk/src/engine/Account.c	2006-09-26 22:07:55 UTC (rev 14894)
@@ -2179,49 +2179,52 @@
 /********************************************************************\
 \********************************************************************/
 
+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

Modified: gnucash/trunk/src/engine/Account.h
===================================================================
--- gnucash/trunk/src/engine/Account.h	2006-09-26 22:07:42 UTC (rev 14893)
+++ gnucash/trunk/src/engine/Account.h	2006-09-26 22:07:55 UTC (rev 14894)
@@ -523,6 +523,9 @@
  *  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,



More information about the gnucash-changes mailing list