aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp8
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp30
-rw-r--r--src/openvic-simulation/history/DiplomaticHistory.cpp46
-rw-r--r--src/openvic-simulation/history/Period.cpp2
-rw-r--r--src/openvic-simulation/map/Map.cpp2
-rw-r--r--src/openvic-simulation/military/Deployment.cpp2
-rw-r--r--src/openvic-simulation/misc/Define.cpp4
-rw-r--r--src/openvic-simulation/scripts/Condition.cpp2
-rw-r--r--src/openvic-simulation/types/Colour.hpp6
-rw-r--r--src/openvic-simulation/types/Date.hpp12
-rw-r--r--src/openvic-simulation/types/IdentifierRegistry.hpp40
-rw-r--r--src/openvic-simulation/types/Vector.hpp3
-rw-r--r--src/openvic-simulation/types/fixed_point/FixedPoint.hpp13
-rw-r--r--src/openvic-simulation/types/fixed_point/FixedPointLUT.hpp7
-rw-r--r--src/openvic-simulation/types/fixed_point/FixedPointMath.hpp2
-rw-r--r--src/openvic-simulation/utility/Getters.hpp16
-rw-r--r--src/openvic-simulation/utility/Logger.hpp25
17 files changed, 124 insertions, 96 deletions
diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp
index 7ab0dbe..297937a 100644
--- a/src/openvic-simulation/dataloader/NodeTools.cpp
+++ b/src/openvic-simulation/dataloader/NodeTools.cpp
@@ -169,6 +169,14 @@ node_callback_t NodeTools::expect_date(callback_t<Date> callback) {
return expect_identifier(expect_date_str(callback));
}
+node_callback_t NodeTools::expect_date_string(callback_t<Date> callback) {
+ return expect_string(expect_date_str(callback));
+}
+
+node_callback_t NodeTools::expect_date_identifier_or_string(callback_t<Date> callback) {
+ return expect_identifier_or_string(expect_date_str(callback));
+}
+
node_callback_t NodeTools::expect_years(callback_t<Timespan> callback) {
return expect_uint<Timespan::day_t>([callback](Timespan::day_t val) -> bool {
return callback(Timespan::from_years(val));
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index 54b61d0..c41c09e 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -119,6 +119,8 @@ namespace OpenVic {
callback_t<std::string_view> expect_date_str(callback_t<Date> callback);
node_callback_t expect_date(callback_t<Date> callback);
+ node_callback_t expect_date_string(callback_t<Date> callback);
+ node_callback_t expect_date_identifier_or_string(callback_t<Date> callback);
node_callback_t expect_years(callback_t<Timespan> callback);
node_callback_t expect_months(callback_t<Timespan> callback);
node_callback_t expect_days(callback_t<Timespan> callback);
@@ -371,15 +373,15 @@ namespace OpenVic {
template<typename T, StringMapCase Case>
Callback<std::string_view> auto expect_mapped_string(
- template_string_map_t<T, Case> const& map, Callback<T> auto callback
+ template_string_map_t<T, Case> const& map, Callback<T> auto callback, bool warn = false
) {
- return [&map, callback](std::string_view string) -> bool {
+ return [&map, callback, warn](std::string_view string) -> bool {
const typename template_string_map_t<T, Case>::const_iterator it = map.find(string);
if (it != map.end()) {
return callback(it->second);
}
- Logger::error("String not found in map: ", string);
- return false;
+ Logger::warn_or_error(warn, "String not found in map: ", string);
+ return warn;
};
}
@@ -470,24 +472,14 @@ namespace OpenVic {
};
}
- template<typename... Args>
- bool warn_or_error(bool warn, Args&&... args) {
- if (warn) {
- Logger::warning(std::forward<Args>(args)...);
- return true;
- } else {
- Logger::error(std::forward<Args>(args)...);
- return false;
- }
- }
-
template<typename T, typename U, typename... SetArgs>
Callback<T> auto set_callback(tsl::ordered_set<U, SetArgs...>& set, bool warn = false) {
return [&set, warn](T val) -> bool {
if (set.emplace(std::move(val)).second) {
return true;
}
- return warn_or_error(warn, "Duplicate set entry: \"", val, "\"");
+ Logger::warn_or_error(warn, "Duplicate set entry: \"", val, "\"");
+ return warn;
};
}
@@ -497,7 +489,8 @@ namespace OpenVic {
if (set.emplace(&val).second) {
return true;
}
- return warn_or_error(warn, "Duplicate set entry: \"", &val, "\"");
+ Logger::warn_or_error(warn, "Duplicate set entry: \"", &val, "\"");
+ return warn;
};
}
@@ -509,7 +502,8 @@ namespace OpenVic {
if (map.emplace(key, std::move(value)).second) {
return true;
}
- return warn_or_error(warn, "Duplicate map entry with key: \"", key, "\"");
+ Logger::warn_or_error(warn, "Duplicate map entry with key: \"", key, "\"");
+ return warn;
};
}
}
diff --git a/src/openvic-simulation/history/DiplomaticHistory.cpp b/src/openvic-simulation/history/DiplomaticHistory.cpp
index 55d6d6b..22ee765 100644
--- a/src/openvic-simulation/history/DiplomaticHistory.cpp
+++ b/src/openvic-simulation/history/DiplomaticHistory.cpp
@@ -32,20 +32,20 @@ AllianceHistory::AllianceHistory(
Country const* new_first,
Country const* new_second,
const Period new_period
-) : first { new_first }, second { new_second }, period {new_period} {}
+) : first { new_first }, second { new_second }, period { new_period } {}
ReparationsHistory::ReparationsHistory(
Country const* new_receiver,
Country const* new_sender,
const Period new_period
-) : receiver { new_receiver }, sender { new_sender }, period {new_period} {}
+) : receiver { new_receiver }, sender { new_sender }, period { new_period } {}
SubjectHistory::SubjectHistory(
Country const* new_overlord,
Country const* new_subject,
const type_t new_type,
const Period new_period
-) : overlord { new_overlord }, subject { new_subject }, type { new_type }, period {new_period} {}
+) : overlord { new_overlord }, subject { new_subject }, type { new_type }, period { new_period } {}
void DiplomaticHistoryManager::reserve_more_wars(size_t size) {
if (locked) {
@@ -115,10 +115,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, expect_identifier_or_string(country_manager.expect_country_str(assign_variable_callback_pointer(first))),
- "second", ONE_EXACTLY, expect_identifier_or_string(country_manager.expect_country_str(assign_variable_callback_pointer(second))),
- "start_date", ONE_EXACTLY, expect_identifier_or_string(expect_date_str(assign_variable_callback(start))),
- "end_date", ZERO_OR_ONE, expect_identifier_or_string(expect_date_str(assign_variable_callback(end)))
+ "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(first)),
+ "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(second)),
+ "start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
+ "end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
alliances.push_back({ first, second, { start, end } });
@@ -131,10 +131,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, expect_identifier_or_string(country_manager.expect_country_str(assign_variable_callback_pointer(overlord))),
- "second", ONE_EXACTLY, expect_identifier_or_string(country_manager.expect_country_str(assign_variable_callback_pointer(subject))),
- "start_date", ONE_EXACTLY, expect_identifier_or_string(expect_date_str(assign_variable_callback(start))),
- "end_date", ZERO_OR_ONE, expect_identifier_or_string(expect_date_str(assign_variable_callback(end)))
+ "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
+ "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
+ "start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
+ "end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
subjects.push_back({ overlord, subject, SubjectHistory::type_t::VASSAL, { start, end } });
@@ -147,10 +147,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier(assign_variable_callback_pointer(overlord)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier(assign_variable_callback_pointer(subject)),
- "start_date", ONE_EXACTLY, expect_date(assign_variable_callback(start)),
- "end_date", ZERO_OR_ONE, expect_date(assign_variable_callback(end))
+ "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
+ "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
+ "start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
+ "end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
subjects.push_back({ overlord, subject, SubjectHistory::type_t::UNION, { start, end } });
@@ -163,10 +163,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier(assign_variable_callback_pointer(overlord)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier(assign_variable_callback_pointer(subject)),
- "start_date", ONE_EXACTLY, expect_date(assign_variable_callback(start)),
- "end_date", ZERO_OR_ONE, expect_date(assign_variable_callback(end))
+ "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
+ "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
+ "start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
+ "end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
subjects.push_back({ overlord, subject, SubjectHistory::type_t::SUBSTATE, { start, end } });
@@ -179,10 +179,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier(assign_variable_callback_pointer(receiver)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier(assign_variable_callback_pointer(sender)),
- "start_date", ONE_EXACTLY, expect_date(assign_variable_callback(start)),
- "end_date", ZERO_OR_ONE, expect_date(assign_variable_callback(end))
+ "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(receiver)),
+ "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(sender)),
+ "start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
+ "end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
reparations.push_back({ receiver, sender, { start, end } });
diff --git a/src/openvic-simulation/history/Period.cpp b/src/openvic-simulation/history/Period.cpp
index cb133dd..37758a1 100644
--- a/src/openvic-simulation/history/Period.cpp
+++ b/src/openvic-simulation/history/Period.cpp
@@ -5,7 +5,7 @@ using namespace OpenVic;
Period::Period(
const Date new_start_date,
const std::optional<Date> new_end_date
-) : start_date {new_start_date}, end_date {new_end_date} {}
+) : start_date { new_start_date }, end_date { new_end_date } {}
bool Period::is_date_in_period(const Date date) const {
return start_date <= date && (!end_date.has_value() || end_date.value() >= date);
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp
index 9a97143..a5cd6a6 100644
--- a/src/openvic-simulation/map/Map.cpp
+++ b/src/openvic-simulation/map/Map.cpp
@@ -80,7 +80,7 @@ Province::distance_t Map::calculate_distance_between(Province const& from, Provi
)
);
- return fvec2_t { min_x, to_pos.y - from_pos.y}.length_squared().sqrt();
+ return fvec2_t { min_x, to_pos.y - from_pos.y }.length_squared().sqrt();
}
using adjacency_t = Province::adjacency_t;
diff --git a/src/openvic-simulation/military/Deployment.cpp b/src/openvic-simulation/military/Deployment.cpp
index 14640ec..4e2693d 100644
--- a/src/openvic-simulation/military/Deployment.cpp
+++ b/src/openvic-simulation/military/Deployment.cpp
@@ -80,7 +80,7 @@ bool DeploymentManager::load_oob_file(
bool ret = expect_dictionary_keys(
"name", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(leader_name)),
- "date", ONE_EXACTLY, expect_identifier_or_string(expect_date_str(assign_variable_callback(leader_date))),
+ "date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(leader_date)),
"type", ONE_EXACTLY, UnitManager::expect_branch_identifier(assign_variable_callback(leader_branch)),
"personality", ONE_EXACTLY,
game_manager.get_military_manager().get_leader_trait_manager().expect_leader_trait_identifier_or_string(
diff --git a/src/openvic-simulation/misc/Define.cpp b/src/openvic-simulation/misc/Define.cpp
index e4e6b52..9ec5d49 100644
--- a/src/openvic-simulation/misc/Define.cpp
+++ b/src/openvic-simulation/misc/Define.cpp
@@ -95,9 +95,7 @@ bool DefineManager::load_defines_file(ast::NodeCPtr root) {
} else if (key == "start_date" || key == "end_date") {
- return expect_identifier_or_string(expect_date_str(
- std::bind_front(&DefineManager::add_date_define, this, key)
- ))(value);
+ return expect_date_identifier_or_string(std::bind_front(&DefineManager::add_date_define, this, key))(value);
} else {
return false;
diff --git a/src/openvic-simulation/scripts/Condition.cpp b/src/openvic-simulation/scripts/Condition.cpp
index 045649b..aab8d93 100644
--- a/src/openvic-simulation/scripts/Condition.cpp
+++ b/src/openvic-simulation/scripts/Condition.cpp
@@ -620,7 +620,7 @@ node_callback_t ConditionManager::expect_condition_node(
} else if (identifier == "relation") {
expect_pair("who", "value"); // { who = [tag/this/from] value = x }
} else if (identifier == "unemployment_by_type") {
- expect_pair("type", "value"); // {type = [poptype] value = x }
+ expect_pair("type", "value"); // { type = [poptype] value = x }
} else if (identifier == "upper_house") {
expect_pair("ideology", "value"); // { ideology = name value = 0.x }
} else if (identifier == "work_available") {
diff --git a/src/openvic-simulation/types/Colour.hpp b/src/openvic-simulation/types/Colour.hpp
index 06a6b36..304d9de 100644
--- a/src/openvic-simulation/types/Colour.hpp
+++ b/src/openvic-simulation/types/Colour.hpp
@@ -12,7 +12,6 @@
#include <type_traits>
#include <utility>
-#include "openvic-simulation/utility/Getters.hpp"
#include "openvic-simulation/utility/Utility.hpp"
namespace OpenVic {
@@ -105,7 +104,10 @@ namespace OpenVic {
/* Colour represented by an unsigned integer, either 24-bit RGB or 32-bit ARGB. */
template<typename ValueT, typename ColourIntT, typename ColourTraits = colour_traits<ValueT, ColourIntT>>
- struct basic_colour_t : ReturnByValueProperty {
+ struct basic_colour_t {
+ /* PROPERTY generated getter functions will return colours by value, rather than const reference. */
+ using ov_return_by_value = void;
+
using colour_traits = ColourTraits;
using value_type = typename colour_traits::value_type;
using integer_type = typename colour_traits::integer_type;
diff --git a/src/openvic-simulation/types/Date.hpp b/src/openvic-simulation/types/Date.hpp
index 9178e6e..9376293 100644
--- a/src/openvic-simulation/types/Date.hpp
+++ b/src/openvic-simulation/types/Date.hpp
@@ -1,16 +1,19 @@
#pragma once
#include <algorithm>
+#include <array>
#include <cstdint>
#include <ostream>
#include <string>
-#include "openvic-simulation/utility/Getters.hpp"
#include "openvic-simulation/utility/Utility.hpp"
namespace OpenVic {
// A relative period between points in time, measured in days
- struct Timespan : ReturnByValueProperty {
+ struct Timespan {
+ /* PROPERTY generated getter functions will return timespans by value, rather than const reference. */
+ using ov_return_by_value = void;
+
using day_t = int64_t;
private:
@@ -86,7 +89,10 @@ namespace OpenVic {
// Represents an in-game date
// Note: Current implementation does not account for leap-years, or dates before Year 0
- struct Date : ReturnByValueProperty {
+ struct Date {
+ /* PROPERTY generated getter functions will return dates by value, rather than const reference. */
+ using ov_return_by_value = void;
+
using year_t = uint16_t;
using month_t = uint8_t;
using day_t = uint8_t;
diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp
index 7e6fdb3..f1edc95 100644
--- a/src/openvic-simulation/types/IdentifierRegistry.hpp
+++ b/src/openvic-simulation/types/IdentifierRegistry.hpp
@@ -269,30 +269,39 @@ namespace OpenVic {
} \
} \
constexpr NodeTools::Callback<std::string_view> auto expect_item_str( \
- NodeTools::Callback<external_value_type CONST&> auto callback, bool warn \
+ NodeTools::Callback<external_value_type CONST&> auto callback, bool allow_empty, bool warn \
) CONST { \
- return [this, callback, warn](std::string_view identifier) -> bool { \
+ return [this, callback, allow_empty, warn](std::string_view identifier) -> bool { \
+ if (identifier.empty()) { \
+ if (allow_empty) { \
+ return true; \
+ } else { \
+ Logger::warn_or_error(warn, "Invalid ", name, " identifier: empty!"); \
+ return warn; \
+ } \
+ } \
external_value_type CONST* item = get_item_by_identifier(identifier); \
if (item != nullptr) { \
return callback(*item); \
} \
- return NodeTools::warn_or_error(warn, "Invalid ", name, " identifier: ", identifier); \
+ Logger::warn_or_error(warn, "Invalid ", name, " identifier: ", identifier); \
+ return warn; \
}; \
} \
constexpr NodeTools::NodeCallback auto expect_item_identifier( \
NodeTools::Callback<external_value_type CONST&> auto callback, bool warn \
) CONST { \
- return NodeTools::expect_identifier(expect_item_str(callback, warn)); \
+ return NodeTools::expect_identifier(expect_item_str(callback, false, warn)); \
} \
constexpr NodeTools::NodeCallback auto expect_item_string( \
- NodeTools::Callback<external_value_type CONST&> auto callback, bool warn \
+ NodeTools::Callback<external_value_type CONST&> auto callback, bool allow_empty, bool warn \
) CONST { \
- return NodeTools::expect_string(expect_item_str(callback, warn)); \
+ return NodeTools::expect_string(expect_item_str(callback, allow_empty, warn), allow_empty); \
} \
constexpr NodeTools::NodeCallback auto expect_item_identifier_or_string( \
- NodeTools::Callback<external_value_type CONST&> auto callback, bool warn \
+ NodeTools::Callback<external_value_type CONST&> auto callback, bool allow_empty, bool warn \
) CONST { \
- return NodeTools::expect_identifier_or_string(expect_item_str(callback, warn)); \
+ return NodeTools::expect_identifier_or_string(expect_item_str(callback, allow_empty, warn), allow_empty); \
} \
constexpr NodeTools::NodeCallback auto expect_item_assign_and_default( \
NodeTools::KeyValueCallback auto default_callback, \
@@ -541,9 +550,10 @@ private:
return registry.get_items(); \
} \
constexpr NodeTools::Callback<std::string_view> auto expect_##singular##_str( \
- NodeTools::Callback<decltype(registry)::external_value_type const_kw&> auto callback, bool warn = false \
+ NodeTools::Callback<decltype(registry)::external_value_type const_kw&> auto callback, bool allow_empty = false, \
+ bool warn = false \
) const_kw { \
- return registry.expect_item_str(callback, warn); \
+ return registry.expect_item_str(callback, allow_empty, warn); \
} \
constexpr NodeTools::NodeCallback auto expect_##singular##_identifier( \
NodeTools::Callback<decltype(registry)::external_value_type const_kw&> auto callback, bool warn = false \
@@ -551,14 +561,16 @@ private:
return registry.expect_item_identifier(callback, warn); \
} \
constexpr NodeTools::NodeCallback auto expect_##singular##_string( \
- NodeTools::Callback<decltype(registry)::external_value_type const_kw&> auto callback, bool warn = false \
+ NodeTools::Callback<decltype(registry)::external_value_type const_kw&> auto callback, bool allow_empty = false, \
+ bool warn = false \
) const_kw { \
- return registry.expect_item_string(callback, warn); \
+ return registry.expect_item_string(callback, allow_empty, warn); \
} \
constexpr NodeTools::NodeCallback auto expect_##singular##_identifier_or_string( \
- NodeTools::Callback<decltype(registry)::external_value_type const_kw&> auto callback, bool warn = false \
+ NodeTools::Callback<decltype(registry)::external_value_type const_kw&> auto callback,bool allow_empty = false, \
+ bool warn = false \
) const_kw { \
- return registry.expect_item_identifier_or_string(callback, warn); \
+ return registry.expect_item_identifier_or_string(callback, allow_empty, warn); \
} \
constexpr NodeTools::NodeCallback auto expect_##singular##_assign_and_default( \
NodeTools::KeyValueCallback auto default_callback, \
diff --git a/src/openvic-simulation/types/Vector.hpp b/src/openvic-simulation/types/Vector.hpp
index 5514cc3..6897835 100644
--- a/src/openvic-simulation/types/Vector.hpp
+++ b/src/openvic-simulation/types/Vector.hpp
@@ -6,6 +6,9 @@ namespace OpenVic {
template<typename T>
struct vec2_t {
+ /* PROPERTY generated getter functions will return 2D vectors by value, rather than const reference. */
+ using ov_return_by_value = void;
+
using type = T;
T x, y;
diff --git a/src/openvic-simulation/types/fixed_point/FixedPoint.hpp b/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
index 8d3a74b..6a47194 100644
--- a/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
+++ b/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
@@ -1,22 +1,21 @@
#pragma once
-#include <cerrno>
-#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <sstream>
#include <string_view>
-#include "openvic-simulation/utility/Getters.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPointLUT.hpp"
#include "openvic-simulation/utility/Logger.hpp"
#include "openvic-simulation/utility/NumberUtils.hpp"
#include "openvic-simulation/utility/StringUtils.hpp"
-#include "FixedPointLUT.hpp"
-
namespace OpenVic {
- struct fixed_point_t : ReturnByValueProperty {
+ struct fixed_point_t {
+ /* PROPERTY generated getter functions will return fixed points by value, rather than const reference. */
+ using ov_return_by_value = void;
+
static constexpr size_t SIZE = 8;
static constexpr int32_t PRECISION = FPLUT::SIN_LUT_PRECISION;
@@ -27,7 +26,7 @@ namespace OpenVic {
constexpr fixed_point_t(int32_t new_value) : value { static_cast<int64_t>(new_value) << PRECISION } {}
// Trivial destructor
- ~fixed_point_t() = default;
+ constexpr ~fixed_point_t() = default;
static constexpr fixed_point_t max() {
return std::numeric_limits<int64_t>::max();
diff --git a/src/openvic-simulation/types/fixed_point/FixedPointLUT.hpp b/src/openvic-simulation/types/fixed_point/FixedPointLUT.hpp
index 45cb639..a5d585f 100644
--- a/src/openvic-simulation/types/fixed_point/FixedPointLUT.hpp
+++ b/src/openvic-simulation/types/fixed_point/FixedPointLUT.hpp
@@ -1,15 +1,10 @@
#pragma once
-#include <array>
-#include <cmath>
-#include <cstddef>
#include <cstdint>
-#include <numbers>
-#include <utility>
namespace OpenVic::FPLUT {
-#include "FixedPointLUT_sin.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPointLUT_sin.hpp"
constexpr int32_t SHIFT = SIN_LUT_PRECISION - SIN_LUT_COUNT_LOG2;
diff --git a/src/openvic-simulation/types/fixed_point/FixedPointMath.hpp b/src/openvic-simulation/types/fixed_point/FixedPointMath.hpp
index c0b5f42..6cdb926 100644
--- a/src/openvic-simulation/types/fixed_point/FixedPointMath.hpp
+++ b/src/openvic-simulation/types/fixed_point/FixedPointMath.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "FixedPoint.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
namespace OpenVic::FPMath {
constexpr fixed_point_t sin(fixed_point_t number) {
diff --git a/src/openvic-simulation/utility/Getters.hpp b/src/openvic-simulation/utility/Getters.hpp
index 33aa5a2..fa76e74 100644
--- a/src/openvic-simulation/utility/Getters.hpp
+++ b/src/openvic-simulation/utility/Getters.hpp
@@ -51,13 +51,15 @@ public: \
ACCESS:
namespace OpenVic {
- /* Any struct extending ReturnByValueProperty will be returned by value by PROPERTY-generated getter functions,
+ /* Any struct tagged with ov_return_by_value will be returned by value by PROPERTY-generated getter functions,
* instead of by const reference as structs are by default. Use this for small structs which don't contain any
- * dynamically allocated memory, e.g. Date and fixed_point_t. */
- struct ReturnByValueProperty {
- constexpr bool operator==(ReturnByValueProperty const&) const = default;
- constexpr std::strong_ordering operator<=>(ReturnByValueProperty const&) const = default;
- };
+ * dynamically allocated memory, e.g. dates and colours. The tag must be public, as in the example below:
+ *
+ * public:
+ * using ov_return_by_value = void;
+ */
+ template<typename T>
+ concept ReturnByValue = requires { typename T::ov_return_by_value; };
/*
* Template function used to choose the return type and provide the implementation
@@ -72,7 +74,7 @@ namespace OpenVic {
/* Return std::string_view looking at std::string */
return std::string_view { property };
} else if constexpr (
- std::integral<T> || std::floating_point<T> || std::is_enum_v<T> || std::derived_from<T, ReturnByValueProperty>
+ std::integral<T> || std::floating_point<T> || std::is_enum_v<T> || ReturnByValue<T>
) {
/* Return value */
return T { property };
diff --git a/src/openvic-simulation/utility/Logger.hpp b/src/openvic-simulation/utility/Logger.hpp
index 53decb3..7a2c3d0 100644
--- a/src/openvic-simulation/utility/Logger.hpp
+++ b/src/openvic-simulation/utility/Logger.hpp
@@ -75,16 +75,16 @@ namespace OpenVic {
size_t message_count;
};
- template<typename... Ts>
+ template<typename... Args>
struct log {
- log(log_channel_t& log_channel, Ts&&... ts, source_location const& location) {
+ log(log_channel_t& log_channel, Args&&... args, source_location const& location) {
std::stringstream stream;
stream << StringUtils::get_filename(location.file_name()) << "("
/* 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::forward<Args>(args)), ...);
stream << std::endl;
log_channel.queue.push(stream.str());
if (log_channel.func) {
@@ -109,19 +109,28 @@ public: \
static inline size_t get_##name##_count() { \
return name##_channel.message_count; \
} \
- template<typename... Ts> \
+ template<typename... Args> \
struct name { \
- name(Ts&&... ts, source_location const& location = source_location::current()) { \
- log<Ts...> { name##_channel, std::forward<Ts>(ts)..., location }; \
+ name(Args&&... args, source_location const& location = source_location::current()) { \
+ log<Args...> { name##_channel, std::forward<Args>(args)..., location }; \
} \
}; \
- template<typename... Ts> \
- name(Ts&&...) -> name<Ts...>;
+ template<typename... Args> \
+ name(Args&&...) -> name<Args...>;
LOG_FUNC(info)
LOG_FUNC(warning)
LOG_FUNC(error)
#undef LOG_FUNC
+
+ template<typename... Args>
+ static inline constexpr void warn_or_error(bool warn, Args&&... args) {
+ if (warn) {
+ warning(std::forward<Args>(args)...);
+ } else {
+ error(std::forward<Args>(args)...);
+ }
+ }
};
}