aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc/Define.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-11-17 10:19:53 +0100
committer GitHub <noreply@github.com>2023-11-17 10:19:53 +0100
commite76336cd92639f4ec71088fc4c80aea4c25528cd (patch)
treeeeed419a7d97ecb58adf63a17eb9184db3e5ed7a /src/openvic-simulation/misc/Define.cpp
parenta00b558a53edb40c9e6789790036f0b618e80ec1 (diff)
parent886b8b8f396438fc2b7da7d2508f2064d14150a8 (diff)
Merge pull request #75 from OpenVicProject/accumulated-changes
Accumulated changes
Diffstat (limited to 'src/openvic-simulation/misc/Define.cpp')
-rw-r--r--src/openvic-simulation/misc/Define.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/openvic-simulation/misc/Define.cpp b/src/openvic-simulation/misc/Define.cpp
index c866b5d..cfd96a6 100644
--- a/src/openvic-simulation/misc/Define.cpp
+++ b/src/openvic-simulation/misc/Define.cpp
@@ -37,27 +37,30 @@ bool DefineManager::add_define(std::string_view name, std::string&& value, Defin
}
Date DefineManager::get_start_date() const {
- return *start_date;
+ return start_date ? *start_date : Date {};
}
Date DefineManager::get_end_date() const {
- return *end_date;
+ return end_date ? *end_date : Date {};
}
-bool DefineManager::add_date_define(std::string_view name, Date date) {
- if (name != "start_date" && name != "end_date") {
+bool DefineManager::in_game_period(Date date) const {
+ if (start_date && end_date) {
+ return date.in_range(*start_date, *end_date);
+ } else {
return false;
}
+}
- bool ret = defines.add_item({ name, date.to_string(), Define::Type::None });
-
+bool DefineManager::add_date_define(std::string_view name, Date date) {
if (name == "start_date") {
- start_date.reset(new Date(date));
+ start_date = date;
} else if (name == "end_date") {
- end_date.reset(new Date(date));
+ end_date = date;
+ } else {
+ return false;
}
-
- return ret;
+ return defines.add_item({ name, date.to_string(), Define::Type::None });
}
bool DefineManager::load_defines_file(ast::NodeCPtr root) {
@@ -103,8 +106,6 @@ bool DefineManager::load_defines_file(ast::NodeCPtr root) {
return ret;
})(value);
} else if (key == "start_date" || key == "end_date") {
- using namespace std::placeholders;
-
return expect_identifier_or_string(expect_date_str([this, &key](Date date) -> bool {
return add_date_define(key, date);
}))(value);