r18851 - gnucash/trunk/src - MSVC compatiblity: Replace QOF_BOOK_LOOKUP_ENTITY macro by a RETURN_ENTITY macro and add inline functions for lookup.
Christian Stimming
cstim at code.gnucash.org
Sat Mar 6 06:01:38 EST 2010
Author: cstim
Date: 2010-03-06 06:01:37 -0500 (Sat, 06 Mar 2010)
New Revision: 18851
Trac: http://svn.gnucash.org/trac/changeset/18851
Modified:
gnucash/trunk/src/business/business-core/gncBillTerm.h
gnucash/trunk/src/business/business-core/gncCustomer.h
gnucash/trunk/src/business/business-core/gncEmployee.h
gnucash/trunk/src/business/business-core/gncEntry.h
gnucash/trunk/src/business/business-core/gncInvoice.h
gnucash/trunk/src/business/business-core/gncJob.h
gnucash/trunk/src/business/business-core/gncOrder.h
gnucash/trunk/src/business/business-core/gncTaxTable.h
gnucash/trunk/src/business/business-core/gncVendor.h
gnucash/trunk/src/libqof/qof/qofbook.h
Log:
MSVC compatiblity: Replace QOF_BOOK_LOOKUP_ENTITY macro by a RETURN_ENTITY macro and add inline functions for lookup.
MSVC doesn't accept the syntax with an inlined block,
x = ({ foo; bar; value;}). Hence, this is being replaced
by actual function definitions, and the body of those functions
is defined by the new macro.
Modified: gnucash/trunk/src/business/business-core/gncBillTerm.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncBillTerm.h 2010-03-06 11:01:16 UTC (rev 18850)
+++ gnucash/trunk/src/business/business-core/gncBillTerm.h 2010-03-06 11:01:37 UTC (rev 18851)
@@ -119,8 +119,10 @@
* Equivalent function prototype is
* GncBillTerm * gncBillTermLookup (QofBook *book, const GUID *guid);
*/
-#define gncBillTermLookup(book,guid) \
- QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_BILLTERM, GncBillTerm)
+static inline GncBillTerm * gncBillTermLookup (const QofBook *book, const GUID *guid)
+{
+ QOF_BOOK_RETURN_ENTITY(book, guid,GNC_ID_BILLTERM, GncBillTerm);
+}
GncBillTerm *gncBillTermLookupByName (QofBook *book, const char *name);
GList * gncBillTermGetTerms (QofBook *book);
Modified: gnucash/trunk/src/business/business-core/gncCustomer.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomer.h 2010-03-06 11:01:16 UTC (rev 18850)
+++ gnucash/trunk/src/business/business-core/gncCustomer.h 2010-03-06 11:01:37 UTC (rev 18851)
@@ -115,8 +115,10 @@
* Equivalent function prototype is
* GncCustomer * gncCustomerLookup (QofBook *book, const GUID *guid);
*/
-#define gncCustomerLookup(book,guid) \
- QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_CUSTOMER, GncCustomer)
+static inline GncCustomer * gncCustomerLookup (const QofBook *book, const GUID *guid)
+{
+ QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_CUSTOMER, GncCustomer);
+}
const char * gncCustomerGetID (const GncCustomer *customer);
const char * gncCustomerGetName (const GncCustomer *customer);
Modified: gnucash/trunk/src/business/business-core/gncEmployee.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncEmployee.h 2010-03-06 11:01:16 UTC (rev 18850)
+++ gnucash/trunk/src/business/business-core/gncEmployee.h 2010-03-06 11:01:37 UTC (rev 18851)
@@ -99,8 +99,10 @@
* Equivalent function prototype is
* GncEmployee * gncEmployeeLookup (QofBook *book, const GUID *guid);
*/
-#define gncEmployeeLookup(book,guid) \
- QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_EMPLOYEE, GncEmployee)
+static inline GncEmployee * gncEmployeeLookup (const QofBook *book, const GUID *guid)
+{
+ QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_EMPLOYEE, GncEmployee);
+}
gboolean gncEmployeeIsDirty (const GncEmployee *employee);
Modified: gnucash/trunk/src/business/business-core/gncEntry.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncEntry.h 2010-03-06 11:01:16 UTC (rev 18850)
+++ gnucash/trunk/src/business/business-core/gncEntry.h 2010-03-06 11:01:37 UTC (rev 18851)
@@ -222,8 +222,10 @@
* Equivalent function prototype is
* GncEntry * gncEntryLookup (QofBook *book, const GUID *guid);
*/
-#define gncEntryLookup(book,guid) \
- QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_ENTRY, GncEntry)
+static inline GncEntry * gncEntryLookup (const QofBook *book, const GUID *guid)
+{
+ QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_ENTRY, GncEntry);
+}
gboolean gncEntryIsOpen (const GncEntry *entry);
void gncEntryBeginEdit (GncEntry *entry);
Modified: gnucash/trunk/src/business/business-core/gncInvoice.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoice.h 2010-03-06 11:01:16 UTC (rev 18850)
+++ gnucash/trunk/src/business/business-core/gncInvoice.h 2010-03-06 11:01:37 UTC (rev 18851)
@@ -185,8 +185,10 @@
* Equivalent function prototype is
* GncInvoice * gncInvoiceLookup (QofBook *book, const GUID *guid);
*/
-#define gncInvoiceLookup(book,guid) \
- QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_INVOICE, GncInvoice)
+static inline GncInvoice * gncInvoiceLookup (const QofBook *book, const GUID *guid)
+{
+ QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_INVOICE, GncInvoice);
+}
void gncInvoiceBeginEdit (GncInvoice *invoice);
void gncInvoiceCommitEdit (GncInvoice *invoice);
Modified: gnucash/trunk/src/business/business-core/gncJob.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncJob.h 2010-03-06 11:01:16 UTC (rev 18850)
+++ gnucash/trunk/src/business/business-core/gncJob.h 2010-03-06 11:01:37 UTC (rev 18851)
@@ -90,8 +90,10 @@
* Equivalent function prototype is
* GncJob * gncJobLookup (QofBook *book, const GUID *guid);
*/
-#define gncJobLookup(book,guid) \
- QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_JOB, GncJob)
+static inline GncJob * gncJobLookup (const QofBook *book, const GUID *guid)
+{
+ QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_JOB, GncJob);
+}
/* Other functions */
Modified: gnucash/trunk/src/business/business-core/gncOrder.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncOrder.h 2010-03-06 11:01:16 UTC (rev 18850)
+++ gnucash/trunk/src/business/business-core/gncOrder.h 2010-03-06 11:01:37 UTC (rev 18851)
@@ -101,8 +101,10 @@
* Equivalent function prototype is
* GncOrder * gncOrderLookup (QofBook *book, const GUID *guid);
*/
-#define gncOrderLookup(book,guid) \
- QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_ORDER, GncOrder)
+static inline GncOrder * gncOrderLookup (const QofBook *book, const GUID *guid)
+{
+ QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_ORDER, GncOrder);
+}
#define ORDER_ID "id"
#define ORDER_REFERENCE "reference"
Modified: gnucash/trunk/src/business/business-core/gncTaxTable.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncTaxTable.h 2010-03-06 11:01:16 UTC (rev 18850)
+++ gnucash/trunk/src/business/business-core/gncTaxTable.h 2010-03-06 11:01:37 UTC (rev 18851)
@@ -144,8 +144,10 @@
* Equivalent function prototype is
* GncTaxTable * gncTaxTableLookup (QofBook *book, const GUID *guid);
*/
-#define gncTaxTableLookup(book,guid) \
- QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_TAXTABLE, GncTaxTable)
+static inline GncTaxTable *gncTaxTableLookup (const QofBook* book, const GUID *guid)
+{
+ QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_TAXTABLE, GncTaxTable);
+}
GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name);
Modified: gnucash/trunk/src/business/business-core/gncVendor.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncVendor.h 2010-03-06 11:01:16 UTC (rev 18850)
+++ gnucash/trunk/src/business/business-core/gncVendor.h 2010-03-06 11:01:37 UTC (rev 18851)
@@ -112,8 +112,10 @@
* Equivalent function prototype is
* GncVendor * gncVendorLookup (QofBook *book, const GUID *guid);
*/
-#define gncVendorLookup(book,guid) \
- QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_VENDOR, GncVendor)
+static inline GncVendor * gncVendorLookup (const QofBook *book, const GUID *guid)
+{
+ QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_VENDOR, GncVendor);
+}
#define VENDOR_ID "id"
#define VENDOR_NAME "name"
Modified: gnucash/trunk/src/libqof/qof/qofbook.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.h 2010-03-06 11:01:16 UTC (rev 18850)
+++ gnucash/trunk/src/libqof/qof/qofbook.h 2010-03-06 11:01:37 UTC (rev 18851)
@@ -131,17 +131,22 @@
* used for anchoring data.
*/
-/** Lookup an entity by guid, returning pointer to the entity */
-#define QOF_BOOK_LOOKUP_ENTITY(book,guid,e_type,c_type) ({ \
- QofInstance *val = NULL; \
- if ((guid != NULL) && (book != NULL)) { \
- QofCollection *col; \
+/** This macro looks up an entity by GUID and returns a pointer to the
+ * entity by ending with a "return" statement. Hence, this macro can
+ * only be used as the last statement in the definition of a function,
+ * but not somewhere inline in the code. */
+#define QOF_BOOK_RETURN_ENTITY(book,guid,e_type,c_type) { \
+ QofInstance *val = NULL; \
+ if ((guid != NULL) && (book != NULL)) { \
+ const QofCollection *col; \
col = qof_book_get_collection (book, e_type); \
val = qof_collection_lookup_entity (col, guid); \
} \
- (c_type *) val; \
-})
+ return (c_type *) val; \
+}
+
+
/** GList of QofBook */
typedef GList QofBookList;
More information about the gnucash-changes
mailing list