aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/utility
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-10-28 11:39:08 +0200
committer hop311 <hop3114@gmail.com>2023-10-29 20:42:47 +0100
commit164264b047921dbe1567d2af183e1cffb200a8cb (patch)
tree21c3c81f65ac3259db4808ebe9fd32a94ca993af /src/openvic-simulation/utility
parentd8ec90f07342876e9331819bd3cc372050f78248 (diff)
Astyle formatting (with manual cleanup)
Diffstat (limited to 'src/openvic-simulation/utility')
-rw-r--r--src/openvic-simulation/utility/BMP.cpp6
-rw-r--r--src/openvic-simulation/utility/Logger.cpp24
-rw-r--r--src/openvic-simulation/utility/Logger.hpp24
-rw-r--r--src/openvic-simulation/utility/StringUtils.hpp42
4 files changed, 69 insertions, 27 deletions
diff --git a/src/openvic-simulation/utility/BMP.cpp b/src/openvic-simulation/utility/BMP.cpp
index 2fa9417..cdd8ead 100644
--- a/src/openvic-simulation/utility/BMP.cpp
+++ b/src/openvic-simulation/utility/BMP.cpp
@@ -91,14 +91,16 @@ bool BMP::read_header() {
#define STR(x) #x
static const std::set<uint16_t> BITS_PER_PIXEL { VALID_BITS_PER_PIXEL };
if (!BITS_PER_PIXEL.contains(header.bits_per_pixel)) {
- Logger::error("Invalid BMP bits per pixel: ", header.bits_per_pixel, " (must be one of " STR(VALID_BITS_PER_PIXEL) ")");
+ Logger::error("Invalid BMP bits per pixel: ", header.bits_per_pixel,
+ " (must be one of " STR(VALID_BITS_PER_PIXEL) ")");
header_validated = false;
}
#undef VALID_BITS_PER_PIXEL
#undef STR
static constexpr uint16_t PALETTE_BITS_PER_PIXEL_LIMIT = 8;
if (header.num_colours != 0 && header.bits_per_pixel > PALETTE_BITS_PER_PIXEL_LIMIT) {
- Logger::error("Invalid BMP palette size: ", header.num_colours, " (should be 0 as bits per pixel is ", header.bits_per_pixel, " > 8)");
+ Logger::error("Invalid BMP palette size: ", header.num_colours,
+ " (should be 0 as bits per pixel is ", header.bits_per_pixel, " > 8)");
header_validated = false;
}
// TODO - validate important_colours
diff --git a/src/openvic-simulation/utility/Logger.cpp b/src/openvic-simulation/utility/Logger.cpp
index 68c43dd..5e25c98 100644
--- a/src/openvic-simulation/utility/Logger.cpp
+++ b/src/openvic-simulation/utility/Logger.cpp
@@ -5,18 +5,30 @@
using namespace OpenVic;
void Logger::set_logger_funcs() {
- Logger::set_info_func([](std::string&& str) { std::cout << str; });
- Logger::set_warning_func([](std::string&& str) { std::cerr << str; });
- Logger::set_error_func([](std::string&& str) { std::cerr << str; });
+ Logger::set_info_func([](std::string&& str) {
+ std::cout << str;
+ });
+ Logger::set_warning_func([](std::string&& str) {
+ std::cerr << str;
+ });
+ Logger::set_error_func([](std::string&& str) {
+ std::cerr << str;
+ });
}
char const* Logger::get_filename(char const* filepath, char const* default_path) {
- if (filepath == nullptr) return default_path;
+ if (filepath == nullptr) {
+ return default_path;
+ }
char const* last_slash = filepath;
while (*filepath != '\0') {
- if (*filepath == '\\' || *filepath == '/') last_slash = filepath + 1;
+ if (*filepath == '\\' || *filepath == '/') {
+ last_slash = filepath + 1;
+ }
filepath++;
}
- if (*last_slash == '\0') return default_path;
+ if (*last_slash == '\0') {
+ return default_path;
+ }
return last_slash;
}
diff --git a/src/openvic-simulation/utility/Logger.hpp b/src/openvic-simulation/utility/Logger.hpp
index d60e59e..b2395ac 100644
--- a/src/openvic-simulation/utility/Logger.hpp
+++ b/src/openvic-simulation/utility/Logger.hpp
@@ -20,15 +20,23 @@ namespace OpenVic {
int _line;
std::string _function;
- public:
source_location(std::string f, int l, std::string n) : _file(f), _line(l), _function(n) {}
- static source_location current(std::string f = __builtin_FILE(), int l = __builtin_LINE(), std::string n = __builtin_FUNCTION()) {
+
+ public:
+ static source_location current(std::string f = __builtin_FILE(), int l = __builtin_LINE(),
+ std::string n = __builtin_FUNCTION()) {
return source_location(f, l, n);
}
- inline char const* file_name() const { return _file.c_str(); }
- inline int line() const { return _line; }
- inline char const* function_name() const { return _function.c_str(); }
+ inline char const* file_name() const {
+ return _file.c_str();
+ }
+ inline int line() const {
+ return _line;
+ }
+ inline char const* function_name() const {
+ return _function.c_str();
+ }
};
#endif
@@ -57,8 +65,10 @@ namespace OpenVic {
log(log_channel_t& log_channel, Ts&&... ts, source_location const& location) {
std::stringstream stream;
stream << "\n" << get_filename(location.file_name()) << "("
- //<< location.line() << ") `" << location.function_name() << "`: ";
- << location.line() << "): ";
+ /* Function name removed to reduce clutter. It is already included
+ * in Godot's print functions, so this was repeating it. */
+ //<< location.line() << ") `" << location.function_name() << "`: ";
+ << location.line() << "): ";
((stream << std::forward<Ts>(ts)), ...);
stream << std::endl;
log_channel.queue.push(stream.str());
diff --git a/src/openvic-simulation/utility/StringUtils.hpp b/src/openvic-simulation/utility/StringUtils.hpp
index 5784208..d968bf6 100644
--- a/src/openvic-simulation/utility/StringUtils.hpp
+++ b/src/openvic-simulation/utility/StringUtils.hpp
@@ -12,11 +12,14 @@ namespace OpenVic::StringUtils {
* or not conversion was successful. It can be nullptr if this information is not needed.
*/
constexpr uint64_t string_to_uint64(char const* str, const char* const end, bool* successful = nullptr, int base = 10) {
- if (successful != nullptr) *successful = false;
+ if (successful != nullptr) {
+ *successful = false;
+ }
// Base value should be between 2 and 36. If it's not, return 0 as an invalid case.
- if (str == nullptr || end <= str || base < 0 || base == 1 || base > 36)
+ if (str == nullptr || end <= str || base < 0 || base == 1 || base > 36) {
return 0;
+ }
// The result of the conversion will be stored in this variable.
uint64_t result = 0;
@@ -26,8 +29,10 @@ namespace OpenVic::StringUtils {
if (*str == '0') {
if (str + 1 != end && (str[1] == 'x' || str[1] == 'X')) {
base = 16; // Hexadecimal.
- str += 2; // Skip '0x' or '0X'
- if (str == end) return 0;
+ str += 2; // Skip '0x' or '0X'
+ if (str == end) {
+ return 0;
+ }
} else {
base = 8; // Octal.
}
@@ -38,7 +43,9 @@ namespace OpenVic::StringUtils {
// If base is 16 and string starts with '0x' or '0X', skip these characters.
if (*str == '0' && str + 1 != end && (str[1] == 'x' || str[1] == 'X')) {
str += 2;
- if (str == end) return 0;
+ if (str == end) {
+ return 0;
+ }
}
}
@@ -76,7 +83,9 @@ namespace OpenVic::StringUtils {
// If successful is not null and the entire string was parsed,
// set *successful to true (if not it is already false).
- if (successful != nullptr && str == end) *successful = true;
+ if (successful != nullptr && str == end) {
+ *successful = true;
+ }
return result;
}
@@ -90,29 +99,38 @@ namespace OpenVic::StringUtils {
}
constexpr int64_t string_to_int64(char const* str, const char* const end, bool* successful = nullptr, int base = 10) {
- if (successful != nullptr) *successful = false;
+ if (successful != nullptr) {
+ *successful = false;
+ }
- if (str == nullptr || end <= str) return 0;
+ if (str == nullptr || end <= str) {
+ return 0;
+ }
// This flag will be set if the number is negative.
bool is_negative = false;
// Check if there is a sign character.
if (*str == '+' || *str == '-') {
- if (*str == '-')
+ if (*str == '-') {
is_negative = true;
+ }
++str;
- if (str == end) return 0;
+ if (str == end) {
+ return 0;
+ }
}
const uint64_t result = string_to_uint64(str, end, successful, base);
if (!is_negative) {
- if (result >= std::numeric_limits<int64_t>::max())
+ if (result >= std::numeric_limits<int64_t>::max()) {
return std::numeric_limits<int64_t>::max();
+ }
return result;
} else {
- if (result > std::numeric_limits<int64_t>::max())
+ if (result > std::numeric_limits<int64_t>::max()) {
return std::numeric_limits<int64_t>::min();
+ }
return -result;
}
}