aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/types
diff options
context:
space:
mode:
author BrickPi <49528459+BrickPi@users.noreply.github.com>2023-10-25 12:16:05 +0200
committer GitHub <noreply@github.com>2023-10-25 12:16:05 +0200
commitfd1b24dfc6988eaa301645f0f5f2fcd845eb0a29 (patch)
treebd5fba638a55c683e587eb5e2bbde43ab5fb1a00 /src/openvic-simulation/types
parent7bda541557722b2a244e80796c612b735d8b5cf7 (diff)
parentc9c198e3b47e84eaea998cd9d2f7a8aa2b50ce73 (diff)
Merge pull request #60 from OpenVicProject/country-history-loading
Diffstat (limited to 'src/openvic-simulation/types')
-rw-r--r--src/openvic-simulation/types/Date.cpp30
-rw-r--r--src/openvic-simulation/types/Date.hpp6
2 files changed, 18 insertions, 18 deletions
diff --git a/src/openvic-simulation/types/Date.cpp b/src/openvic-simulation/types/Date.cpp
index f167b7b..6e21dfc 100644
--- a/src/openvic-simulation/types/Date.cpp
+++ b/src/openvic-simulation/types/Date.cpp
@@ -179,7 +179,7 @@ std::ostream& OpenVic::operator<<(std::ostream& out, Date const& date) {
}
// Parsed from string of the form YYYY.MM.DD
-Date Date::from_string(char const* const str, char const* const end, bool* successful) {
+Date Date::from_string(char const* const str, char const* const end, bool* successful, bool quiet) {
if (successful != nullptr) *successful = true;
year_t year = 0;
@@ -187,7 +187,7 @@ Date Date::from_string(char const* const str, char const* const end, bool* succe
day_t day = 1;
if (str == nullptr || end <= str) {
- Logger::error("Invalid string start/end pointers: ", static_cast<void const*>(str), " - ", static_cast<void const*>(end));
+ if (!quiet) Logger::error("Invalid string start/end pointers: ", static_cast<void const*>(str), " - ", static_cast<void const*>(end));
if (successful != nullptr) *successful = false;
return { year, month, day };
}
@@ -196,7 +196,7 @@ Date Date::from_string(char const* const str, char const* const end, bool* succe
while (std::isdigit(*year_end) && ++year_end < end);
if (year_end <= str) {
- Logger::error("Failed to find year digits in date: ", std::string_view { str, static_cast<size_t>(end - str) });
+ if (!quiet) Logger::error("Failed to find year digits in date: ", std::string_view { str, static_cast<size_t>(end - str) });
if (successful != nullptr) *successful = false;
return { year, month, day };
}
@@ -204,7 +204,7 @@ Date Date::from_string(char const* const str, char const* const end, bool* succe
bool sub_successful = false;
uint64_t val = StringUtils::string_to_uint64(str, year_end, &sub_successful, 10);
if (!sub_successful || val > std::numeric_limits<year_t>::max()) {
- Logger::error("Failed to read year: ", std::string_view { str, static_cast<size_t>(end - str) });
+ if (!quiet) Logger::error("Failed to read year: ", std::string_view { str, static_cast<size_t>(end - str) });
if (successful != nullptr) *successful = false;
return { year, month, day };
}
@@ -217,13 +217,13 @@ Date Date::from_string(char const* const str, char const* const end, bool* succe
while (std::isdigit(*month_end) && ++month_end < end);
}
if (month_start >= month_end) {
- Logger::error("Failed to find month digits in date: ", std::string_view { str, static_cast<size_t>(end - str) });
+ if (!quiet) Logger::error("Failed to find month digits in date: ", std::string_view { str, static_cast<size_t>(end - str) });
if (successful != nullptr) *successful = false;
} else {
sub_successful = false;
val = StringUtils::string_to_uint64(month_start, month_end, &sub_successful, 10);
if (!sub_successful || val < 1 || val > MONTHS_IN_YEAR) {
- Logger::error("Failed to read month: ", std::string_view { str, static_cast<size_t>(end - str) });
+ if (!quiet) Logger::error("Failed to read month: ", std::string_view { str, static_cast<size_t>(end - str) });
if (successful != nullptr) *successful = false;
} else {
month = val;
@@ -235,41 +235,41 @@ Date Date::from_string(char const* const str, char const* const end, bool* succe
while (std::isdigit(*day_end) && ++day_end < end);
}
if (day_start >= day_end) {
- Logger::error("Failed to find day digits in date: ", std::string_view { str, static_cast<size_t>(end - str) });
+ if (!quiet) Logger::error("Failed to find day digits in date: ", std::string_view { str, static_cast<size_t>(end - str) });
if (successful != nullptr) *successful = false;
} else {
sub_successful = false;
val = StringUtils::string_to_uint64(day_start, day_end, &sub_successful);
if (!sub_successful || val < 1 || val > DAYS_IN_MONTH[month - 1]) {
- Logger::error("Failed to read day: ", std::string_view { str, static_cast<size_t>(end - str) });
+ if (!quiet) Logger::error("Failed to read day: ", std::string_view { str, static_cast<size_t>(end - str) });
if (successful != nullptr) *successful = false;
} else {
day = val;
if (day_end < end) {
- Logger::error("Unexpected string \"", std::string_view { day_end, static_cast<size_t>(end - day_end) }, "\" at the end of date ", std::string_view { str, static_cast<size_t>(end - str) });
+ if (!quiet) Logger::error("Unexpected string \"", std::string_view { day_end, static_cast<size_t>(end - day_end) }, "\" at the end of date ", std::string_view { str, static_cast<size_t>(end - str) });
if (successful != nullptr) *successful = false;
}
}
}
} else {
- Logger::error("Unexpected character \"", *month_end, "\" in month of date ", std::string_view { str, static_cast<size_t>(end - str) });
+ if (!quiet) Logger::error("Unexpected character \"", *month_end, "\" in month of date ", std::string_view { str, static_cast<size_t>(end - str) });
if (successful != nullptr) *successful = false;
}
}
}
}
} else {
- Logger::error("Unexpected character \"", *year_end, "\" in year of date ", std::string_view { str, static_cast<size_t>(end - str) });
+ if (!quiet) Logger::error("Unexpected character \"", *year_end, "\" in year of date ", std::string_view { str, static_cast<size_t>(end - str) });
if (successful != nullptr) *successful = false;
}
}
return { year, month, day };
};
-Date Date::from_string(char const* str, size_t length, bool* successful) {
- return from_string(str, str + length, successful);
+Date Date::from_string(char const* str, size_t length, bool* successful, bool quiet) {
+ return from_string(str, str + length, successful, quiet);
}
-Date Date::from_string(std::string_view str, bool* successful) {
- return from_string(str.data(), str.length(), successful);
+Date Date::from_string(std::string_view str, bool* successful, bool quiet) {
+ return from_string(str.data(), str.length(), successful, quiet);
}
diff --git a/src/openvic-simulation/types/Date.hpp b/src/openvic-simulation/types/Date.hpp
index 718de80..0cc2587 100644
--- a/src/openvic-simulation/types/Date.hpp
+++ b/src/openvic-simulation/types/Date.hpp
@@ -92,9 +92,9 @@ namespace OpenVic {
std::string to_string() const;
explicit operator std::string() const;
// Parsed from string of the form YYYY.MM.DD
- static Date from_string(char const* str, char const* end, bool* successful = nullptr);
- static Date from_string(char const* str, size_t length, bool* successful = nullptr);
- static Date from_string(std::string_view str, bool* successful = nullptr);
+ static Date from_string(char const* str, char const* end, bool* successful = nullptr, bool quiet = false);
+ static Date from_string(char const* str, size_t length, bool* successful = nullptr, bool quiet = false);
+ static Date from_string(std::string_view str, bool* successful = nullptr, bool quiet = false);
};
std::ostream& operator<<(std::ostream& out, Date const& date);
}