Skip to content

Commit

Permalink
clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
wichtounet committed Aug 11, 2023
1 parent 5bd1ae9 commit 39a8e3e
Show file tree
Hide file tree
Showing 28 changed files with 224 additions and 223 deletions.
4 changes: 2 additions & 2 deletions include/currency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace budget {
struct date;

double exchange_rate(const std::string& from);
double exchange_rate(const std::string& from, budget::date d);
double exchange_rate(const std::string& from, const budget::date& d);
double exchange_rate(const std::string& from, const std::string& to);
double exchange_rate(const std::string& from, const std::string& to, budget::date d);
double exchange_rate(const std::string& from, const std::string& to, const budget::date& d);

void load_currency_cache();
void save_currency_cache();
Expand Down
2 changes: 1 addition & 1 deletion include/date.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ date local_day();

date date_from_string(std::string_view str);

std::string date_to_string(date date);
std::string date_to_string(const date& date);

template<>
inline std::string to_string(budget::date date){
Expand Down
2 changes: 1 addition & 1 deletion include/debts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct debt {
std::map<std::string, std::string> get_params() const ;

void load(data_reader & reader);
void save(data_writer & writer);
void save(data_writer& writer) const;
};

void load_debts();
Expand Down
2 changes: 1 addition & 1 deletion include/earnings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct earning {
std::map<std::string, std::string> get_params() const ;

void load(data_reader& reader);
void save(data_writer & writer);
void save(data_writer& writer) const;
};

void load_earnings();
Expand Down
2 changes: 1 addition & 1 deletion include/expenses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct expense {
std::map<std::string, std::string> get_params() const ;

void load(data_reader & reader);
void save(data_writer & writer);
void save(data_writer& writer) const;
};

void load_expenses();
Expand Down
2 changes: 1 addition & 1 deletion include/fortune.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct fortune {
std::map<std::string, std::string> get_params() const ;

void load(data_reader & reader);
void save(data_writer & writer);
void save(data_writer& writer) const;
};

budget::money current_fortune();
Expand Down
4 changes: 2 additions & 2 deletions include/incomes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct income {
std::map<std::string, std::string> get_params() const ;

void load(data_reader & reader);
void save(data_writer & writer);
void save(data_writer& writer) const;
};

void load_incomes();
Expand All @@ -70,7 +70,7 @@ void show_incomes(budget::writer& w);
struct data_cache;

budget::money get_base_income(data_cache & cache);
budget::money get_base_income(data_cache & cache, budget::date d);
budget::money get_base_income(data_cache& cache, const budget::date& d);

budget::income new_income(budget::money amount, bool print);

Expand Down
9 changes: 5 additions & 4 deletions include/liabilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void save_liabilities();
void show_liabilities(budget::writer& w);

budget::liability get_liability(size_t id);
budget::liability get_liability(std::string name);
budget::liability get_liability(const std::string& name);

std::vector<budget::liability> all_liabilities();

Expand All @@ -90,15 +90,16 @@ void migrate_liabilities_6_to_7();

// The value of a liability in its own currency
budget::money get_liability_value(budget::liability & liability, data_cache & cache);
budget::money get_liability_value(budget::liability & liability, budget::date d, data_cache & cache);
budget::money get_liability_value(budget::liability& liability, const budget::date& d, data_cache& cache);

// The value of a liability in the default currency
budget::money get_liability_value_conv(budget::liability & liability, data_cache & cache);
budget::money get_liability_value_conv(budget::liability & liability, budget::date d, data_cache & cache);
budget::money get_liability_value_conv(budget::liability& liability, const budget::date& d, data_cache& cache);

// The value of a liability in a specific currency
budget::money get_liability_value_conv(budget::liability & liability, const std::string& currency, data_cache & cache);
budget::money get_liability_value_conv(budget::liability & liability, budget::date d, const std::string& currency, data_cache & cache);
budget::money get_liability_value_conv(budget::liability& liability, const budget::date& d, const std::string& currency,
data_cache& cache);

// Utilities for liabilities
void update_asset_class_allocation(budget::liability& liability, budget::asset_class & clas, budget::money alloc);
Expand Down
2 changes: 1 addition & 1 deletion include/objectives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct objective {
std::map<std::string, std::string> get_params() const ;

void load(data_reader & reader);
void save(data_writer & writer);
void save(data_writer& writer) const;
};

void yearly_objective_status(budget::writer& w, bool lines, bool full_align);
Expand Down
2 changes: 1 addition & 1 deletion include/wishes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct wish {
std::map<std::string, std::string> get_params() const ;

void load(data_reader & reader);
void save(data_writer & writer);
void save(data_writer & writer) const;
};

void load_wishes();
Expand Down
3 changes: 1 addition & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ bool verify_folder(){

return false;

} else {
return false;
}
return false;
}

return true;
Expand Down
29 changes: 15 additions & 14 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@ std::string budget::format_reset() {
std::string budget::format_money(const budget::money& m) {
if (m.positive()) {
return "::green" + budget::to_string(m);
} else if (m.negative()) {
}

if (m.negative()) {
return "::red" + budget::to_string(m);
} else {
return budget::to_string(m);
}

return budget::to_string(m);
}

std::string budget::format_money_reverse(const budget::money& m) {
if (m.positive()) {
return "::red" + budget::to_string(m);
} else if (m.negative()) {
}

if (m.negative()) {
return "::green" + budget::to_string(m);
} else {
return budget::to_string(m);
}

return budget::to_string(m);
}

size_t budget::rsize(const std::string& value) {
Expand Down Expand Up @@ -113,7 +117,7 @@ namespace {

char getch() {
char buf = 0;
struct termios old;
struct termios old{};
fflush(stdout);

if (tcgetattr(0, &old) < 0) {
Expand Down Expand Up @@ -156,25 +160,22 @@ std::string budget::get_string_complete(const std::vector<std::string>& choices)
size_t index = 0;

while (true) {
char c = getch();
const char c = getch();

if (+c == 127) {
if (!answer.empty()) {
std::cout << "\b \b";
answer.pop_back();
}
} else if (c == '\r') {
std::cout << std::endl;
return answer;
} else if (c == '\n') {
} else if (c == '\r' || c == '\n') {
std::cout << std::endl;
return answer;
} else if (c == '\t') {
if (!answer.empty()) {
size_t count = 0;
std::string valid;

for (auto& choice : choices) {
for (const auto& choice : choices) {
if (choice.size() > answer.size()) {
if (choice.substr(0, answer.size()) == answer) {
++count;
Expand All @@ -191,7 +192,7 @@ std::string budget::get_string_complete(const std::vector<std::string>& choices)
} else if (c == '\033') {
getch();

char cc = getch();
const char cc = getch();

if (cc == 'A') {
for (size_t i = 0; i < answer.size(); ++i) {
Expand Down
24 changes: 13 additions & 11 deletions src/console_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ std::string success_to_string(int success) {
ss << "%\033[0m ";

success = std::min(success, 109);
size_t good = success == 0 ? 0 : (success / 10) + 1;
const size_t good = success == 0 ? 0 : (success / 10) + 1;

for (size_t i = 0; i < good; ++i) {
ss << "\033[1;42m \033[0m";
Expand All @@ -48,7 +48,8 @@ std::string format(const std::string& v) {
auto value = v.substr(5);

return "\033[0;31m" + value + budget::format_reset();
} else if (v.substr(0, 7) == "::green") {
}
if (v.substr(0, 7) == "::green") {
auto value = v.substr(7);

return "\033[0;32m" + value + budget::format_reset();
Expand All @@ -57,7 +58,7 @@ std::string format(const std::string& v) {

return "\033[0;33m" + value + budget::format_reset();
} else if (v.substr(0, 9) == "::success") {
auto value = v.substr(9);
auto value = v.substr(9);
auto success = budget::to_number<unsigned long>(value);
return success_to_string(success);
}
Expand All @@ -70,7 +71,8 @@ std::string underline_format(const std::string& v) {
auto value = v.substr(5);

return "\033[4;31m" + value + budget::format_reset();
} else if (v.substr(0, 7) == "::green") {
}
if (v.substr(0, 7) == "::green") {
auto value = v.substr(7);

return "\033[4;32m" + value + budget::format_reset();
Expand All @@ -79,7 +81,7 @@ std::string underline_format(const std::string& v) {

return "\033[4;33m" + value + budget::format_reset();
} else if (v.substr(0, 9) == "::success") {
auto value = v.substr(9);
auto value = v.substr(9);
auto success = budget::to_number<unsigned long>(value);
return success_to_string(success);
}
Expand Down Expand Up @@ -151,10 +153,10 @@ budget::writer& budget::console_writer::operator<<(const budget::title_end_t&) {

void budget::console_writer::display_table(std::vector<std::string>& columns, std::vector<std::vector<std::string>>& contents, size_t groups, std::vector<size_t> lines, size_t left, [[maybe_unused]] size_t foot) {
cpp_assert(groups > 0, "There must be at least 1 group");
cpp_assert(contents.size() || columns.size(), "There must be at least some columns or contents");
cpp_assert(!contents.empty() || !columns.empty(), "There must be at least some columns or contents");

// Remove the Edit column, if necessary
if (columns.size() && columns.back() == "Edit") {
if (!columns.empty() && columns.back() == "Edit") {
columns.pop_back();

for (auto& row : contents) {
Expand All @@ -171,7 +173,7 @@ void budget::console_writer::display_table(std::vector<std::string>& columns, st
std::vector<size_t> widths;
std::vector<size_t> header_widths;

if (!contents.size()) {
if (contents.empty()) {
for (auto& column : columns) {
widths.push_back(rsize(column));
}
Expand All @@ -187,7 +189,7 @@ void budget::console_writer::display_table(std::vector<std::string>& columns, st
}
}

cpp_assert(columns.size() == 0 || widths.size() == groups * columns.size(), "Widths incorrectly computed");
cpp_assert(columns.empty() || widths.size() == groups * columns.size(), "Widths incorrectly computed");

// Display the header

Expand Down Expand Up @@ -241,7 +243,7 @@ void budget::console_writer::display_table(std::vector<std::string>& columns, st

auto& row = contents[i];

bool underline = std::find(lines.begin(), lines.end(), i) != lines.end();
const bool underline = std::find(lines.begin(), lines.end(), i) != lines.end();

for (size_t j = 0; j < row.size(); j += groups) {
size_t acc_width = 0;
Expand All @@ -250,7 +252,7 @@ void budget::console_writer::display_table(std::vector<std::string>& columns, st
for (size_t k = 0; k < groups - 1; ++k) {
auto column = j + k;

std::string value = format(row[column]);
std::string const value = format(row[column]);

acc_width += widths[column];

Expand Down
Loading

0 comments on commit 39a8e3e

Please sign in to comment.