aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc/Define.hpp
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-10-20 01:56:06 +0200
committer Spartan322 <Megacake1234@gmail.com>2023-10-20 10:48:38 +0200
commit3d728f054e3c214f840b7e63539aea0c4c5246b5 (patch)
treec25a4e654d597ca2ca699ffb2b1bde6b6eeba053 /src/openvic-simulation/misc/Define.hpp
parent910d6cd73d7b1857ff481e1af060e780ec27d800 (diff)
Add Defines Loading
Caches start_date and end_date in DefineManager Add static `get_property` and HASID_PROPERTY macro to HasIdentifier
Diffstat (limited to 'src/openvic-simulation/misc/Define.hpp')
-rw-r--r--src/openvic-simulation/misc/Define.hpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/openvic-simulation/misc/Define.hpp b/src/openvic-simulation/misc/Define.hpp
new file mode 100644
index 0000000..9b768b7
--- /dev/null
+++ b/src/openvic-simulation/misc/Define.hpp
@@ -0,0 +1,63 @@
+#pragma once
+
+#include <concepts>
+#include <memory>
+
+#include "openvic-simulation/types/IdentifierRegistry.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
+
+namespace OpenVic {
+ struct DefineManager;
+
+ struct Define : HasIdentifier {
+ friend struct DefineManager;
+
+ enum class Type : unsigned char {
+ None,
+ Country,
+ Economy,
+ Military,
+ Diplomacy,
+ Pops,
+ Ai,
+ Graphics
+ };
+
+ private:
+ std::string HASID_PROPERTY(value);
+ Type HASID_PROPERTY(type);
+
+ Define(
+ std::string_view new_identifier,
+ std::string&& new_value,
+ Type new_type
+ );
+
+ public:
+ Define(Define&&) = default;
+
+ fixed_point_t get_value_as_fp() const;
+ int64_t get_value_as_int() const;
+ uint64_t get_value_as_uint() const;
+ };
+
+ struct DefineManager {
+ private:
+ IdentifierRegistry<Define> defines;
+
+ std::unique_ptr<Date> start_date = nullptr;
+ std::unique_ptr<Date> end_date = nullptr;
+
+ public:
+ DefineManager();
+
+ bool add_define(std::string_view name, std::string&& value, Define::Type type);
+ bool add_date_define(std::string_view name, Date date);
+ IDENTIFIER_REGISTRY_ACCESSORS(define);
+
+ const Date& get_start_date() const;
+ const Date& get_end_date() const;
+
+ bool load_defines_file(ast::NodeCPtr root);
+ };
+} \ No newline at end of file