Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better c++ #1965

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open

Better c++ #1965

wants to merge 2 commits into from

Conversation

christopherlam
Copy link
Contributor

@christopherlam christopherlam commented Jun 19, 2024

to be selectively merged after 5.7.

  • adds an overloaded gnc_account_foreach_descendant for c++ use.
  • use c++ containers instead of creating new GLists

@christopherlam christopherlam force-pushed the better-c++ branch 6 times, most recently from 447f6b1 to 1e37258 Compare June 24, 2024 10:14
@christopherlam christopherlam force-pushed the better-c++ branch 2 times, most recently from 27f6336 to 95cfcf9 Compare July 2, 2024 12:56
@jralls
Copy link
Member

jralls commented Jul 3, 2024

to be selectively merged after 5.7.

That would be better as multiple PRs. It's ok to make a chain of them, just say in the comments who depends on who.

libgnucash/engine/Account.cpp Outdated Show resolved Hide resolved
gnucash/register/ledger-core/split-register-control.cpp Outdated Show resolved Hide resolved
gnucash/gnome/window-reconcile.cpp Outdated Show resolved Hide resolved
libgnucash/engine/Account.cpp Show resolved Hide resolved
else
return false;
auto limit = *priv_limit;
if (limit) *balance = *limit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That relies on an implicit cast from gnc_numeric to GncNumeric. Better to say *balance = gnc_numeric_create(limit->num, limit->denom);

}
else
else if (auto priv_limit = get_kvp_gnc_numeric_path (acc, { KEY_BALANCE_LIMIT, key }))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep KVP implementation details in QofInstance.

@@ -113,8 +113,10 @@ typedef struct AccountPrivate
gnc_numeric cleared_balance;
gnc_numeric reconciled_balance;

std::optional<gnc_numeric> higher_balance_limit;
std::optional<gnc_numeric> lower_balance_limit;
// outer optional to denote if balance_limit is cached
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too clever by half. Change your design so that the limits are loaded from KVP at object initialization and save the value to KVP in xaccAccountCommitEdit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too clever by half. Change your design so that the limits are loaded from KVP at object initialization and save the value to KVP in xaccAccountCommitEdit.

Not too sure about that. gnc_account_init shouldn't assume a book is available to read kvp from. I'm thinking a 'balance_limits_are_cached' bool may be used. Or, forego caching them altogether.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? You can't create any other kind of QofInstance without a book, not that that has anything to do with this.

You have the wrong mental model of KVP. KVP is a storage extension to provide class member variables that don't require a matching XML element name and therefore require adding handler code to the backend. Ideally KVP wouldn't exist and we'd maintain and version datafiles, but we don't. Next best would have the KVP code in the backends and map directly to instance member variables so the engine wouldn't have to worry about them.

gnucash/import-export/import-main-matcher.cpp Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants