[Query.cpp] convert to cpp

This commit is contained in:
Christopher Lam 2024-03-17 16:41:27 +08:00
parent 4d9836aac2
commit a67e4651c3
3 changed files with 55 additions and 55 deletions

View File

@ -138,7 +138,7 @@ add_custom_target(iso-4217-c DEPENDS ${ISO_4217_C})
set (engine_SOURCES set (engine_SOURCES
Account.cpp Account.cpp
Recurrence.cpp Recurrence.cpp
Query.c Query.cpp
SchedXaction.c SchedXaction.c
SX-book.c SX-book.c
SX-ttinfo.c SX-ttinfo.c

View File

@ -50,7 +50,7 @@ static QofLogModule log_module = GNC_MOD_QUERY;
static GSList * static GSList *
build_param_list_internal (const char *first, va_list rest) build_param_list_internal (const char *first, va_list rest)
{ {
GSList *list = NULL; GSList *list = nullptr;
char const *param; char const *param;
for (param = first; param; param = va_arg (rest, const char *)) for (param = first; param; param = va_arg (rest, const char *))
@ -69,12 +69,12 @@ xaccQueryGetSplitsUniqueTrans(QofQuery *q)
{ {
GList * splits = qof_query_run(q); GList * splits = qof_query_run(q);
GList * current; GList * current;
GList * result = NULL; GList * result = nullptr;
GHashTable * trans_hash = g_hash_table_new(g_direct_hash, g_direct_equal); GHashTable * trans_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
for (current = splits; current; current = current->next) for (current = splits; current; current = current->next)
{ {
Split *split = current->data; Split *split = GNC_SPLIT (current->data);
Transaction *trans = xaccSplitGetParent (split); Transaction *trans = xaccSplitGetParent (split);
if (!g_hash_table_lookup (trans_hash, trans)) if (!g_hash_table_lookup (trans_hash, trans))
@ -98,9 +98,9 @@ xaccQueryGetSplitsUniqueTrans(QofQuery *q)
static void static void
query_match_all_filter_func(gpointer key, gpointer value, gpointer user_data) query_match_all_filter_func(gpointer key, gpointer value, gpointer user_data)
{ {
Transaction * t = key; Transaction * t = GNC_TRANSACTION(key);
int num_matches = GPOINTER_TO_INT(value); int num_matches = GPOINTER_TO_INT(value);
GList ** matches = user_data; auto matches = static_cast<GList**>(user_data);
if (num_matches == xaccTransCountSplits(t)) if (num_matches == xaccTransCountSplits(t))
{ {
@ -111,8 +111,8 @@ query_match_all_filter_func(gpointer key, gpointer value, gpointer user_data)
static void static void
query_match_any_filter_func(gpointer key, gpointer value, gpointer user_data) query_match_any_filter_func(gpointer key, gpointer value, gpointer user_data)
{ {
Transaction * t = key; Transaction * t = GNC_TRANSACTION(key);
GList ** matches = user_data; auto matches = static_cast<GList**>(user_data);
*matches = g_list_prepend(*matches, t); *matches = g_list_prepend(*matches, t);
} }
@ -120,18 +120,18 @@ TransList *
xaccQueryGetTransactions (QofQuery * q, query_txn_match_t runtype) xaccQueryGetTransactions (QofQuery * q, query_txn_match_t runtype)
{ {
GList * splits = qof_query_run(q); GList * splits = qof_query_run(q);
GList * current = NULL; GList * current = nullptr;
GList * retval = NULL; GList * retval = nullptr;
GHashTable * trans_hash = g_hash_table_new(g_direct_hash, g_direct_equal); GHashTable * trans_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
Transaction * trans = NULL; Transaction * trans = nullptr;
gpointer val = NULL; gpointer val = nullptr;
int count = 0; int count = 0;
/* iterate over matching splits, incrementing a match-count in /* iterate over matching splits, incrementing a match-count in
* the hash table */ * the hash table */
for (current = splits; current; current = current->next) for (current = splits; current; current = current->next)
{ {
trans = xaccSplitGetParent((Split *)(current->data)); trans = xaccSplitGetParent(GNC_SPLIT(current->data));
/* don't waste time looking up unless we need the count /* don't waste time looking up unless we need the count
* information */ * information */
@ -169,9 +169,9 @@ xaccQueryGetTransactions (QofQuery * q, query_txn_match_t runtype)
static void static void
query_match_all_lot_filter_func(gpointer key, gpointer value, gpointer user_data) query_match_all_lot_filter_func(gpointer key, gpointer value, gpointer user_data)
{ {
GNCLot * l = key; GNCLot * l = GNC_LOT(key);
int num_matches = GPOINTER_TO_INT(value); int num_matches = GPOINTER_TO_INT(value);
GList ** matches = user_data; auto matches = static_cast<GList**>(user_data);
if (num_matches == gnc_lot_count_splits(l)) if (num_matches == gnc_lot_count_splits(l))
{ {
@ -182,8 +182,8 @@ query_match_all_lot_filter_func(gpointer key, gpointer value, gpointer user_data
static void static void
query_match_any_lot_filter_func(gpointer key, gpointer value, gpointer user_data) query_match_any_lot_filter_func(gpointer key, gpointer value, gpointer user_data)
{ {
GNCLot * t = key; GNCLot * t = GNC_LOT(key);
GList ** matches = user_data; auto matches = static_cast<GList**>(user_data);
*matches = g_list_prepend(*matches, t); *matches = g_list_prepend(*matches, t);
} }
@ -191,18 +191,18 @@ LotList *
xaccQueryGetLots (QofQuery * q, query_txn_match_t runtype) xaccQueryGetLots (QofQuery * q, query_txn_match_t runtype)
{ {
GList * splits = qof_query_run(q); GList * splits = qof_query_run(q);
GList * current = NULL; GList * current = nullptr;
GList * retval = NULL; GList * retval = nullptr;
GHashTable * lot_hash = g_hash_table_new(g_direct_hash, g_direct_equal); GHashTable * lot_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
GNCLot * lot = NULL; GNCLot * lot = nullptr;
gpointer val = NULL; gpointer val = nullptr;
int count = 0; int count = 0;
/* iterate over matching splits, incrementing a match-count in /* iterate over matching splits, incrementing a match-count in
* the hash table */ * the hash table */
for (current = splits; current; current = current->next) for (current = splits; current; current = current->next)
{ {
lot = xaccSplitGetLot((Split *)(current->data)); lot = xaccSplitGetLot((GNC_SPLIT (current->data)));
/* don't waste time looking up unless we need the count /* don't waste time looking up unless we need the count
* information */ * information */
@ -239,24 +239,24 @@ void
xaccQueryAddAccountMatch(QofQuery *q, AccountList *acct_list, xaccQueryAddAccountMatch(QofQuery *q, AccountList *acct_list,
QofGuidMatch how, QofQueryOp op) QofGuidMatch how, QofQueryOp op)
{ {
GList *list = NULL; GList *list = nullptr;
if (!q) return; if (!q) return;
for (; acct_list; acct_list = acct_list->next) for (; acct_list; acct_list = acct_list->next)
{ {
Account *acc = acct_list->data; Account *acc = GNC_ACCOUNT (acct_list->data);
const GncGUID *guid; const GncGUID *guid;
if (!acc) if (!acc)
{ {
PWARN ("acct_list has NULL account"); PWARN ("acct_list has nullptr account");
continue; continue;
} }
guid = qof_entity_get_guid (QOF_INSTANCE(acc)); guid = qof_entity_get_guid (QOF_INSTANCE(acc));
if (!guid) if (!guid)
{ {
PWARN ("acct returns NULL GncGUID"); PWARN ("acct returns nullptr GncGUID");
continue; continue;
} }
@ -271,13 +271,13 @@ xaccQueryAddAccountGUIDMatch(QofQuery *q, AccountGUIDList *guid_list,
QofGuidMatch how, QofQueryOp op) QofGuidMatch how, QofQueryOp op)
{ {
QofQueryPredData *pred_data; QofQueryPredData *pred_data;
GSList *param_list = NULL; GSList *param_list = nullptr;
if (!q) return; if (!q) return;
if (!guid_list && how != QOF_GUID_MATCH_NULL) if (!guid_list && how != QOF_GUID_MATCH_NULL)
{ {
g_warning("Got a NULL guid_list but the QofGuidMatch is not MATCH_NULL (but instead %d). In other words, the list of GUID matches is empty but it must contain something non-empty.", how); g_warning("Got a nullptr guid_list but the QofGuidMatch is not MATCH_nullptr (but instead %d). In other words, the list of GUID matches is empty but it must contain something non-empty.", how);
/* qof_query_guid_predicate() would trigger a g_warning as well */ /* qof_query_guid_predicate() would trigger a g_warning as well */
return; return;
} }
@ -289,11 +289,11 @@ xaccQueryAddAccountGUIDMatch(QofQuery *q, AccountGUIDList *guid_list,
{ {
case QOF_GUID_MATCH_ANY: case QOF_GUID_MATCH_ANY:
case QOF_GUID_MATCH_NONE: case QOF_GUID_MATCH_NONE:
param_list = qof_query_build_param_list (SPLIT_ACCOUNT, QOF_PARAM_GUID, NULL); param_list = qof_query_build_param_list (SPLIT_ACCOUNT, QOF_PARAM_GUID, nullptr);
break; break;
case QOF_GUID_MATCH_ALL: case QOF_GUID_MATCH_ALL:
param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_SPLITLIST, param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_SPLITLIST,
SPLIT_ACCOUNT_GUID, NULL); SPLIT_ACCOUNT_GUID, nullptr);
break; break;
default: default:
PERR ("Invalid match type: %d", how); PERR ("Invalid match type: %d", how);
@ -315,7 +315,7 @@ xaccQueryAddSingleAccountMatch(QofQuery *q, Account *acc, QofQueryOp op)
guid = qof_entity_get_guid (QOF_INSTANCE(acc)); guid = qof_entity_get_guid (QOF_INSTANCE(acc));
g_return_if_fail (guid); g_return_if_fail (guid);
list = g_list_prepend (NULL, (gpointer)guid); list = g_list_prepend (nullptr, (gpointer)guid);
xaccQueryAddAccountGUIDMatch (q, list, QOF_GUID_MATCH_ANY, op); xaccQueryAddAccountGUIDMatch (q, list, QOF_GUID_MATCH_ANY, op);
g_list_free (list); g_list_free (list);
} }
@ -385,7 +385,7 @@ xaccQueryAddDateMatchTT (QofQuery * q,
gboolean use_end, time64 ett, gboolean use_end, time64 ett,
QofQueryOp op) QofQueryOp op)
{ {
QofQuery *tmp_q = NULL; QofQuery *tmp_q = nullptr;
QofQueryPredData *pred_data; QofQueryPredData *pred_data;
GSList *param_list; GSList *param_list;
@ -403,7 +403,7 @@ xaccQueryAddDateMatchTT (QofQuery * q,
return; return;
} }
param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, NULL); param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, nullptr);
qof_query_add_term (tmp_q, param_list, pred_data, QOF_QUERY_AND); qof_query_add_term (tmp_q, param_list, pred_data, QOF_QUERY_AND);
} }
@ -416,7 +416,7 @@ xaccQueryAddDateMatchTT (QofQuery * q,
return; return;
} }
param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, NULL); param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, nullptr);
qof_query_add_term (tmp_q, param_list, pred_data, QOF_QUERY_AND); qof_query_add_term (tmp_q, param_list, pred_data, QOF_QUERY_AND);
} }
@ -436,13 +436,13 @@ xaccQueryGetDateMatchTT (QofQuery * q,
*stt = 0; *stt = 0;
*ett = 0; *ett = 0;
param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, NULL); param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, nullptr);
terms = qof_query_get_term_type (q, param_list); terms = qof_query_get_term_type (q, param_list);
g_slist_free(param_list); g_slist_free(param_list);
for (tmp = terms; tmp; tmp = g_slist_next(tmp)) for (tmp = terms; tmp; tmp = g_slist_next(tmp))
{ {
term_data = tmp->data; term_data = static_cast<QofQueryPredData*>(tmp->data);
if (term_data->how == QOF_COMPARE_GTE) if (term_data->how == QOF_COMPARE_GTE)
qof_query_date_predicate_get_date(term_data, stt); qof_query_date_predicate_get_date(term_data, stt);
if (term_data->how == QOF_COMPARE_LTE) if (term_data->how == QOF_COMPARE_LTE)
@ -497,7 +497,7 @@ xaccQueryAddClearedMatch(QofQuery * q, cleared_match_t how, QofQueryOp op)
if (!pred_data) if (!pred_data)
return; return;
param_list = qof_query_build_param_list (SPLIT_RECONCILE, NULL); param_list = qof_query_build_param_list (SPLIT_RECONCILE, nullptr);
qof_query_add_term (q, param_list, pred_data, op); qof_query_add_term (q, param_list, pred_data, op);
} }
@ -506,17 +506,17 @@ void
xaccQueryAddGUIDMatch(QofQuery * q, const GncGUID *guid, xaccQueryAddGUIDMatch(QofQuery * q, const GncGUID *guid,
QofIdType id_type, QofQueryOp op) QofIdType id_type, QofQueryOp op)
{ {
GSList *param_list = NULL; GSList *param_list = nullptr;
if (!q || !guid || !id_type) if (!q || !guid || !id_type)
return; return;
if (!g_strcmp0 (id_type, GNC_ID_SPLIT)) if (!g_strcmp0 (id_type, GNC_ID_SPLIT))
param_list = qof_query_build_param_list (QOF_PARAM_GUID, NULL); param_list = qof_query_build_param_list (QOF_PARAM_GUID, nullptr);
else if (!g_strcmp0 (id_type, GNC_ID_TRANS)) else if (!g_strcmp0 (id_type, GNC_ID_TRANS))
param_list = qof_query_build_param_list (SPLIT_TRANS, QOF_PARAM_GUID, NULL); param_list = qof_query_build_param_list (SPLIT_TRANS, QOF_PARAM_GUID, nullptr);
else if (!g_strcmp0 (id_type, GNC_ID_ACCOUNT)) else if (!g_strcmp0 (id_type, GNC_ID_ACCOUNT))
param_list = qof_query_build_param_list (SPLIT_ACCOUNT, QOF_PARAM_GUID, NULL); param_list = qof_query_build_param_list (SPLIT_ACCOUNT, QOF_PARAM_GUID, nullptr);
else else
PERR ("Invalid match type: %s", id_type); PERR ("Invalid match type: %s", id_type);
@ -534,7 +534,7 @@ xaccQueryAddClosingTransMatch(QofQuery *q, gboolean value, QofQueryOp op)
{ {
GSList *param_list; GSList *param_list;
param_list = qof_query_build_param_list(SPLIT_TRANS, TRANS_IS_CLOSING, NULL); param_list = qof_query_build_param_list(SPLIT_TRANS, TRANS_IS_CLOSING, nullptr);
qof_query_add_boolean_match(q, param_list, value, op); qof_query_add_boolean_match(q, param_list, value, op);
} }
@ -554,11 +554,11 @@ xaccQueryGetEarliestDateFound(QofQuery * q)
if (!spl) return 0; if (!spl) return 0;
/* Safe until 2038 on archs where time64 is 32bit */ /* Safe until 2038 on archs where time64 is 32bit */
sp = spl->data; sp = GNC_SPLIT (spl->data);
earliest = sp->parent->date_posted; earliest = sp->parent->date_posted;
for (; spl; spl = spl->next) for (; spl; spl = spl->next)
{ {
sp = spl->data; sp = GNC_SPLIT (spl->data);
if (sp->parent->date_posted < earliest) if (sp->parent->date_posted < earliest)
{ {
earliest = sp->parent->date_posted; earliest = sp->parent->date_posted;
@ -584,7 +584,7 @@ xaccQueryGetLatestDateFound(QofQuery * q)
for (; spl; spl = spl->next) for (; spl; spl = spl->next)
{ {
sp = spl->data; sp = GNC_SPLIT (spl->data);
if (sp->parent->date_posted > latest) if (sp->parent->date_posted > latest)
{ {
latest = sp->parent->date_posted; latest = sp->parent->date_posted;
@ -598,7 +598,7 @@ xaccQueryAddDescriptionMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
QofQueryCompare h, QofQueryOp o) QofQueryCompare h, QofQueryOp o)
{ {
xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_TRANS, xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_TRANS,
TRANS_DESCRIPTION, NULL); TRANS_DESCRIPTION, nullptr);
} }
void void
@ -606,7 +606,7 @@ xaccQueryAddNotesMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
QofQueryCompare h, QofQueryOp o) QofQueryCompare h, QofQueryOp o)
{ {
xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_TRANS, xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_TRANS,
TRANS_NOTES, NULL); TRANS_NOTES, nullptr);
} }
void void
@ -614,21 +614,21 @@ xaccQueryAddNumberMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
QofQueryCompare h, QofQueryOp o) QofQueryCompare h, QofQueryOp o)
{ {
xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_TRANS, xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_TRANS,
TRANS_NUM, NULL); TRANS_NUM, nullptr);
} }
void void
xaccQueryAddActionMatch(QofQuery *q, const char *m, gboolean c, gboolean r, xaccQueryAddActionMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
QofQueryCompare h, QofQueryOp o) QofQueryCompare h, QofQueryOp o)
{ {
xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_ACTION, NULL); xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_ACTION, nullptr);
} }
void void
xaccQueryAddMemoMatch(QofQuery *q, const char *m, gboolean c, gboolean r, xaccQueryAddMemoMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
QofQueryCompare h, QofQueryOp o) QofQueryCompare h, QofQueryOp o)
{ {
xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_MEMO, NULL); xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_MEMO, nullptr);
} }
void void
@ -636,7 +636,7 @@ xaccQueryAddValueMatch(QofQuery *q, gnc_numeric amt, QofNumericMatch sgn,
QofQueryCompare how, QofQueryOp op) QofQueryCompare how, QofQueryOp op)
{ {
xaccQueryAddNumericMatch ((q), (amt), (sgn), (how), (op), xaccQueryAddNumericMatch ((q), (amt), (sgn), (how), (op),
SPLIT_VALUE, NULL); SPLIT_VALUE, nullptr);
} }
void void
@ -644,7 +644,7 @@ xaccQueryAddSharePriceMatch(QofQuery *q, gnc_numeric amt, QofQueryCompare how,
QofQueryOp op) QofQueryOp op)
{ {
xaccQueryAddNumericMatch ((q), (amt), QOF_NUMERIC_MATCH_ANY, (how), (op), xaccQueryAddNumericMatch ((q), (amt), QOF_NUMERIC_MATCH_ANY, (how), (op),
SPLIT_SHARE_PRICE, NULL); SPLIT_SHARE_PRICE, nullptr);
} }
void void
@ -652,7 +652,7 @@ xaccQueryAddSharesMatch(QofQuery *q, gnc_numeric amt, QofQueryCompare how,
QofQueryOp op) QofQueryOp op)
{ {
xaccQueryAddNumericMatch ((q), (amt), QOF_NUMERIC_MATCH_ANY, (how), (op), xaccQueryAddNumericMatch ((q), (amt), QOF_NUMERIC_MATCH_ANY, (how), (op),
SPLIT_AMOUNT, NULL); SPLIT_AMOUNT, nullptr);
} }
void void
@ -661,7 +661,7 @@ xaccQueryAddBalanceMatch(QofQuery *q, QofQueryCompare bal, QofQueryOp op)
xaccQueryAddNumericMatch( xaccQueryAddNumericMatch(
(q), gnc_numeric_zero(), QOF_NUMERIC_MATCH_ANY, (q), gnc_numeric_zero(), QOF_NUMERIC_MATCH_ANY,
((bal) ? QOF_COMPARE_EQUAL : QOF_COMPARE_NEQ), (op), ((bal) ? QOF_COMPARE_EQUAL : QOF_COMPARE_NEQ), (op),
SPLIT_TRANS, TRANS_IMBALANCE, NULL); SPLIT_TRANS, TRANS_IMBALANCE, nullptr);
} }

View File

@ -683,7 +683,7 @@ libgnucash/engine/qofsession.cpp
libgnucash/engine/qof-string-cache.cpp libgnucash/engine/qof-string-cache.cpp
libgnucash/engine/qofutil.cpp libgnucash/engine/qofutil.cpp
libgnucash/engine/qof-win32.cpp libgnucash/engine/qof-win32.cpp
libgnucash/engine/Query.c libgnucash/engine/Query.cpp
libgnucash/engine/Recurrence.cpp libgnucash/engine/Recurrence.cpp
libgnucash/engine/SchedXaction.c libgnucash/engine/SchedXaction.c
libgnucash/engine/Scrub2.cpp libgnucash/engine/Scrub2.cpp