Skip to content

Commit

Permalink
constness
Browse files Browse the repository at this point in the history
  • Loading branch information
wichtounet committed Sep 28, 2023
1 parent 73dd935 commit a4c5b2a
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/fortune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ budget::money budget::current_fortune(){
budget::money fortune_amount = all.front().amount;
date fortune_date = all.front().check_date;

for (auto& fortune : all) {
for (const auto& fortune : all) {
if (fortune.check_date > fortune_date) {
fortune_amount = fortune.amount;
fortune_date = fortune.check_date;
Expand Down
4 changes: 2 additions & 2 deletions src/incomes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ budget::money budget::get_base_income(data_cache & cache){
budget::money budget::get_base_income(data_cache& cache, const budget::date& d) {
// First, we try to get the base income from the incomes module

for (auto & income : cache.incomes()) {
for (const auto & income : cache.incomes()) {
if (income.since <= d && income.until >= d) {
return income.amount;
}
Expand All @@ -172,7 +172,7 @@ budget::money budget::get_base_income(data_cache& cache, const budget::date& d)

budget::money income;

for (auto& account : all_accounts(cache, d.year(), d.month())) {
for (const auto& account : all_accounts(cache, d.year(), d.month())) {
income += account.amount;
}

Expand Down
6 changes: 3 additions & 3 deletions src/liabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data_handler<liability> liabilities{"liabilities", "liabilities.data"};
std::vector<std::string> get_liabilities_names(){
std::vector<std::string> names;

for (auto& liability : all_liabilities()) {
for (const auto& liability : all_liabilities()) {
names.push_back(liability.name);
}

Expand Down Expand Up @@ -336,7 +336,7 @@ budget::date budget::liability_start_date(data_cache& cache) {

auto asset_values = cache.asset_values();

for (auto& liability : cache.liabilities()) {
for (const auto& liability : cache.liabilities()) {
start = std::min(start, min_with_default(asset_values | liability_only | filter_by_asset(liability.id) | to_date, start));
}

Expand Down Expand Up @@ -442,7 +442,7 @@ bool budget::no_liabilities() {
budget::money budget::get_liability_value(const budget::liability& liability, const budget::date& d, data_cache& cache) {
budget::money asset_value_amount;

for (auto& asset_value : cache.sorted_group_asset_values(true)[liability.id]) {
for (const auto& asset_value : cache.sorted_group_asset_values(true)[liability.id]) {
if (asset_value.set_date <= d) {
if (asset_value.liability) {
asset_value_amount = asset_value.amount;
Expand Down
10 changes: 5 additions & 5 deletions src/objectives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ std::map<std::string, std::string, std::less<>> budget::objective::get_params()
void budget::yearly_objective_status(budget::writer& w, bool lines, bool full_align){
size_t yearly = 0;

for (auto& objective : w.cache.objectives()) {
for (const auto& objective : w.cache.objectives()) {
if (objective.type == "yearly") {
++yearly;
}
Expand All @@ -76,11 +76,11 @@ void budget::yearly_objective_status(budget::writer& w, bool lines, bool full_al

size_t width = 0;
if (full_align) {
for (auto& objective : w.cache.objectives()) {
for (const auto& objective : w.cache.objectives()) {
width = std::max(rsize(objective.name), width);
}
} else {
for (auto& objective : w.cache.objectives() | filter_by_type("yearly")) {
for (const auto& objective : w.cache.objectives() | filter_by_type("yearly")) {
width = std::max(rsize(objective.name), width);
}
}
Expand All @@ -91,7 +91,7 @@ void budget::yearly_objective_status(budget::writer& w, bool lines, bool full_al
std::vector<std::string> columns = {"Goal", "Status", "Progress"};
std::vector<std::vector<std::string>> contents;

for (auto& objective : w.cache.objectives() | filter_by_type("yearly")) {
for (const auto& objective : w.cache.objectives() | filter_by_type("yearly")) {
contents.push_back({objective.name, get_status(year_status, objective), get_success(year_status, objective)});
}

Expand All @@ -107,7 +107,7 @@ void budget::monthly_objective_status(budget::writer& w){
auto current_year = today.year();
auto sm = start_month(w.cache, current_year);

for (auto& objective : w.cache.objectives() | filter_by_type("monthly")) {
for (const auto& objective : w.cache.objectives() | filter_by_type("monthly")) {
std::vector<std::string> columns = {objective.name, "Status", "Progress"};
std::vector<std::vector<std::string>> contents;

Expand Down
22 changes: 11 additions & 11 deletions src/overview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool invalid_accounts_all(){
return true;
}

for(auto& c : current_accounts){
for(const auto& c : current_accounts){
bool found = false;

for (const auto& p : previous) {
Expand Down Expand Up @@ -85,10 +85,10 @@ bool invalid_accounts(budget::year year){
return true;
}

for(auto& c : current_accounts){
for(const auto& c : current_accounts){
bool found = false;

for(auto& p : previous){
for(const auto& p : previous){
if(p.name == c.name){
found = true;
break;
Expand Down Expand Up @@ -152,7 +152,7 @@ budget::money compute_total_budget_account(budget::account & account, budget::mo
// Note: we still need to access the previous accounts since the
// current account could be a more recent version of an archived
// account
for(auto& prev_account : all_accounts(cache, y, m)){
for(const auto& prev_account : all_accounts(cache, y, m)){
if (prev_account.name == account.name) {
total += prev_account.amount;
total -= fold_left_auto(all_expenses_month(cache, prev_account.id, y, m) | to_amount);
Expand All @@ -173,7 +173,7 @@ budget::money compute_total_budget_account(budget::account & account, budget::mo
// Note: Here we do not strictly have to access the previous version
// since this version is supposed to be called with match account/month/year
// But doing so may prevent issue
for (auto& prev_account : all_accounts(cache, year, month)) {
for (const auto& prev_account : all_accounts(cache, year, month)) {
if (prev_account.name == account.name) {
total += prev_account.amount;
break;
Expand Down Expand Up @@ -202,7 +202,7 @@ std::vector<budget::money> compute_total_budget(data_cache & cache, budget::mont
break;
}

for(auto& account : all_accounts(cache, y, m)){
for(const auto& account : all_accounts(cache, y, m)){
tmp[account.name] += account.amount;
tmp[account.name] -= fold_left_auto(all_expenses_month(cache, account.id, y, m) | to_amount);
tmp[account.name] += fold_left_auto(all_earnings_month(cache, account.id, y, m) | to_amount);
Expand All @@ -218,7 +218,7 @@ std::vector<budget::money> compute_total_budget(data_cache & cache, budget::mont

std::vector<budget::money> total_budgets;

for(auto& account : all_accounts(cache, year, month)){
for(const auto& account : all_accounts(cache, year, month)){
tmp[account.name] += account.amount;

total_budgets.push_back(tmp[account.name]);
Expand Down Expand Up @@ -302,7 +302,7 @@ std::pair<budget::money, acc_data_t> aggregate(const Data & data, bool full, boo
}

data_cache cache;
for (auto& account : current_accounts(cache)) {
for (const auto& account : current_accounts(cache)) {
if (!acc_data.contains(account.name)) {
acc_data[account.name];
}
Expand Down Expand Up @@ -1029,7 +1029,7 @@ void budget::display_balance(budget::writer& w, budget::year year, bool relaxed,

//Prepare the rows

for(auto& account : all_accounts(w.cache, year, sm)){
for(const auto& account : all_accounts(w.cache, year, sm)){
row_mapping[account.name] = contents.size();

contents.push_back({account.name});
Expand All @@ -1040,7 +1040,7 @@ void budget::display_balance(budget::writer& w, budget::year year, bool relaxed,
if(year > today.year()){
auto pretotal = compute_total_budget(w.cache, sm, year);
size_t i = 0;
for(auto& account : all_accounts(w.cache, year, sm)){
for(const auto& account : all_accounts(w.cache, year, sm)){
account_previous[account.name][sm - 1] += pretotal[i++] - account.amount;
}
}
Expand All @@ -1050,7 +1050,7 @@ void budget::display_balance(budget::writer& w, budget::year year, bool relaxed,
for(unsigned short i = sm; i <= 12; ++i){
const budget::month m = i;

for(auto& account : all_accounts(w.cache, year, m)){
for(const auto& account : all_accounts(w.cache, year, m)){
budget::money total_expenses;
budget::money total_earnings;

Expand Down
4 changes: 2 additions & 2 deletions src/recurring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ budget::date last_date(const budget::recurring& recurring) {
budget::date last(1400, 1, 1);

if (recurring.type == "expense") {
for (auto& expense : all_expenses()) {
for (const auto& expense : all_expenses()) {
if (expense.name == recurring.name && expense.amount == recurring.amount && get_account(expense.account).name == recurring.account) {
if (expense.date > last) {
last = expense.date;
}
}
}
} else if (recurring.type == "earning") {
for (auto& earning : all_earnings()) {
for (const auto& earning : all_earnings()) {
if (earning.name == recurring.name && earning.amount == recurring.amount && get_account(earning.account).name == recurring.account) {
if (earning.date > last) {
last = earning.date;
Expand Down
8 changes: 4 additions & 4 deletions src/report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ using graph_type = std::vector<std::vector<std::string>>;
void render(budget::writer& w, graph_type& graph) {
std::ranges::reverse(graph);

for (auto& line : graph) {
for (auto& col : line) {
for (const auto& line : graph) {
for (const auto& col : line) {
w << col;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ void budget::report(budget::writer& w, budget::year year, bool filter, const std
budget::money m_expenses;
budget::money m_earnings;

for (auto& account : all_accounts(w.cache, year, month)) {
for (const auto& account : all_accounts(w.cache, year, month)) {
if (!filter || account.name == filter_account) {
auto expenses = fold_left_auto(all_expenses_month(w.cache, account.id, year, month) | to_amount);
auto earnings = fold_left_auto(all_earnings_month(w.cache, account.id, year, month) | to_amount);
Expand Down Expand Up @@ -145,7 +145,7 @@ void budget::report(budget::writer& w, budget::year year, bool filter, const std
budget::money total_earnings;
budget::money total_balance;

for (auto& account : all_accounts(w.cache, year, month)) {
for (const auto& account : all_accounts(w.cache, year, month)) {
if (!filter || account.name == filter_account) {
auto expenses = fold_left_auto(all_expenses_month(w.cache, account.id, year, month) | to_amount);
auto earnings = fold_left_auto(all_earnings_month(w.cache, account.id, year, month) | to_amount);
Expand Down
2 changes: 1 addition & 1 deletion src/share.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void budget::prefetch_share_price_cache(){
const server_lock_guard l(shares_lock);

// Collect all the tickers
for (auto& [key, value] : share_prices) {
for (const auto& [key, value] : share_prices) {
tickers.insert(key.ticker);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void budget::account_summary(budget::writer& w, budget::month month, budget::yea
for (unsigned short i = sm; i <= month; ++i) {
const budget::month m = i;

for (auto& account : all_accounts(w.cache, year, m)) {
for (const auto& account : all_accounts(w.cache, year, m)) {
auto total_expenses = fold_left_auto(w.cache.expenses() | filter_by_account(account.id) | filter_by_date(year, m) | to_amount);
auto total_earnings = fold_left_auto(w.cache.earnings() | filter_by_account(account.id) | filter_by_date(year, m) | to_amount);

Expand Down

0 comments on commit a4c5b2a

Please sign in to comment.