gnucash stable: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Sun May 5 04:32:04 EDT 2024
Updated via https://github.com/Gnucash/gnucash/commit/d867a9d1 (commit)
via https://github.com/Gnucash/gnucash/commit/9e4b03f7 (commit)
via https://github.com/Gnucash/gnucash/commit/1e1d21b7 (commit)
via https://github.com/Gnucash/gnucash/commit/ef8afedd (commit)
via https://github.com/Gnucash/gnucash/commit/3bc7ce60 (commit)
via https://github.com/Gnucash/gnucash/commit/80997ee5 (commit)
via https://github.com/Gnucash/gnucash/commit/d405b589 (commit)
via https://github.com/Gnucash/gnucash/commit/c5caa55e (commit)
from https://github.com/Gnucash/gnucash/commit/a53ed8f5 (commit)
commit d867a9d18aa3748165d6c2b6d2a9bd146adc43e6
Merge: ef8afedd09 9e4b03f71b
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun May 5 14:36:43 2024 +0800
Merge branch 'TransactionP-hpp' into stable #1928
commit 9e4b03f71b8befd066b76c9ed2565ef5e8bbcd5a
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Apr 25 21:21:36 2024 +0800
[SplitP.hpp] rename to .hpp
diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt
index 202d910254..599fcc0077 100644
--- a/libgnucash/engine/CMakeLists.txt
+++ b/libgnucash/engine/CMakeLists.txt
@@ -6,7 +6,7 @@ add_subdirectory(mocks)
set(engine_noinst_HEADERS
AccountP.hpp
- SplitP.h
+ SplitP.hpp
SX-book.h
SX-ttinfo.h
TransactionP.hpp
diff --git a/libgnucash/engine/SplitP.h b/libgnucash/engine/SplitP.hpp
similarity index 98%
rename from libgnucash/engine/SplitP.h
rename to libgnucash/engine/SplitP.hpp
index 93cfe8312c..d13c2ffa1b 100644
--- a/libgnucash/engine/SplitP.h
+++ b/libgnucash/engine/SplitP.hpp
@@ -1,5 +1,5 @@
/********************************************************************\
- * SplitP.h -- private header for splits *
+ * SplitP.hpp -- private header for splits *
* Copyright (C) 1997 Robin D. Clark *
* Copyright (C) 1997-2000 Linas Vepstas <linas at linas.org> *
* Copyright (C) 2000 Bill Gribble *
@@ -25,7 +25,7 @@
/*
* FILE:
- * SplitP.h
+ * SplitP.hpp
*
* FUNCTION:
* The is the *private* split header file. Code outside of
@@ -52,10 +52,6 @@
#include "qof.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/** STRUCTS *********************************************************/
/* A "split" is more commonly referred to as an "entry" in a "transaction".
*/
@@ -236,10 +232,6 @@ typedef struct
SplitTestFunctions* _utest_split_fill_functions (void);
-#ifdef __cplusplus
-}
-#endif
-
/*@}*/
diff --git a/libgnucash/engine/Transaction.cpp b/libgnucash/engine/Transaction.cpp
index 0cc0fcf4aa..dc6d5186bd 100644
--- a/libgnucash/engine/Transaction.cpp
+++ b/libgnucash/engine/Transaction.cpp
@@ -46,7 +46,7 @@
#include "Scrub.h"
#include "Scrub3.h"
#include "TransactionP.hpp"
-#include "SplitP.h"
+#include "SplitP.hpp"
#include "TransLog.h"
#include "cap-gains.h"
#include "gnc-commodity.h"
diff --git a/libgnucash/engine/TransactionP.hpp b/libgnucash/engine/TransactionP.hpp
index 50a2d80a87..512e5dde01 100644
--- a/libgnucash/engine/TransactionP.hpp
+++ b/libgnucash/engine/TransactionP.hpp
@@ -49,7 +49,7 @@
#include <glib.h>
#include "gnc-engine.h" /* for typedefs */
-#include "SplitP.h"
+#include "SplitP.hpp"
#include "qof.h"
diff --git a/libgnucash/engine/mocks/gmock-Split.h b/libgnucash/engine/mocks/gmock-Split.h
index ce022fb2d0..0fe7eb24e4 100644
--- a/libgnucash/engine/mocks/gmock-Split.h
+++ b/libgnucash/engine/mocks/gmock-Split.h
@@ -4,7 +4,7 @@
#include <gmock/gmock.h>
#include <Split.h>
-#include <SplitP.h>
+#include <SplitP.hpp>
#include "gmock-qofbook.h"
#include "gmock-gobject.h"
diff --git a/libgnucash/engine/test/utest-Split.cpp b/libgnucash/engine/test/utest-Split.cpp
index 23d163ee59..8ec6d59399 100644
--- a/libgnucash/engine/test/utest-Split.cpp
+++ b/libgnucash/engine/test/utest-Split.cpp
@@ -28,7 +28,7 @@
#include <unittest-support.h>
/* Add specific headers for this class */
#include <Split.h>
-#include <SplitP.h>
+#include <SplitP.hpp>
#include <Account.h>
#include <Transaction.h>
#include <TransactionP.hpp>
commit 1e1d21b716790e9bddf5283f65decd71da1f30c7
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Apr 25 21:15:31 2024 +0800
[Transaction.hpp] rename to .hpp
diff --git a/gnucash/import-export/log-replay/gnc-log-replay.cpp b/gnucash/import-export/log-replay/gnc-log-replay.cpp
index 63e7e0a41d..6685c59b0c 100644
--- a/gnucash/import-export/log-replay/gnc-log-replay.cpp
+++ b/gnucash/import-export/log-replay/gnc-log-replay.cpp
@@ -34,7 +34,7 @@
#include "Account.h"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "TransLog.h"
#include "Scrub.h"
#include "gnc-log-replay.h"
diff --git a/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp b/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
index ecf3e40cbe..92ec28a5eb 100644
--- a/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
+++ b/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
@@ -27,7 +27,7 @@
#include <string.h>
#include "AccountP.hpp"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "gnc-lot.h"
#include "gnc-lot-p.h"
diff --git a/libgnucash/backend/xml/io-gncxml-v1.cpp b/libgnucash/backend/xml/io-gncxml-v1.cpp
index 789a72ff7a..0b008cf68e 100644
--- a/libgnucash/backend/xml/io-gncxml-v1.cpp
+++ b/libgnucash/backend/xml/io-gncxml-v1.cpp
@@ -38,7 +38,7 @@
#include <Query.h>
#include <Scrub.h>
#include <Transaction.h>
-#include <TransactionP.h>
+#include <TransactionP.hpp>
#include <TransLog.h>
#include <gnc-pricedb.h>
#include <gnc-pricedb-p.h>
diff --git a/libgnucash/backend/xml/io-gncxml-v2.cpp b/libgnucash/backend/xml/io-gncxml-v2.cpp
index 193fb7a544..76c562c616 100644
--- a/libgnucash/backend/xml/io-gncxml-v2.cpp
+++ b/libgnucash/backend/xml/io-gncxml-v2.cpp
@@ -51,7 +51,7 @@
#include "SX-book.h"
#include "SX-book-p.h"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "TransLog.h"
#if PLATFORM(WINDOWS)
#ifdef __STRICT_ANSI_UNSET__
diff --git a/libgnucash/backend/xml/test/test-xml-transaction.cpp b/libgnucash/backend/xml/test/test-xml-transaction.cpp
index 39470ddbeb..b7ccfe2c54 100644
--- a/libgnucash/backend/xml/test/test-xml-transaction.cpp
+++ b/libgnucash/backend/xml/test/test-xml-transaction.cpp
@@ -42,7 +42,7 @@
#include <AccountP.hpp>
#include <Transaction.h>
-#include <TransactionP.h>
+#include <TransactionP.hpp>
#include "../gnc-xml-helper.h"
#include "../gnc-xml.h"
diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index 2b45128148..f164e18720 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -37,7 +37,7 @@
#include "Account.hpp"
#include "Split.h"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "gnc-event.h"
#include "gnc-glib-utils.h"
#include "gnc-lot.h"
diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt
index dbd2516c9e..202d910254 100644
--- a/libgnucash/engine/CMakeLists.txt
+++ b/libgnucash/engine/CMakeLists.txt
@@ -9,7 +9,7 @@ set(engine_noinst_HEADERS
SplitP.h
SX-book.h
SX-ttinfo.h
- TransactionP.h
+ TransactionP.hpp
gnc-backend-prov.hpp
gnc-date-p.h
gnc-int128.hpp
diff --git a/libgnucash/engine/Query.cpp b/libgnucash/engine/Query.cpp
index 16f45db6b3..38e9f4f77a 100644
--- a/libgnucash/engine/Query.cpp
+++ b/libgnucash/engine/Query.cpp
@@ -43,7 +43,7 @@
#include "Account.h"
#include "Query.h"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
static QofLogModule log_module = GNC_MOD_QUERY;
diff --git a/libgnucash/engine/Scrub.cpp b/libgnucash/engine/Scrub.cpp
index f468f13f76..b80113591d 100644
--- a/libgnucash/engine/Scrub.cpp
+++ b/libgnucash/engine/Scrub.cpp
@@ -50,7 +50,7 @@
#include "Account.hpp"
#include "Scrub.h"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "gnc-commodity.h"
#include "qofinstance-p.h"
#include "gnc-session.h"
diff --git a/libgnucash/engine/Scrub2.cpp b/libgnucash/engine/Scrub2.cpp
index 265492f738..7c78bca4d7 100644
--- a/libgnucash/engine/Scrub2.cpp
+++ b/libgnucash/engine/Scrub2.cpp
@@ -39,7 +39,7 @@
#include "AccountP.hpp"
#include "Account.hpp"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "Scrub2.h"
#include "cap-gains.h"
#include "gnc-engine.h"
diff --git a/libgnucash/engine/Scrub3.cpp b/libgnucash/engine/Scrub3.cpp
index 69bda2edc3..2572f4be79 100644
--- a/libgnucash/engine/Scrub3.cpp
+++ b/libgnucash/engine/Scrub3.cpp
@@ -43,7 +43,7 @@
#include "Scrub2.h"
#include "Scrub3.h"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
static QofLogModule log_module = GNC_MOD_LOT;
diff --git a/libgnucash/engine/Split.cpp b/libgnucash/engine/Split.cpp
index 85fa02fa52..d4c6baaa53 100644
--- a/libgnucash/engine/Split.cpp
+++ b/libgnucash/engine/Split.cpp
@@ -49,7 +49,7 @@
#include "Split.h"
#include "AccountP.hpp"
#include "Scrub.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "TransLog.h"
#include "cap-gains.h"
#include "gnc-commodity.h"
diff --git a/libgnucash/engine/TransLog.cpp b/libgnucash/engine/TransLog.cpp
index 151e9a2a79..2145d22c8a 100644
--- a/libgnucash/engine/TransLog.cpp
+++ b/libgnucash/engine/TransLog.cpp
@@ -32,7 +32,7 @@
#include "Account.h"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "TransLog.h"
#include "qof.h"
#ifdef _MSC_VER
diff --git a/libgnucash/engine/Transaction.cpp b/libgnucash/engine/Transaction.cpp
index bc17b5d18e..0cc0fcf4aa 100644
--- a/libgnucash/engine/Transaction.cpp
+++ b/libgnucash/engine/Transaction.cpp
@@ -45,7 +45,7 @@
#include "AccountP.hpp"
#include "Scrub.h"
#include "Scrub3.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "SplitP.h"
#include "TransLog.h"
#include "cap-gains.h"
diff --git a/libgnucash/engine/TransactionP.h b/libgnucash/engine/TransactionP.hpp
similarity index 98%
rename from libgnucash/engine/TransactionP.h
rename to libgnucash/engine/TransactionP.hpp
index 6493fe96a4..50a2d80a87 100644
--- a/libgnucash/engine/TransactionP.h
+++ b/libgnucash/engine/TransactionP.hpp
@@ -1,5 +1,5 @@
/********************************************************************\
- * TransactionP.h -- private header for transaction & splits *
+ * TransactionP.hpp -- private header for transaction & splits *
* Copyright (C) 1997 Robin D. Clark *
* Copyright (C) 1997-2000 Linas Vepstas <linas at linas.org> *
* Copyright (C) 2000 Bill Gribble *
@@ -25,7 +25,7 @@
/*
* FILE:
- * TransactionP.h
+ * TransactionP.hpp
*
* FUNCTION:
* The is the *private* transaction header file. Code outside of
@@ -52,10 +52,6 @@
#include "SplitP.h"
#include "qof.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/** STRUCTS *********************************************************/
/*
@@ -197,9 +193,5 @@ TransTestFunctions* _utest_trans_fill_functions (void);
/*@}*/
-#ifdef __cplusplus
-}
-#endif
-
#endif /* XACC_TRANSACTION_P_H */
diff --git a/libgnucash/engine/cap-gains.cpp b/libgnucash/engine/cap-gains.cpp
index 3c004c552b..e9b677ee7c 100644
--- a/libgnucash/engine/cap-gains.cpp
+++ b/libgnucash/engine/cap-gains.cpp
@@ -63,7 +63,7 @@ ToDo:
#include "Scrub2.h"
#include "Scrub3.h"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "cap-gains.h"
#include "gnc-engine.h"
#include "engine-helpers.h"
diff --git a/libgnucash/engine/cashobjects.cpp b/libgnucash/engine/cashobjects.cpp
index ef6d0edd0b..e4e3cc61c8 100644
--- a/libgnucash/engine/cashobjects.cpp
+++ b/libgnucash/engine/cashobjects.cpp
@@ -30,7 +30,7 @@
#include "cashobjects.h"
#include "gnc-engine.h"
#include "AccountP.hpp"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "SchedXaction.h"
#include "SX-book-p.h"
#include "gnc-pricedb-p.h"
diff --git a/libgnucash/engine/gnc-engine.cpp b/libgnucash/engine/gnc-engine.cpp
index b912ea063b..6ea75fd01f 100644
--- a/libgnucash/engine/gnc-engine.cpp
+++ b/libgnucash/engine/gnc-engine.cpp
@@ -30,7 +30,7 @@
#include "AccountP.hpp"
#include "SX-book-p.h"
#include "gnc-budget.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "gnc-commodity.h"
#include "gnc-pricedb-p.h"
diff --git a/libgnucash/engine/gnc-engine.h b/libgnucash/engine/gnc-engine.h
index 1f911f9405..af626821bd 100644
--- a/libgnucash/engine/gnc-engine.h
+++ b/libgnucash/engine/gnc-engine.h
@@ -142,7 +142,7 @@ typedef struct account_s Account;
* divided into.
*
* This is the typename for a split. The actual structure is defined
- * in the private header TransactionP.h, but no one outside the engine
+ * in the private header TransactionP.hpp, but no one outside the engine
* should include that file. Instead, access that data only through
* the functions in Transaction.h .*/
typedef struct split_s Split;
@@ -153,7 +153,7 @@ typedef struct split_s Split;
* divided into one or more Splits (usually two).
*
* This is the typename for a transaction. The actual structure is
- * defined in the private header TransactionP.h, but no one outside
+ * defined in the private header TransactionP.hpp, but no one outside
* the engine should include that file. Instead, access that data only
* through the functions in Transaction.h .*/
typedef struct transaction_s Transaction;
diff --git a/libgnucash/engine/gnc-lot.cpp b/libgnucash/engine/gnc-lot.cpp
index 8e6cb5ad45..1ee3eedf00 100644
--- a/libgnucash/engine/gnc-lot.cpp
+++ b/libgnucash/engine/gnc-lot.cpp
@@ -51,7 +51,7 @@
#include "gnc-lot-p.h"
#include "cap-gains.h"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "gncInvoice.h"
/* This static indicates the debugging module that this .o belongs to. */
diff --git a/libgnucash/engine/mocks/gmock-Transaction.h b/libgnucash/engine/mocks/gmock-Transaction.h
index b0537ed50f..804307186b 100644
--- a/libgnucash/engine/mocks/gmock-Transaction.h
+++ b/libgnucash/engine/mocks/gmock-Transaction.h
@@ -4,7 +4,7 @@
#include <gmock/gmock.h>
#include <Transaction.h>
-#include <TransactionP.h>
+#include <TransactionP.hpp>
#include "gmock-gobject.h"
diff --git a/libgnucash/engine/policy.cpp b/libgnucash/engine/policy.cpp
index 35febca6f4..f67cc9d822 100644
--- a/libgnucash/engine/policy.cpp
+++ b/libgnucash/engine/policy.cpp
@@ -36,7 +36,7 @@
#include "Account.h"
#include "Account.hpp"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "cap-gains.h"
#include "gnc-engine.h"
#include "gnc-lot.h"
diff --git a/libgnucash/engine/test-core/test-engine-stuff.cpp b/libgnucash/engine/test-core/test-engine-stuff.cpp
index 2024f8fb9a..8dbb440ece 100644
--- a/libgnucash/engine/test-core/test-engine-stuff.cpp
+++ b/libgnucash/engine/test-core/test-engine-stuff.cpp
@@ -62,7 +62,7 @@
#include "gnc-engine.h"
#include "gnc-session.h"
#include "Transaction.h"
-#include "TransactionP.h"
+#include "TransactionP.hpp"
#include "Recurrence.h"
#include "SchedXaction.h"
#include "SX-book.h"
diff --git a/libgnucash/engine/test/utest-Split.cpp b/libgnucash/engine/test/utest-Split.cpp
index 9293d79ee1..23d163ee59 100644
--- a/libgnucash/engine/test/utest-Split.cpp
+++ b/libgnucash/engine/test/utest-Split.cpp
@@ -31,7 +31,7 @@
#include <SplitP.h>
#include <Account.h>
#include <Transaction.h>
-#include <TransactionP.h>
+#include <TransactionP.hpp>
#include <gnc-lot.h>
#include <gnc-event.h>
diff --git a/libgnucash/engine/test/utest-Transaction.cpp b/libgnucash/engine/test/utest-Transaction.cpp
index 704af204c9..5c252e5136 100644
--- a/libgnucash/engine/test/utest-Transaction.cpp
+++ b/libgnucash/engine/test/utest-Transaction.cpp
@@ -28,7 +28,7 @@
#include <unittest-support.h>
/* Add specific headers for this class */
#include "../Transaction.h"
-#include "../TransactionP.h"
+#include "../TransactionP.hpp"
#include "../Split.h"
#include "../Account.h"
#include "../gnc-lot.h"
commit ef8afedd09b6f9f670768f51fa256a81cb9d6e0b
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat May 4 22:22:13 2024 +0800
[gnc-euro.cpp] use c++isms
diff --git a/libgnucash/engine/gnc-euro.cpp b/libgnucash/engine/gnc-euro.cpp
index d614231353..4c7b453970 100644
--- a/libgnucash/engine/gnc-euro.cpp
+++ b/libgnucash/engine/gnc-euro.cpp
@@ -19,27 +19,15 @@
* *
\********************************************************************/
-#include <config.h>
+#include <string>
+#include <map>
+#include <optional>
#include "gnc-euro.h"
-
-#include <glib/gi18n.h>
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
#include "gnc-session.h"
-/* local structs */
-typedef struct
-{
- const char *currency;
- double rate;
-} gnc_euro_rate_struct;
-
-
-/* This array MUST be sorted ! */
/* The rates are per EURO and are converted to GncNumeric */
-static gnc_euro_rate_struct gnc_euro_rates[] =
+static const std::map<std::string,double> gnc_euro_rates =
{
{ "ATS", 13.7603 }, /* austrian schilling */
{ "BEF", 40.3399 }, /* belgian franc */
@@ -63,55 +51,25 @@ static gnc_euro_rate_struct gnc_euro_rates[] =
{ "SKK", 30.1260 } /* slovak koruna */
};
-static int
-gnc_euro_rate_compare (const void * key, const void * value)
-{
- auto curr = static_cast<const gnc_commodity*>(key);
- auto euro = static_cast<const gnc_euro_rate_struct*>(value);
-
- if (!key || !value)
- return -1;
-
- return g_ascii_strcasecmp(gnc_commodity_get_mnemonic(curr), euro->currency);
-}
-
-#if 0 /* Not Used */
-static int
-gnc_euro_rate_compare_code (const void * key, const void * value)
+static std::optional<double>
+get_euro_rate (const gnc_commodity * currency)
{
- const char *code = key;
- const gnc_euro_rate_struct * euro = value;
+ if (!currency || !gnc_commodity_is_iso(currency))
+ return {};
- if (!key || !value)
- return -1;
+ auto it = gnc_euro_rates.find (gnc_commodity_get_mnemonic(currency));
+ if (it == gnc_euro_rates.end())
+ return {};
- return g_ascii_strcasecmp (code, euro->currency);
+ return it->second;
}
-#endif
/* ------------------------------------------------------ */
gboolean
gnc_is_euro_currency(const gnc_commodity * currency)
{
- gnc_euro_rate_struct *result;
-
- if (currency == NULL)
- return FALSE;
-
- if (!gnc_commodity_is_iso(currency))
- return FALSE;
-
- result = (gnc_euro_rate_struct*)bsearch(currency,
- gnc_euro_rates,
- sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
- sizeof(gnc_euro_rate_struct),
- gnc_euro_rate_compare);
-
- if (result == NULL)
- return FALSE;
-
- return TRUE;
+ return get_euro_rate (currency).has_value();
}
/* ------------------------------------------------------ */
@@ -119,34 +77,17 @@ gnc_is_euro_currency(const gnc_commodity * currency)
gnc_numeric
gnc_convert_to_euro(const gnc_commodity * currency, gnc_numeric value)
{
- gnc_euro_rate_struct *result;
+ auto euro_rate = get_euro_rate (currency);
+ if (!euro_rate)
+ return gnc_numeric_zero();
- if (currency == NULL)
- return gnc_numeric_zero ();
-
- if (!gnc_commodity_is_iso(currency))
- return gnc_numeric_zero ();
-
- result = (gnc_euro_rate_struct*)bsearch(currency,
- gnc_euro_rates,
- sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
- sizeof(gnc_euro_rate_struct),
- gnc_euro_rate_compare);
-
- if (result == NULL)
- return gnc_numeric_zero ();
+ auto rate = double_to_gnc_numeric (*euro_rate, 100000, GNC_HOW_RND_ROUND_HALF_UP);
/* round to 2 decimal places */
- {
- gnc_numeric rate;
-
- rate = double_to_gnc_numeric (result->rate, 100000, GNC_HOW_RND_ROUND_HALF_UP);
-
- /* EC Regulation 1103/97 states we should use "Round half away from zero"
- * See https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX%3A31997R1103&qid=1662917247821
- */
- return gnc_numeric_div (value, rate, 100, GNC_HOW_RND_ROUND_HALF_UP);
- }
+ /* EC Regulation 1103/97 states we should use "Round half away from zero"
+ * See https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX%3A31997R1103&qid=1662917247821
+ */
+ return gnc_numeric_div (value, rate, 100, GNC_HOW_RND_ROUND_HALF_UP);
}
/* ------------------------------------------------------ */
@@ -154,33 +95,16 @@ gnc_convert_to_euro(const gnc_commodity * currency, gnc_numeric value)
gnc_numeric
gnc_convert_from_euro(const gnc_commodity * currency, gnc_numeric value)
{
- gnc_euro_rate_struct * result;
-
- if (currency == NULL)
- return gnc_numeric_zero ();
-
- if (!gnc_commodity_is_iso(currency))
- return gnc_numeric_zero ();
+ auto euro_rate = get_euro_rate (currency);
+ if (!euro_rate)
+ return gnc_numeric_zero();
- result = (gnc_euro_rate_struct*)bsearch(currency,
- gnc_euro_rates,
- sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
- sizeof(gnc_euro_rate_struct),
- gnc_euro_rate_compare);
+ auto rate = double_to_gnc_numeric (*euro_rate, 100000, GNC_HOW_RND_ROUND_HALF_UP);
- if (result == NULL)
- return gnc_numeric_zero ();
-
- {
- gnc_numeric rate;
-
- rate = double_to_gnc_numeric (result->rate, 100000, GNC_HOW_RND_ROUND_HALF_UP);
-
- /* EC Regulation 1103/97 states we should use "Round half away from zero"
- * See http://europa.eu/legislation_summaries/economic_and_monetary_affairs/institutional_and_economic_framework/l25025_en.htm */
- return gnc_numeric_mul (value, rate, gnc_commodity_get_fraction (currency),
- GNC_HOW_RND_ROUND_HALF_UP);
- }
+ /* EC Regulation 1103/97 states we should use "Round half away from zero"
+ * See http://europa.eu/legislation_summaries/economic_and_monetary_affairs/institutional_and_economic_framework/l25025_en.htm */
+ return gnc_numeric_mul (value, rate, gnc_commodity_get_fraction (currency),
+ GNC_HOW_RND_ROUND_HALF_UP);
}
/* ------------------------------------------------------ */
@@ -188,25 +112,11 @@ gnc_convert_from_euro(const gnc_commodity * currency, gnc_numeric value)
gnc_numeric
gnc_euro_currency_get_rate (const gnc_commodity *currency)
{
- gnc_euro_rate_struct * result;
-
- if (currency == NULL)
- return gnc_numeric_zero ();
-
- if (!gnc_commodity_is_iso(currency))
- return gnc_numeric_zero ();
-
- result = (gnc_euro_rate_struct*)bsearch(currency,
- gnc_euro_rates,
- sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
- sizeof(gnc_euro_rate_struct),
- gnc_euro_rate_compare);
-
- if (result == NULL)
- return gnc_numeric_zero ();
+ auto euro_rate = get_euro_rate (currency);
+ if (!euro_rate)
+ return gnc_numeric_zero();
- return double_to_gnc_numeric (result->rate, GNC_DENOM_AUTO,
- GNC_HOW_RND_ROUND_HALF_UP);
+ return double_to_gnc_numeric (*euro_rate, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP);
}
/* ------------------------------------------------------ */
commit 3bc7ce606de64cefe35681a09f9868785778f6bc
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat May 4 21:52:30 2024 +0800
[gnc-euro.cpp] convert to c++
diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt
index dbd2516c9e..4098b22cae 100644
--- a/libgnucash/engine/CMakeLists.txt
+++ b/libgnucash/engine/CMakeLists.txt
@@ -160,7 +160,7 @@ set (engine_SOURCES
gnc-date.cpp
gnc-datetime.cpp
gnc-engine.cpp
- gnc-euro.c
+ gnc-euro.cpp
gnc-event.c
gnc-features.cpp
gnc-hooks.c
diff --git a/libgnucash/engine/gnc-euro.c b/libgnucash/engine/gnc-euro.cpp
similarity index 79%
rename from libgnucash/engine/gnc-euro.c
rename to libgnucash/engine/gnc-euro.cpp
index 411d6209fd..d614231353 100644
--- a/libgnucash/engine/gnc-euro.c
+++ b/libgnucash/engine/gnc-euro.cpp
@@ -66,8 +66,8 @@ static gnc_euro_rate_struct gnc_euro_rates[] =
static int
gnc_euro_rate_compare (const void * key, const void * value)
{
- const gnc_commodity * curr = key;
- const gnc_euro_rate_struct * euro = value;
+ auto curr = static_cast<const gnc_commodity*>(key);
+ auto euro = static_cast<const gnc_euro_rate_struct*>(value);
if (!key || !value)
return -1;
@@ -102,11 +102,11 @@ gnc_is_euro_currency(const gnc_commodity * currency)
if (!gnc_commodity_is_iso(currency))
return FALSE;
- result = bsearch(currency,
- gnc_euro_rates,
- sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
- sizeof(gnc_euro_rate_struct),
- gnc_euro_rate_compare);
+ result = (gnc_euro_rate_struct*)bsearch(currency,
+ gnc_euro_rates,
+ sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
+ sizeof(gnc_euro_rate_struct),
+ gnc_euro_rate_compare);
if (result == NULL)
return FALSE;
@@ -127,11 +127,11 @@ gnc_convert_to_euro(const gnc_commodity * currency, gnc_numeric value)
if (!gnc_commodity_is_iso(currency))
return gnc_numeric_zero ();
- result = bsearch(currency,
- gnc_euro_rates,
- sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
- sizeof(gnc_euro_rate_struct),
- gnc_euro_rate_compare);
+ result = (gnc_euro_rate_struct*)bsearch(currency,
+ gnc_euro_rates,
+ sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
+ sizeof(gnc_euro_rate_struct),
+ gnc_euro_rate_compare);
if (result == NULL)
return gnc_numeric_zero ();
@@ -162,11 +162,11 @@ gnc_convert_from_euro(const gnc_commodity * currency, gnc_numeric value)
if (!gnc_commodity_is_iso(currency))
return gnc_numeric_zero ();
- result = bsearch(currency,
- gnc_euro_rates,
- sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
- sizeof(gnc_euro_rate_struct),
- gnc_euro_rate_compare);
+ result = (gnc_euro_rate_struct*)bsearch(currency,
+ gnc_euro_rates,
+ sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
+ sizeof(gnc_euro_rate_struct),
+ gnc_euro_rate_compare);
if (result == NULL)
return gnc_numeric_zero ();
@@ -196,11 +196,11 @@ gnc_euro_currency_get_rate (const gnc_commodity *currency)
if (!gnc_commodity_is_iso(currency))
return gnc_numeric_zero ();
- result = bsearch(currency,
- gnc_euro_rates,
- sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
- sizeof(gnc_euro_rate_struct),
- gnc_euro_rate_compare);
+ result = (gnc_euro_rate_struct*)bsearch(currency,
+ gnc_euro_rates,
+ sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
+ sizeof(gnc_euro_rate_struct),
+ gnc_euro_rate_compare);
if (result == NULL)
return gnc_numeric_zero ();
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 54843eb06d..a62930a67b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -640,7 +640,7 @@ libgnucash/engine/gnc-datetime.cpp
libgnucash/engine/gncEmployee.c
libgnucash/engine/gnc-engine.cpp
libgnucash/engine/gncEntry.c
-libgnucash/engine/gnc-euro.c
+libgnucash/engine/gnc-euro.cpp
libgnucash/engine/gnc-event.c
libgnucash/engine/gnc-features.cpp
libgnucash/engine/gnc-hooks.c
commit 80997ee5b49ac2971b292ee897829e31e5a52854
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun May 5 09:17:10 2024 +0800
[gtest-gnc-euro] add rounding test
diff --git a/libgnucash/engine/test/gtest-gnc-euro.cpp b/libgnucash/engine/test/gtest-gnc-euro.cpp
index 57585d5975..e9a6c90163 100644
--- a/libgnucash/engine/test/gtest-gnc-euro.cpp
+++ b/libgnucash/engine/test/gtest-gnc-euro.cpp
@@ -96,6 +96,13 @@ TEST_F(Currencies, convert_to_euro)
ASSERT_NE(eur, nullptr);
EXPECT_TRUE(gnc_numeric_equal(value,
gnc_convert_to_euro(eur, value)));
+
+ // test euro rounding strategy ROUND_HALF_UP. this cyp_val will
+ // convert to 0.005 exactly, rounded to 0.01 eur
+ gnc_numeric cyp_val{585274, 200000000};
+ auto eur_val{gnc_convert_to_euro(cyp, cyp_val)};
+ EXPECT_EQ (eur_val.num, 1);
+ EXPECT_EQ (eur_val.denom, 100);
}
TEST_F(Currencies, convert_from_euro)
commit d405b5891f22f9b9178e7ba7dfe9931498874698
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Apr 25 22:16:15 2024 +0800
[gnc-log-replay.cpp] don't set import to DEBUG
because it'll spew too many debug messages when gnc-log-replay
completes.
diff --git a/gnucash/import-export/log-replay/gnc-log-replay.cpp b/gnucash/import-export/log-replay/gnc-log-replay.cpp
index 197c4d6927..63e7e0a41d 100644
--- a/gnucash/import-export/log-replay/gnc-log-replay.cpp
+++ b/gnucash/import-export/log-replay/gnc-log-replay.cpp
@@ -558,7 +558,7 @@ void gnc_file_log_replay (GtkWindow *parent)
if (!expected_header)
expected_header = g_strdup(expected_header_orig);
- qof_log_set_level(GNC_MOD_IMPORT, QOF_LOG_DEBUG);
+ // qof_log_set_level(GNC_MOD_IMPORT, QOF_LOG_DEBUG);
ENTER(" ");
/* Don't log the log replay. This would only result in redundant logs */
commit c5caa55e9a3247488e1e2c3d80814e31c1de3041
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Apr 25 21:15:09 2024 +0800
[gnc-log-replay.cpp] convert to c++
diff --git a/gnucash/import-export/log-replay/CMakeLists.txt b/gnucash/import-export/log-replay/CMakeLists.txt
index c25ab751e9..12d35fecc7 100644
--- a/gnucash/import-export/log-replay/CMakeLists.txt
+++ b/gnucash/import-export/log-replay/CMakeLists.txt
@@ -1,6 +1,6 @@
set(log_replay_SOURCES
- gnc-log-replay.c
+ gnc-log-replay.cpp
gnc-plugin-log-replay.c
)
diff --git a/gnucash/import-export/log-replay/gnc-log-replay.c b/gnucash/import-export/log-replay/gnc-log-replay.cpp
similarity index 95%
rename from gnucash/import-export/log-replay/gnc-log-replay.c
rename to gnucash/import-export/log-replay/gnc-log-replay.cpp
index 98885753dd..197c4d6927 100644
--- a/gnucash/import-export/log-replay/gnc-log-replay.c
+++ b/gnucash/import-export/log-replay/gnc-log-replay.cpp
@@ -40,14 +40,12 @@
#include "gnc-log-replay.h"
#include "gnc-file.h"
#include "qof.h"
+#include "qofinstance-p.h"
#include "gnc-ui-util.h"
#include "gnc-gui-query.h"
#define GNC_PREFS_GROUP "dialogs.log-replay"
-/* EFFECTIVE FRIEND FUNCTION */
-void qof_instance_set_guid (gpointer inst, const GncGUID *guid);
-
/* NW: If you want a new log_module, just define
a unique string either in gnc-engine.h or
locally.*/
@@ -152,16 +150,16 @@ static split_record interpret_split_record( char *record_line)
switch (tok_ptr[0])
{
case 'B':
- record.log_action = LOG_BEGIN_EDIT;
+ record.log_action = split_record::_enum_action::LOG_BEGIN_EDIT;
break;
case 'D':
- record.log_action = LOG_DELETE;
+ record.log_action = split_record::_enum_action::LOG_DELETE;
break;
case 'C':
- record.log_action = LOG_COMMIT;
+ record.log_action = split_record::_enum_action::LOG_COMMIT;
break;
case 'R':
- record.log_action = LOG_ROLLBACK;
+ record.log_action = split_record::_enum_action::LOG_ROLLBACK;
break;
}
record.log_action_present = TRUE;
@@ -265,16 +263,16 @@ static void dump_split_record(split_record record)
{
switch (record.log_action)
{
- case LOG_BEGIN_EDIT:
+ case split_record::_enum_action::LOG_BEGIN_EDIT:
DEBUG("Log action: LOG_BEGIN_EDIT");
break;
- case LOG_DELETE:
+ case split_record::_enum_action::LOG_DELETE:
DEBUG("Log action: LOG_DELETE");
break;
- case LOG_COMMIT:
+ case split_record::_enum_action::LOG_COMMIT:
DEBUG("Log action: LOG_COMMIT");
break;
- case LOG_ROLLBACK:
+ case split_record::_enum_action::LOG_ROLLBACK:
DEBUG("Log action: LOG_ROLLBACK");
break;
}
@@ -387,13 +385,13 @@ static void process_trans_record( FILE *log_file)
{
switch (record.log_action)
{
- case LOG_BEGIN_EDIT:
+ case split_record::_enum_action::LOG_BEGIN_EDIT:
DEBUG("process_trans_record():Ignoring log action: LOG_BEGIN_EDIT"); /*Do nothing, there is no point*/
break;
- case LOG_ROLLBACK:
+ case split_record::_enum_action::LOG_ROLLBACK:
DEBUG("process_trans_record():Ignoring log action: LOG_ROLLBACK");/*Do nothing, since we didn't do the begin_edit either*/
break;
- case LOG_DELETE:
+ case split_record::_enum_action::LOG_DELETE:
DEBUG("process_trans_record(): Playing back LOG_DELETE");
if ((trans = xaccTransLookup (&(record.trans_guid), book)) != NULL
&& first_record == TRUE)
@@ -414,7 +412,7 @@ static void process_trans_record( FILE *log_file)
else
xaccTransDestroy(trans);
break;
- case LOG_COMMIT:
+ case split_record::_enum_action::LOG_COMMIT:
DEBUG("process_trans_record(): Playing back LOG_COMMIT");
if (record.trans_guid_present == TRUE
&& first_record == TRUE)
@@ -549,11 +547,11 @@ void gnc_file_log_replay (GtkWindow *parent)
char *read_retval;
GtkFileFilter *filter;
FILE *log_file;
- char * record_start_str = "===== START";
+ const char * record_start_str = "===== START";
/* NOTE: This string must match src/engine/TransLog.c (sans newline) */
- char * expected_header_orig = "mod\ttrans_guid\tsplit_guid\ttime_now\t"
- "date_entered\tdate_posted\tacc_guid\tacc_name\tnum\tdescription\t"
- "notes\tmemo\taction\treconciled\tamount\tvalue\tdate_reconciled";
+ const char * expected_header_orig = "mod\ttrans_guid\tsplit_guid\ttime_now\t"
+ "date_entered\tdate_posted\tacc_guid\tacc_name\tnum\tdescription\t"
+ "notes\tmemo\taction\treconciled\tamount\tvalue\tdate_reconciled";
static char *expected_header = NULL;
/* Use g_strdup_printf so we don't get accidental tab -> space conversion */
diff --git a/gnucash/import-export/log-replay/gnc-log-replay.h b/gnucash/import-export/log-replay/gnc-log-replay.h
index 767702a369..013d481446 100644
--- a/gnucash/import-export/log-replay/gnc-log-replay.h
+++ b/gnucash/import-export/log-replay/gnc-log-replay.h
@@ -27,9 +27,18 @@
#include <gtk/gtk.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/** The gnc_file_log_replay() routine will pop up a standard file
* selection dialogue asking the user to pick a log file to replay. If one
* is selected the .log file is opened and read. Its contents
* are then silently merged in the current log file. */
void gnc_file_log_replay (GtkWindow *parent);
+
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 54843eb06d..942f666f98 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -356,7 +356,7 @@ gnucash/import-export/import-parse.cpp
gnucash/import-export/import-pending-matches.cpp
gnucash/import-export/import-settings.cpp
gnucash/import-export/import-utilities.cpp
-gnucash/import-export/log-replay/gnc-log-replay.c
+gnucash/import-export/log-replay/gnc-log-replay.cpp
gnucash/import-export/log-replay/gnc-plugin-log-replay.c
gnucash/import-export/ofx/gncmod-ofx-import.c
gnucash/import-export/ofx/gnc-ofx-import.cpp
Summary of changes:
gnucash/import-export/log-replay/CMakeLists.txt | 2 +-
.../{gnc-log-replay.c => gnc-log-replay.cpp} | 40 ++--
gnucash/import-export/log-replay/gnc-log-replay.h | 9 +
libgnucash/backend/xml/gnc-transaction-xml-v2.cpp | 2 +-
libgnucash/backend/xml/io-gncxml-v1.cpp | 2 +-
libgnucash/backend/xml/io-gncxml-v2.cpp | 2 +-
.../backend/xml/test/test-xml-transaction.cpp | 2 +-
libgnucash/engine/Account.cpp | 2 +-
libgnucash/engine/CMakeLists.txt | 6 +-
libgnucash/engine/Query.cpp | 2 +-
libgnucash/engine/Scrub.cpp | 2 +-
libgnucash/engine/Scrub2.cpp | 2 +-
libgnucash/engine/Scrub3.cpp | 2 +-
libgnucash/engine/Split.cpp | 2 +-
libgnucash/engine/{SplitP.h => SplitP.hpp} | 12 +-
libgnucash/engine/TransLog.cpp | 2 +-
libgnucash/engine/Transaction.cpp | 4 +-
.../engine/{TransactionP.h => TransactionP.hpp} | 14 +-
libgnucash/engine/cap-gains.cpp | 2 +-
libgnucash/engine/cashobjects.cpp | 2 +-
libgnucash/engine/gnc-engine.cpp | 2 +-
libgnucash/engine/gnc-engine.h | 4 +-
libgnucash/engine/gnc-euro.c | 221 ---------------------
libgnucash/engine/gnc-euro.cpp | 131 ++++++++++++
libgnucash/engine/gnc-lot.cpp | 2 +-
libgnucash/engine/mocks/gmock-Split.h | 2 +-
libgnucash/engine/mocks/gmock-Transaction.h | 2 +-
libgnucash/engine/policy.cpp | 2 +-
libgnucash/engine/test-core/test-engine-stuff.cpp | 2 +-
libgnucash/engine/test/gtest-gnc-euro.cpp | 7 +
libgnucash/engine/test/utest-Split.cpp | 4 +-
libgnucash/engine/test/utest-Transaction.cpp | 2 +-
po/POTFILES.in | 4 +-
33 files changed, 203 insertions(+), 295 deletions(-)
rename gnucash/import-export/log-replay/{gnc-log-replay.c => gnc-log-replay.cpp} (95%)
rename libgnucash/engine/{SplitP.h => SplitP.hpp} (98%)
rename libgnucash/engine/{TransactionP.h => TransactionP.hpp} (97%)
delete mode 100644 libgnucash/engine/gnc-euro.c
create mode 100644 libgnucash/engine/gnc-euro.cpp
More information about the gnucash-changes
mailing list