aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/types
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-10-29 21:14:55 +0100
committer GitHub <noreply@github.com>2023-10-29 21:14:55 +0100
commit06cc0606156d009026930c785c62434276fbe782 (patch)
treed37fcb69766ec029ea4e3e2816c419f9d7e05f7c /src/openvic-simulation/types
parentd8ec90f07342876e9331819bd3cc372050f78248 (diff)
parent1b5e43fa7750cc4025d32f18390593cbce3ba842 (diff)
Merge pull request #67 from OpenVicProject/format
Formating
Diffstat (limited to 'src/openvic-simulation/types')
-rw-r--r--src/openvic-simulation/types/Colour.hpp4
-rw-r--r--src/openvic-simulation/types/Date.cpp207
-rw-r--r--src/openvic-simulation/types/IdentifierRegistry.cpp14
-rw-r--r--src/openvic-simulation/types/IdentifierRegistry.hpp97
-rw-r--r--src/openvic-simulation/types/Vector.cpp3
-rw-r--r--src/openvic-simulation/types/fixed_point/FixedPoint.hpp30
6 files changed, 256 insertions, 99 deletions
diff --git a/src/openvic-simulation/types/Colour.hpp b/src/openvic-simulation/types/Colour.hpp
index 15c574f..e516d5b 100644
--- a/src/openvic-simulation/types/Colour.hpp
+++ b/src/openvic-simulation/types/Colour.hpp
@@ -15,8 +15,8 @@ namespace OpenVic {
* When colour_t is used in a purely graphical context, NULL_COLOUR
* should be allowed.
*/
- static constexpr colour_t NULL_COLOUR = 0, FULL_COLOUR = 0xFF,
- MAX_COLOUR_RGB = 0xFFFFFF, MAX_COLOUR_ARGB = 0xFFFFFFFF;
+ static constexpr colour_t NULL_COLOUR = 0, FULL_COLOUR = 0xFF;
+ static constexpr colour_t MAX_COLOUR_RGB = 0xFFFFFF, MAX_COLOUR_ARGB = 0xFFFFFFFF;
constexpr colour_t float_to_colour_byte(float f, float min = 0.0f, float max = 1.0f) {
return static_cast<colour_t>(std::clamp(min + f * (max - min), min, max) * 255.0f);
diff --git a/src/openvic-simulation/types/Date.cpp b/src/openvic-simulation/types/Date.cpp
index 6e21dfc..8fbb859 100644
--- a/src/openvic-simulation/types/Date.cpp
+++ b/src/openvic-simulation/types/Date.cpp
@@ -12,20 +12,40 @@ using namespace OpenVic;
Timespan::Timespan(day_t value) : days { value } {}
-bool Timespan::operator<(Timespan other) const { return days < other.days; };
-bool Timespan::operator>(Timespan other) const { return days > other.days; };
-bool Timespan::operator<=(Timespan other) const { return days <= other.days; };
-bool Timespan::operator>=(Timespan other) const { return days >= other.days; };
-bool Timespan::operator==(Timespan other) const { return days == other.days; };
-bool Timespan::operator!=(Timespan other) const { return days != other.days; };
+bool Timespan::operator<(Timespan other) const {
+ return days < other.days;
+};
+bool Timespan::operator>(Timespan other) const {
+ return days > other.days;
+};
+bool Timespan::operator<=(Timespan other) const {
+ return days <= other.days;
+};
+bool Timespan::operator>=(Timespan other) const {
+ return days >= other.days;
+};
+bool Timespan::operator==(Timespan other) const {
+ return days == other.days;
+};
+bool Timespan::operator!=(Timespan other) const {
+ return days != other.days;
+};
-Timespan Timespan::operator+(Timespan other) const { return days + other.days; }
+Timespan Timespan::operator+(Timespan other) const {
+ return days + other.days;
+}
-Timespan Timespan::operator-(Timespan other) const { return days - other.days; }
+Timespan Timespan::operator-(Timespan other) const {
+ return days - other.days;
+}
-Timespan Timespan::operator*(day_t factor) const { return days * factor; }
+Timespan Timespan::operator*(day_t factor) const {
+ return days * factor;
+}
-Timespan Timespan::operator/(day_t factor) const { return days / factor; }
+Timespan Timespan::operator/(day_t factor) const {
+ return days / factor;
+}
Timespan& Timespan::operator+=(Timespan other) {
days += other.days;
@@ -65,16 +85,15 @@ Timespan::operator std::string() const {
}
Timespan Timespan::fromYears(day_t num) {
- return num * Date::DAYS_IN_YEAR;
+ return num * Date::DAYS_IN_YEAR;
}
Timespan Timespan::fromMonths(day_t num) {
- return (num / Date::MONTHS_IN_YEAR) * Date::DAYS_IN_YEAR +
- Date::DAYS_UP_TO_MONTH[num % Date::MONTHS_IN_YEAR];
+ return (num / Date::MONTHS_IN_YEAR) * Date::DAYS_IN_YEAR + Date::DAYS_UP_TO_MONTH[num % Date::MONTHS_IN_YEAR];
}
Timespan Timespan::fromDays(day_t num) {
- return num;
+ return num;
}
std::ostream& OpenVic::operator<<(std::ostream& out, Timespan const& timespan) {
@@ -92,8 +111,11 @@ Timespan::day_t const* Date::DAYS_UP_TO_MONTH = generate_days_up_to_month();
Timespan::day_t const* Date::generate_days_up_to_month() {
static Timespan::day_t days_up_to_month[MONTHS_IN_YEAR];
Timespan::day_t days = 0;
- for (int month = 0; month < MONTHS_IN_YEAR;
- days_up_to_month[month] = days, days += DAYS_IN_MONTH[month++]);
+ int month = 0;
+ while (month < MONTHS_IN_YEAR) {
+ days_up_to_month[month] = days;
+ days += DAYS_IN_MONTH[month++];
+ }
assert(days == DAYS_IN_YEAR);
return days_up_to_month;
}
@@ -103,9 +125,11 @@ Date::month_t const* Date::MONTH_FROM_DAY_IN_YEAR = generate_month_from_day_in_y
Date::month_t const* Date::generate_month_from_day_in_year() {
static month_t month_from_day_in_year[DAYS_IN_YEAR];
Timespan::day_t days_left = 0;
- for (int day = 0, month = 0; day < DAYS_IN_YEAR;
- days_left = (days_left > 0 ? days_left : DAYS_IN_MONTH[month++]) - 1,
- month_from_day_in_year[day++] = month);
+ int day = 0, month = 0;
+ while (day < DAYS_IN_YEAR) {
+ days_left = (days_left > 0 ? days_left : DAYS_IN_MONTH[month++]) - 1;
+ month_from_day_in_year[day++] = month;
+ }
assert(days_left == 0);
assert(month_from_day_in_year[DAYS_IN_YEAR - 1] == MONTHS_IN_YEAR);
return month_from_day_in_year;
@@ -132,16 +156,32 @@ Date::day_t Date::getDay() const {
return (static_cast<Timespan::day_t>(timespan) % DAYS_IN_YEAR) - DAYS_UP_TO_MONTH[getMonth() - 1] + 1;
}
-bool Date::operator<(Date other) const { return timespan < other.timespan; };
-bool Date::operator>(Date other) const { return timespan > other.timespan; };
-bool Date::operator<=(Date other) const { return timespan <= other.timespan; };
-bool Date::operator>=(Date other) const { return timespan >= other.timespan; };
-bool Date::operator==(Date other) const { return timespan == other.timespan; };
-bool Date::operator!=(Date other) const { return timespan != other.timespan; };
+bool Date::operator<(Date other) const {
+ return timespan < other.timespan;
+};
+bool Date::operator>(Date other) const {
+ return timespan > other.timespan;
+};
+bool Date::operator<=(Date other) const {
+ return timespan <= other.timespan;
+};
+bool Date::operator>=(Date other) const {
+ return timespan >= other.timespan;
+};
+bool Date::operator==(Date other) const {
+ return timespan == other.timespan;
+};
+bool Date::operator!=(Date other) const {
+ return timespan != other.timespan;
+};
-Date Date::operator+(Timespan other) const { return timespan + other; }
+Date Date::operator+(Timespan other) const {
+ return timespan + other;
+}
-Timespan Date::operator-(Date other) const { return timespan - other.timespan; }
+Timespan Date::operator-(Date other) const {
+ return timespan - other.timespan;
+}
Date& Date::operator+=(Timespan other) {
timespan += other;
@@ -175,37 +215,54 @@ Date::operator std::string() const {
}
std::ostream& OpenVic::operator<<(std::ostream& out, Date const& date) {
- return out << static_cast<int>(date.getYear()) << Date::SEPARATOR_CHARACTER << static_cast<int>(date.getMonth()) << Date::SEPARATOR_CHARACTER << static_cast<int>(date.getDay());
+ return out << static_cast<int>(date.getYear()) << Date::SEPARATOR_CHARACTER << static_cast<int>(date.getMonth())
+ << Date::SEPARATOR_CHARACTER << static_cast<int>(date.getDay());
}
// Parsed from string of the form YYYY.MM.DD
Date Date::from_string(char const* const str, char const* const end, bool* successful, bool quiet) {
- if (successful != nullptr) *successful = true;
+ if (successful != nullptr) {
+ *successful = true;
+ }
year_t year = 0;
month_t month = 1;
day_t day = 1;
if (str == nullptr || end <= str) {
- if (!quiet) Logger::error("Invalid string start/end pointers: ", static_cast<void const*>(str), " - ", static_cast<void const*>(end));
- if (successful != nullptr) *successful = false;
+ 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 };
}
char const* year_end = str;
- while (std::isdigit(*year_end) && ++year_end < end);
+ while (std::isdigit(*year_end) && ++year_end < end) {}
if (year_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;
+ 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 };
}
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()) {
- if (!quiet) Logger::error("Failed to read year: ", std::string_view { str, static_cast<size_t>(end - str) });
- if (successful != nullptr) *successful = false;
+ 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 };
}
year = val;
@@ -214,17 +271,27 @@ Date Date::from_string(char const* const str, char const* const end, bool* succe
char const* const month_start = year_end + 1;
char const* month_end = month_start;
if (month_start < end) {
- while (std::isdigit(*month_end) && ++month_end < end);
+ while (std::isdigit(*month_end) && ++month_end < end) {}
}
if (month_start >= month_end) {
- 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;
+ 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) {
- if (!quiet) Logger::error("Failed to read month: ", std::string_view { str, static_cast<size_t>(end - str) });
- if (successful != nullptr) *successful = false;
+ 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;
if (month_end < end) {
@@ -232,35 +299,71 @@ Date Date::from_string(char const* const str, char const* const end, bool* succe
char const* const day_start = month_end + 1;
char const* day_end = day_start;
if (day_start < end) {
- while (std::isdigit(*day_end) && ++day_end < end);
+ while (std::isdigit(*day_end) && ++day_end < end) {}
}
if (day_start >= day_end) {
- 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;
+ 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]) {
- if (!quiet) Logger::error("Failed to read day: ", std::string_view { str, static_cast<size_t>(end - str) });
- if (successful != nullptr) *successful = false;
+ 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) {
- 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;
+ 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 {
- 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;
+ 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 {
- 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;
+ 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 };
diff --git a/src/openvic-simulation/types/IdentifierRegistry.cpp b/src/openvic-simulation/types/IdentifierRegistry.cpp
index f92750b..faddd75 100644
--- a/src/openvic-simulation/types/IdentifierRegistry.cpp
+++ b/src/openvic-simulation/types/IdentifierRegistry.cpp
@@ -4,8 +4,7 @@
using namespace OpenVic;
-HasIdentifier::HasIdentifier(std::string_view new_identifier)
- : identifier { new_identifier } {
+HasIdentifier::HasIdentifier(std::string_view new_identifier) : identifier { new_identifier } {
assert(!identifier.empty());
}
@@ -25,13 +24,14 @@ HasColour::HasColour(colour_t const new_colour, bool can_be_null, bool can_have_
assert((can_be_null || colour != NULL_COLOUR) && colour <= (!can_have_alpha ? MAX_COLOUR_RGB : MAX_COLOUR_ARGB));
}
-colour_t HasColour::get_colour() const { return colour; }
+colour_t HasColour::get_colour() const {
+ return colour;
+}
std::string HasColour::colour_to_hex_string() const {
return OpenVic::colour_to_hex_string(colour);
}
-HasIdentifierAndColour::HasIdentifierAndColour(std::string_view new_identifier,
- const colour_t new_colour, bool can_be_null, bool can_have_alpha)
- : HasIdentifier { new_identifier },
- HasColour { new_colour, can_be_null, can_have_alpha } {}
+HasIdentifierAndColour::HasIdentifierAndColour(
+ std::string_view new_identifier, const colour_t new_colour, bool can_be_null, bool can_have_alpha
+) : HasIdentifier { new_identifier }, HasColour { new_colour, can_be_null, can_have_alpha } {}
diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp
index f53d78b..bcb8e33 100644
--- a/src/openvic-simulation/types/IdentifierRegistry.hpp
+++ b/src/openvic-simulation/types/IdentifierRegistry.hpp
@@ -9,8 +9,12 @@
#include "openvic-simulation/utility/Logger.hpp"
#define REF_GETTERS(var) \
- constexpr decltype(var)& get_##var() { return var; } \
- constexpr decltype(var) const& get_##var() const { return var; }
+ constexpr decltype(var)& get_##var() { \
+ return var; \
+ } \
+ constexpr decltype(var) const& get_##var() const { \
+ return var; \
+ }
namespace OpenVic {
/*
@@ -45,10 +49,10 @@ namespace OpenVic {
#define HASID_PROPERTY(NAME) \
const NAME; \
-\
public: \
- auto get_##NAME() const->decltype(get_property(NAME)) { return get_property(NAME); } \
-\
+ auto get_##NAME() const->decltype(get_property(NAME)) { \
+ return get_property(NAME); \
+ } \
private:
};
@@ -80,7 +84,9 @@ private:
*/
class HasIdentifierAndColour : public HasIdentifier, public HasColour {
protected:
- HasIdentifierAndColour(std::string_view new_identifier, const colour_t new_colour, bool can_be_null, bool can_have_alpha);
+ HasIdentifierAndColour(
+ std::string_view new_identifier, const colour_t new_colour, bool can_be_null, bool can_have_alpha
+ );
public:
HasIdentifierAndColour(HasIdentifierAndColour const&) = delete;
@@ -97,9 +103,7 @@ private:
constexpr auto pred = [](typename decimal_map_t<T>::value_type a, typename decimal_map_t<T>::value_type b) -> bool {
return a.second < b.second;
};
- const typename decimal_map_t<T>::const_iterator result = std::max_element(
- map.begin(), map.end(), pred
- );
+ const typename decimal_map_t<T>::const_iterator result = std::max_element(map.begin(), map.end(), pred);
if (result != map.end()) {
return *result;
} else {
@@ -111,11 +115,17 @@ private:
/* Callbacks for trying to add duplicate keys via UniqueKeyRegistry::add_item */
static bool duplicate_fail_callback(std::string_view registry_name, std::string_view duplicate_identifier) {
- Logger::error("Failure adding item to the ", registry_name, " registry - an item with the identifier \"", duplicate_identifier, "\" already exists!");
+ Logger::error(
+ "Failure adding item to the ", registry_name, " registry - an item with the identifier \"", duplicate_identifier,
+ "\" already exists!"
+ );
return false;
}
static bool duplicate_warning_callback(std::string_view registry_name, std::string_view duplicate_identifier) {
- Logger::warning("Warning adding item to the ", registry_name, " registry - an item with the identifier \"", duplicate_identifier, "\" already exists!");
+ Logger::warning(
+ "Warning adding item to the ", registry_name, " registry - an item with the identifier \"", duplicate_identifier,
+ "\" already exists!"
+ );
return true;
}
static bool duplicate_ignore_callback(std::string_view registry_name, std::string_view duplicate_identifier) {
@@ -141,14 +151,19 @@ private:
using value_type = _Type;
using storage_type = _Storage;
- UniqueKeyRegistry(std::string_view new_name, bool new_log_lock = true, _GetIdentifier new_GetIdentifier = {}, _GetPointer new_GetPointer = {})
- : name { new_name }, log_lock { new_log_lock }, GetIdentifier { new_GetIdentifier }, GetPointer { new_GetPointer } {}
+ UniqueKeyRegistry(
+ std::string_view new_name, bool new_log_lock = true, _GetIdentifier new_GetIdentifier = {},
+ _GetPointer new_GetPointer = {}
+ ) : name { new_name }, log_lock { new_log_lock }, GetIdentifier { new_GetIdentifier }, GetPointer { new_GetPointer } {}
std::string_view get_name() const {
return name;
}
- bool add_item(storage_type&& item, NodeTools::callback_t<std::string_view, std::string_view> duplicate_callback = duplicate_fail_callback) {
+ bool add_item(
+ storage_type&& item,
+ NodeTools::callback_t<std::string_view, std::string_view> duplicate_callback = duplicate_fail_callback
+ ) {
if (locked) {
Logger::error("Cannot add item to the ", name, " registry - locked!");
return false;
@@ -156,7 +171,9 @@ private:
const std::string_view new_identifier = GetIdentifier(GetPointer(item));
if (duplicate_callback &&
duplicate_callback.target<bool(std::string_view, std::string_view)>() == duplicate_ignore_callback) {
- if (has_identifier(new_identifier)) return true;
+ if (has_identifier(new_identifier)) {
+ return true;
+ }
} else {
value_type const* old_item = get_item_by_identifier(new_identifier);
if (old_item != nullptr) {
@@ -173,7 +190,9 @@ private:
Logger::error("Failed to lock ", name, " registry - already locked!");
} else {
locked = true;
- if (log_lock) Logger::info("Locked ", name, " registry after registering ", size(), " items");
+ if (log_lock) {
+ Logger::info("Locked ", name, " registry after registering ", size(), " items");
+ }
}
}
@@ -206,7 +225,9 @@ private:
#define GETTERS \
value_type _const* get_item_by_identifier(std::string_view identifier) _const { \
const typename decltype(identifier_index_map)::const_iterator it = identifier_index_map.find(identifier); \
- if (it != identifier_index_map.end()) return GetPointer(items[it->second]); \
+ if (it != identifier_index_map.end()) { \
+ return GetPointer(items[it->second]); \
+ } \
return nullptr; \
} \
value_type _const* get_item_by_index(size_t index) _const { \
@@ -215,7 +236,9 @@ private:
NodeTools::callback_t<std::string_view> expect_item_str(NodeTools::callback_t<value_type _const&> callback) _const { \
return [this, callback](std::string_view identifier) -> bool { \
value_type _const* item = get_item_by_identifier(identifier); \
- if (item != nullptr) return callback(*item); \
+ if (item != nullptr) { \
+ return callback(*item); \
+ } \
Logger::error("Invalid ", name, ": ", identifier); \
return false; \
}; \
@@ -223,7 +246,8 @@ private:
NodeTools::node_callback_t expect_item_identifier(NodeTools::callback_t<value_type _const&> callback) _const { \
return NodeTools::expect_identifier(expect_item_str(callback)); \
} \
- NodeTools::node_callback_t expect_item_dictionary(NodeTools::callback_t<value_type _const&, ast::NodeCPtr> callback) _const { \
+ NodeTools::node_callback_t expect_item_dictionary(NodeTools::callback_t<value_type _const&, ast::NodeCPtr> callback) \
+ _const { \
return NodeTools::expect_dictionary([this, callback](std::string_view key, ast::NodeCPtr value) -> bool { \
return expect_item_str(std::bind(callback, std::placeholders::_1, value))(key); \
}); \
@@ -256,7 +280,8 @@ private:
return identifiers;
}
- NodeTools::node_callback_t expect_item_decimal_map(NodeTools::callback_t<decimal_map_t<value_type const*>&&> callback) const {
+ NodeTools::node_callback_t expect_item_decimal_map(NodeTools::callback_t<decimal_map_t<value_type const*>&&> callback)
+ const {
return [this, callback](ast::NodeCPtr node) -> bool {
decimal_map_t<value_type const*> map;
bool ret = expect_item_dictionary([&map](value_type const& key, ast::NodeCPtr value) -> bool {
@@ -314,8 +339,12 @@ private:
using IdentifierInstanceRegistry = InstanceRegistry<_Type, _get_identifier<_Type>>;
#define IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(singular, plural) \
- void lock_##plural() { plural.lock(); } \
- bool plural##_are_locked() const { return plural.is_locked(); } \
+ void lock_##plural() { \
+ plural.lock(); \
+ } \
+ bool plural##_are_locked() const { \
+ return plural.is_locked(); \
+ } \
decltype(plural)::value_type const* get_##singular##_by_identifier(std::string_view identifier) const { \
return plural.get_item_by_identifier(identifier); \
} \
@@ -331,16 +360,24 @@ private:
std::vector<std::string_view> get_##singular##_identifiers() const { \
return plural.get_item_identifiers(); \
} \
- NodeTools::callback_t<std::string_view> expect_##singular##_str(NodeTools::callback_t<decltype(plural)::value_type const&> callback) const { \
+ NodeTools::callback_t<std::string_view> expect_##singular##_str( \
+ NodeTools::callback_t<decltype(plural)::value_type const&> callback \
+ ) const { \
return plural.expect_item_str(callback); \
} \
- NodeTools::node_callback_t expect_##singular##_identifier(NodeTools::callback_t<decltype(plural)::value_type const&> callback) const { \
+ NodeTools::node_callback_t expect_##singular##_identifier( \
+ NodeTools::callback_t<decltype(plural)::value_type const&> callback \
+ ) const { \
return plural.expect_item_identifier(callback); \
} \
- NodeTools::node_callback_t expect_##singular##_dictionary(NodeTools::callback_t<decltype(plural)::value_type const&, ast::NodeCPtr> callback) const { \
+ NodeTools::node_callback_t expect_##singular##_dictionary( \
+ NodeTools::callback_t<decltype(plural)::value_type const&, ast::NodeCPtr> callback \
+ ) const { \
return plural.expect_item_dictionary(callback); \
} \
- NodeTools::node_callback_t expect_##singular##_decimal_map(NodeTools::callback_t<decimal_map_t<decltype(plural)::value_type const*>&&> callback) const { \
+ NodeTools::node_callback_t expect_##singular##_decimal_map( \
+ NodeTools::callback_t<decimal_map_t<decltype(plural)::value_type const*>&&> callback \
+ ) const { \
return plural.expect_item_decimal_map(callback); \
}
@@ -348,13 +385,17 @@ private:
decltype(plural)::value_type* get_##singular##_by_identifier(std::string_view identifier) { \
return plural.get_item_by_identifier(identifier); \
} \
- NodeTools::callback_t<std::string_view> expect_##singular##_str(NodeTools::callback_t<decltype(plural)::value_type&> callback) { \
+ NodeTools::callback_t<std::string_view> expect_##singular##_str( \
+ NodeTools::callback_t<decltype(plural)::value_type&> callback \
+ ) { \
return plural.expect_item_str(callback); \
} \
NodeTools::node_callback_t expect_##singular##_identifier(NodeTools::callback_t<decltype(plural)::value_type&> callback) { \
return plural.expect_item_identifier(callback); \
} \
- NodeTools::node_callback_t expect_##singular##_dictionary(NodeTools::callback_t<decltype(plural)::value_type&, ast::NodeCPtr> callback) { \
+ NodeTools::node_callback_t expect_##singular##_dictionary( \
+ NodeTools::callback_t<decltype(plural)::value_type&, ast::NodeCPtr> callback \
+ ) { \
return plural.expect_item_dictionary(callback); \
}
diff --git a/src/openvic-simulation/types/Vector.cpp b/src/openvic-simulation/types/Vector.cpp
index 10d2dd2..28f30bf 100644
--- a/src/openvic-simulation/types/Vector.cpp
+++ b/src/openvic-simulation/types/Vector.cpp
@@ -8,10 +8,9 @@ constexpr vec2_t<T>::vec2_t(T new_val) : x { new_val }, y { new_val } {}
template<typename T>
constexpr vec2_t<T>::vec2_t(T new_x, T new_y) : x { new_x }, y { new_y } {}
-
template<typename T>
constexpr vec2_t<T> vec2_t<T>::abs() const {
- return { };
+ return {};
}
template<typename T>
diff --git a/src/openvic-simulation/types/fixed_point/FixedPoint.hpp b/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
index 649d3f6..4bf5716 100644
--- a/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
+++ b/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
@@ -253,7 +253,9 @@ namespace OpenVic {
}
val += err;
}
- if (val.is_negative()) stream << "-";
+ if (val.is_negative()) {
+ stream << "-";
+ }
val = val.abs();
stream << val.to_int64_t() << ".";
val = val.get_frac();
@@ -283,7 +285,9 @@ namespace OpenVic {
// Deterministic
static constexpr fixed_point_t parse(char const* str, char const* const end, bool* successful = nullptr) {
- if (successful != nullptr) *successful = false;
+ if (successful != nullptr) {
+ *successful = false;
+ }
if (str == nullptr || str >= end) {
return _0();
@@ -294,11 +298,13 @@ namespace OpenVic {
if (*str == '-') {
negative = true;
++str;
- if (str == end) return _0();
+ if (str == end) {
+ return _0();
+ }
}
char const* dot_pointer = str;
- while (*dot_pointer != '.' && ++dot_pointer != end);
+ while (*dot_pointer != '.' && ++dot_pointer != end) {}
if (dot_pointer == str && dot_pointer + 1 == end) {
// Invalid: ".", "+." or "-."
@@ -306,20 +312,26 @@ namespace OpenVic {
}
fixed_point_t result = _0();
- if (successful != nullptr) *successful = true;
+ if (successful != nullptr) {
+ *successful = true;
+ }
if (dot_pointer != str) {
// Non-empty integer part
bool int_successful = false;
result += parse_integer(str, dot_pointer, &int_successful);
- if (!int_successful && successful != nullptr) *successful = false;
+ if (!int_successful && successful != nullptr) {
+ *successful = false;
+ }
}
if (dot_pointer + 1 < end) {
// Non-empty fractional part
bool frac_successful = false;
result += parse_fraction(dot_pointer + 1, end, &frac_successful);
- if (!frac_successful && successful != nullptr) *successful = false;
+ if (!frac_successful && successful != nullptr) {
+ *successful = false;
+ }
}
return negative ? -result : result;
@@ -599,7 +611,9 @@ namespace OpenVic {
static constexpr fixed_point_t parse_fraction(char const* str, char const* end, bool* successful) {
char const* const read_end = str + PRECISION;
- if (read_end < end) end = read_end;
+ if (read_end < end) {
+ end = read_end;
+ }
uint64_t parsed_value = StringUtils::string_to_uint64(str, end, successful, 10);
while (end++ < read_end) {
parsed_value *= 10;