gnucash stable: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Sat Jun 1 01:16:33 EDT 2024
Updated via https://github.com/Gnucash/gnucash/commit/6c7abb48 (commit)
via https://github.com/Gnucash/gnucash/commit/7dc2e2e6 (commit)
via https://github.com/Gnucash/gnucash/commit/55592efe (commit)
from https://github.com/Gnucash/gnucash/commit/1cc1e498 (commit)
commit 6c7abb487d652294bf75ce840627db32f4b2a360
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Jun 1 11:59:13 2024 +0800
[SX-ttinfo.hpp] convert to c++ header
diff --git a/gnucash/gnome/assistant-loan.cpp b/gnucash/gnome/assistant-loan.cpp
index 943ab3c244..54578c17c3 100644
--- a/gnucash/gnome/assistant-loan.cpp
+++ b/gnucash/gnome/assistant-loan.cpp
@@ -34,7 +34,7 @@
#include "assistant-loan.h"
#include "SchedXaction.h"
#include "SX-book.h"
-#include "SX-ttinfo.h"
+#include "SX-ttinfo.hpp"
#include "gnc-amount-edit.h"
#include "gnc-account-sel.h"
#include "gnc-date.h"
diff --git a/gnucash/gnome/dialog-sx-from-trans.cpp b/gnucash/gnome/dialog-sx-from-trans.cpp
index 4fc436f496..5aa4de3e68 100644
--- a/gnucash/gnome/dialog-sx-from-trans.cpp
+++ b/gnucash/gnome/dialog-sx-from-trans.cpp
@@ -43,7 +43,7 @@
#include "Recurrence.h"
#include "SchedXaction.h"
#include "SX-book.h"
-#include "SX-ttinfo.h"
+#include "SX-ttinfo.hpp"
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <stdlib.h>
diff --git a/libgnucash/app-utils/test/test-sx.cpp b/libgnucash/app-utils/test/test-sx.cpp
index 163a38e06c..d8a3c18a7f 100644
--- a/libgnucash/app-utils/test/test-sx.cpp
+++ b/libgnucash/app-utils/test/test-sx.cpp
@@ -24,7 +24,7 @@
#include <stdlib.h>
#include "SX-book.h"
-#include "SX-ttinfo.h"
+#include "SX-ttinfo.hpp"
#include "gnc-date.h"
#include "gnc-session.h"
#include "gnc-sx-instance-model.h"
diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt
index 2058b5866b..7fa07271f6 100644
--- a/libgnucash/engine/CMakeLists.txt
+++ b/libgnucash/engine/CMakeLists.txt
@@ -8,7 +8,7 @@ set(engine_noinst_HEADERS
AccountP.hpp
SplitP.hpp
SX-book.h
- SX-ttinfo.h
+ SX-ttinfo.hpp
TransactionP.hpp
gnc-backend-prov.hpp
gnc-date-p.h
@@ -37,7 +37,7 @@ set (engine_HEADERS
Recurrence.h
SchedXaction.h
SX-book.h
- SX-ttinfo.h
+ SX-ttinfo.hpp
Query.h
Scrub.h
Scrub2.h
diff --git a/libgnucash/engine/SX-ttinfo.cpp b/libgnucash/engine/SX-ttinfo.cpp
index e14482d019..3d1ffd7293 100644
--- a/libgnucash/engine/SX-ttinfo.cpp
+++ b/libgnucash/engine/SX-ttinfo.cpp
@@ -25,7 +25,7 @@
#include <config.h>
-#include "SX-ttinfo.h"
+#include "SX-ttinfo.hpp"
struct TTInfo_s
{
diff --git a/libgnucash/engine/SX-ttinfo.h b/libgnucash/engine/SX-ttinfo.hpp
similarity index 98%
rename from libgnucash/engine/SX-ttinfo.h
rename to libgnucash/engine/SX-ttinfo.hpp
index 1c36d1d3ea..72486f7a66 100644
--- a/libgnucash/engine/SX-ttinfo.h
+++ b/libgnucash/engine/SX-ttinfo.hpp
@@ -31,10 +31,6 @@
#include "Account.h"
#include "gnc-commodity.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
typedef struct TTInfo_s TTInfo;
typedef struct TTSplitInfo_s TTSplitInfo;
@@ -91,8 +87,4 @@ const char *gnc_ttsplitinfo_get_debit_formula(TTSplitInfo *split_i);
void gnc_ttsplitinfo_set_account(TTSplitInfo *split_i, Account *acc);
Account *gnc_ttsplitinfo_get_account(TTSplitInfo *split_i);
-#ifdef __cplusplus
-}
-#endif
-
#endif
diff --git a/libgnucash/engine/SchedXaction.cpp b/libgnucash/engine/SchedXaction.cpp
index 403f7f2441..293b173f7a 100644
--- a/libgnucash/engine/SchedXaction.cpp
+++ b/libgnucash/engine/SchedXaction.cpp
@@ -34,7 +34,7 @@
#include "Account.hpp"
#include "SX-book.h"
#include "SX-book-p.h"
-#include "SX-ttinfo.h"
+#include "SX-ttinfo.hpp"
#include "SchedXaction.h"
#include "Transaction.h"
#include "gnc-engine.h"
commit 7dc2e2e6f93ad26c8429186d4f429b497f349f97
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Jun 1 09:53:27 2024 +0800
[SchedXaction.cpp] use c++ algo
diff --git a/libgnucash/engine/SchedXaction.cpp b/libgnucash/engine/SchedXaction.cpp
index b2b1c5d95b..403f7f2441 100644
--- a/libgnucash/engine/SchedXaction.cpp
+++ b/libgnucash/engine/SchedXaction.cpp
@@ -31,6 +31,7 @@
#include "qof.h"
#include "Account.h"
+#include "Account.hpp"
#include "SX-book.h"
#include "SX-book-p.h"
#include "SX-ttinfo.h"
@@ -40,6 +41,8 @@
#include "engine-helpers.h"
#include "qofinstance-p.h"
+#include <unordered_set>
+
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gnc.engine.sx"
@@ -416,46 +419,20 @@ xaccSchedXactionMalloc(QofBook *book)
return sx;
}
-static void
-sxprivTransMapDelete( gpointer data, gpointer user_data )
-{
- Transaction *t = (Transaction *) data;
- xaccTransBeginEdit( t );
- xaccTransDestroy( t );
- xaccTransCommitEdit( t );
- return;
-}
-
static void
delete_template_trans(SchedXaction *sx)
{
- GList *templ_acct_splits, *curr_split_listref;
- Split *curr_split;
- Transaction *split_trans;
- GList *templ_acct_transactions = NULL;
-
- templ_acct_splits
- = xaccAccountGetSplitList(sx->template_acct);
-
- for (curr_split_listref = templ_acct_splits;
- curr_split_listref;
- curr_split_listref = curr_split_listref->next)
- {
- curr_split = (Split *) curr_split_listref->data;
- split_trans = xaccSplitGetParent(curr_split);
- if (! (g_list_find(templ_acct_transactions, split_trans)))
- {
- templ_acct_transactions
- = g_list_prepend(templ_acct_transactions, split_trans);
- }
- }
-
- g_list_foreach(templ_acct_transactions,
- sxprivTransMapDelete,
- NULL);
-
- g_list_free (templ_acct_splits);
- g_list_free (templ_acct_transactions);
+ std::unordered_set<Transaction*> txns;
+ auto& splits{xaccAccountGetSplits (sx->template_acct)};
+ std::for_each (splits.begin(), splits.end(),
+ [&txns](auto s){ txns.insert (xaccSplitGetParent (s)); });
+ std::for_each (txns.begin(), txns.end(),
+ [](auto t)
+ {
+ xaccTransBeginEdit (t);
+ xaccTransDestroy (t);
+ xaccTransCommitEdit (t);
+ });
return;
}
commit 55592efe253408614f537bf0fb797952ffe4201e
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Jun 1 09:35:35 2024 +0800
[SchedXAction.cpp] convert to c++
diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt
index a4d7f50d39..2058b5866b 100644
--- a/libgnucash/engine/CMakeLists.txt
+++ b/libgnucash/engine/CMakeLists.txt
@@ -140,7 +140,7 @@ set (engine_SOURCES
Account.cpp
Recurrence.cpp
Query.cpp
- SchedXaction.c
+ SchedXaction.cpp
SX-book.cpp
SX-ttinfo.cpp
Scrub.cpp
diff --git a/libgnucash/engine/SchedXaction.c b/libgnucash/engine/SchedXaction.cpp
similarity index 97%
rename from libgnucash/engine/SchedXaction.c
rename to libgnucash/engine/SchedXaction.cpp
index 266bbd99f3..b2b1c5d95b 100644
--- a/libgnucash/engine/SchedXaction.c
+++ b/libgnucash/engine/SchedXaction.cpp
@@ -208,25 +208,25 @@ gnc_schedxaction_set_property (GObject *object,
/* Note: when passed through a boxed gvalue, the julian value of the date is copied.
The date may appear invalid until a function requiring for dmy calculation is
called. */
- xaccSchedXactionSetStartDate(sx, g_value_get_boxed(value));
+ xaccSchedXactionSetStartDate(sx, static_cast<const GDate*>(g_value_get_boxed(value)));
break;
case PROP_END_DATE:
/* Note: when passed through a boxed gvalue, the julian value of the date is copied.
The date may appear invalid until a function requiring for dmy calculation is
called. */
- xaccSchedXactionSetEndDate(sx, g_value_get_boxed(value));
+ xaccSchedXactionSetEndDate(sx, static_cast<const GDate*>(g_value_get_boxed(value)));
break;
case PROP_LAST_OCCURANCE_DATE:
/* Note: when passed through a boxed gvalue, the julian value of the date is copied.
The date may appear invalid until a function requiring for dmy calculation is
called. */
- xaccSchedXactionSetLastOccurDate(sx, g_value_get_boxed(value));
+ xaccSchedXactionSetLastOccurDate(sx, static_cast<const GDate*>(g_value_get_boxed(value)));
break;
case PROP_INSTANCE_COUNT:
gnc_sx_set_instance_count(sx, g_value_get_int(value));
break;
case PROP_TEMPLATE_ACCOUNT:
- sx_set_template_account(sx, g_value_get_object(value));
+ sx_set_template_account(sx, GNC_ACCOUNT(g_value_get_object(value)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@@ -409,7 +409,7 @@ xaccSchedXactionMalloc(QofBook *book)
g_return_val_if_fail (book, NULL);
- sx = g_object_new(GNC_TYPE_SCHEDXACTION, NULL);
+ sx = GNC_SX(g_object_new(GNC_TYPE_SCHEDXACTION, NULL));
xaccSchedXactionInit( sx, book );
qof_event_gen( &sx->inst, QOF_EVENT_CREATE , NULL);
@@ -483,8 +483,6 @@ xaccSchedXactionDestroy( SchedXaction *sx )
static void
xaccSchedXactionFree( SchedXaction *sx )
{
- GList *l;
-
if ( sx == NULL ) return;
qof_event_gen( &sx->inst, QOF_EVENT_DESTROY , NULL);
@@ -502,16 +500,7 @@ xaccSchedXactionFree( SchedXaction *sx )
xaccAccountBeginEdit( sx->template_acct );
xaccAccountDestroy( sx->template_acct );
- for ( l = sx->deferredList; l; l = l->next )
- {
- gnc_sx_destroy_temporal_state( l->data );
- l->data = NULL;
- }
- if ( sx->deferredList )
- {
- g_list_free( sx->deferredList );
- sx->deferredList = NULL;
- }
+ g_list_free_full (sx->deferredList, g_free);
/* a GList of Recurrences */
g_list_free_full (sx->schedule, g_free);
@@ -799,7 +788,7 @@ gint gnc_sx_get_num_occur_daterange(const SchedXaction *sx, const GDate* start_d
gnc_sx_incr_temporal_state (sx, tmpState);
if (xaccSchedXactionHasOccurDef(sx) && tmpState->num_occur_rem < 0)
{
- gnc_sx_destroy_temporal_state (tmpState);
+ g_free (tmpState);
return result;
}
}
@@ -812,7 +801,7 @@ gint gnc_sx_get_num_occur_daterange(const SchedXaction *sx, const GDate* start_d
gnc_sx_incr_temporal_state (sx, tmpState);
if (xaccSchedXactionHasOccurDef(sx) && tmpState->num_occur_rem < 0)
{
- gnc_sx_destroy_temporal_state (tmpState);
+ g_free (tmpState);
return result;
}
}
@@ -840,7 +829,7 @@ gint gnc_sx_get_num_occur_daterange(const SchedXaction *sx, const GDate* start_d
if (!countFirstDate && result > 0)
--result;
- gnc_sx_destroy_temporal_state (tmpState);
+ g_free (tmpState);
return result;
}
@@ -1036,8 +1025,6 @@ xaccSchedXactionSetTemplateTrans(SchedXaction *sx, GList *t_t_list,
QofBook *book)
{
Transaction *new_trans;
- TTInfo *tti;
- TTSplitInfo *s_info;
Split *new_split;
GList *split_list;
@@ -1048,7 +1035,7 @@ xaccSchedXactionSetTemplateTrans(SchedXaction *sx, GList *t_t_list,
for (; t_t_list != NULL; t_t_list = t_t_list->next)
{
- tti = t_t_list->data;
+ auto tti = static_cast<TTInfo*>(t_t_list->data);
new_trans = xaccMallocTransaction(book);
@@ -1071,7 +1058,7 @@ xaccSchedXactionSetTemplateTrans(SchedXaction *sx, GList *t_t_list,
split_list;
split_list = split_list->next)
{
- s_info = split_list->data;
+ auto s_info = static_cast<TTSplitInfo*>(split_list->data);
new_split = pack_split_info(s_info, sx->template_acct,
new_trans, book);
xaccTransAppendSplit(new_trans, new_split);
@@ -1083,12 +1070,11 @@ xaccSchedXactionSetTemplateTrans(SchedXaction *sx, GList *t_t_list,
SXTmpStateData*
gnc_sx_create_temporal_state(const SchedXaction *sx )
{
- SXTmpStateData *toRet =
- g_new0( SXTmpStateData, 1 );
+ auto toRet = g_new0 (SXTmpStateData, 1);
if (g_date_valid (&(sx->last_date)))
- toRet->last_date = sx->last_date;
+ toRet->last_date = sx->last_date;
else
- g_date_set_dmy (&(toRet->last_date), 1, 1, 1970);
+ g_date_set_dmy (&toRet->last_date, 1, static_cast<GDateMonth>(1), 1970);
toRet->num_occur_rem = sx->num_occurances_remain;
toRet->num_inst = sx->instance_num;
return toRet;
@@ -1173,7 +1159,7 @@ gnc_sx_remove_defer_instance( SchedXaction *sx, void *deferStateData )
return;
}
- gnc_sx_destroy_temporal_state(found_by_value->data);
+ g_free (found_by_value->data);
sx->deferredList = g_list_delete_link(sx->deferredList, found_by_value);
}
@@ -1230,7 +1216,7 @@ static QofObject SXDesc =
DI(.interface_version = ) QOF_OBJECT_VERSION,
DI(.e_type = ) GNC_SX_ID,
DI(.type_label = ) "Scheduled Transaction",
- DI(.create = ) (gpointer)xaccSchedXactionMalloc,
+ DI(.create = ) (void* (*)(QofBook*))xaccSchedXactionMalloc,
DI(.book_begin = ) NULL,
DI(.book_end = ) gnc_sx_book_end,
DI(.is_dirty = ) qof_collection_is_dirty,
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 31d25a9b8a..f4618ee1b5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -684,7 +684,7 @@ libgnucash/engine/qofutil.cpp
libgnucash/engine/qof-win32.cpp
libgnucash/engine/Query.cpp
libgnucash/engine/Recurrence.cpp
-libgnucash/engine/SchedXaction.c
+libgnucash/engine/SchedXaction.cpp
libgnucash/engine/Scrub2.cpp
libgnucash/engine/Scrub3.cpp
libgnucash/engine/ScrubBudget.c
Summary of changes:
gnucash/gnome/assistant-loan.cpp | 2 +-
gnucash/gnome/dialog-sx-from-trans.cpp | 2 +-
libgnucash/app-utils/test/test-sx.cpp | 2 +-
libgnucash/engine/CMakeLists.txt | 6 +-
libgnucash/engine/SX-ttinfo.cpp | 2 +-
libgnucash/engine/{SX-ttinfo.h => SX-ttinfo.hpp} | 8 --
.../engine/{SchedXaction.c => SchedXaction.cpp} | 99 +++++++---------------
po/POTFILES.in | 2 +-
8 files changed, 39 insertions(+), 84 deletions(-)
rename libgnucash/engine/{SX-ttinfo.h => SX-ttinfo.hpp} (98%)
rename libgnucash/engine/{SchedXaction.c => SchedXaction.cpp} (94%)
More information about the gnucash-changes
mailing list