From f061dd4bf2d1a180cb94647e845c53385a6a44a4 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:50:04 +0300 Subject: [PATCH] make setting constructors private --- loader/include/Geode/loader/SettingV3.hpp | 54 +++++++++++++++++++---- loader/src/loader/SettingV3.cpp | 36 +++++++-------- 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/loader/include/Geode/loader/SettingV3.hpp b/loader/include/Geode/loader/SettingV3.hpp index 91af75ad..c03f0c81 100644 --- a/loader/include/Geode/loader/SettingV3.hpp +++ b/loader/include/Geode/loader/SettingV3.hpp @@ -133,8 +133,12 @@ namespace geode { protected: Result<> onParse(std::string const& key, std::string const& modID, matjson::Value const& json) override; + private: + class PrivateMarker {}; + friend class SettingV3; + public: - TitleSettingV3(); + TitleSettingV3(PrivateMarker); std::string getTitle() const; @@ -157,8 +161,12 @@ namespace geode { protected: Result<> onParse(std::string const& key, std::string const& modID, matjson::Value const& json) override; + private: + class PrivateMarker {}; + friend class SettingV3; + public: - UnresolvedCustomSettingV3(); + UnresolvedCustomSettingV3(PrivateMarker); bool load(matjson::Value const& json) override; bool save(matjson::Value& json) const override; @@ -180,8 +188,12 @@ namespace geode { bool& getValueMut() const override; Result<> onParse(std::string const& key, std::string const& modID, matjson::Value const& json) override; + private: + class PrivateMarker {}; + friend class SettingV3; + public: - BoolSettingV3(); + BoolSettingV3(PrivateMarker); bool getDefaultValue() const override; Result<> isValid(bool value) const override; @@ -203,8 +215,12 @@ namespace geode { int64_t& getValueMut() const override; Result<> onParse(std::string const& key, std::string const& modID, matjson::Value const& json) override; + private: + class PrivateMarker {}; + friend class SettingV3; + public: - IntSettingV3(); + IntSettingV3(PrivateMarker); int64_t getDefaultValue() const override; Result<> isValid(int64_t value) const override; @@ -237,8 +253,12 @@ namespace geode { double& getValueMut() const override; Result<> onParse(std::string const& key, std::string const& modID, matjson::Value const& json) override; + private: + class PrivateMarker {}; + friend class SettingV3; + public: - FloatSettingV3(); + FloatSettingV3(PrivateMarker); double getDefaultValue() const override; Result<> isValid(double value) const override; @@ -271,8 +291,12 @@ namespace geode { std::string& getValueMut() const override; Result<> onParse(std::string const& key, std::string const& modID, matjson::Value const& json) override; + private: + class PrivateMarker {}; + friend class SettingV3; + public: - StringSettingV3(); + StringSettingV3(PrivateMarker); std::string getDefaultValue() const override; Result<> isValid(std::string_view value) const override; @@ -298,8 +322,12 @@ namespace geode { std::filesystem::path& getValueMut() const override; Result<> onParse(std::string const& key, std::string const& modID, matjson::Value const& json) override; + private: + class PrivateMarker {}; + friend class SettingV3; + public: - FileSettingV3(); + FileSettingV3(PrivateMarker); std::filesystem::path getDefaultValue() const override; Result<> isValid(std::filesystem::path const& value) const override; @@ -323,8 +351,12 @@ namespace geode { cocos2d::ccColor3B& getValueMut() const override; Result<> onParse(std::string const& key, std::string const& modID, matjson::Value const& json) override; + private: + class PrivateMarker {}; + friend class SettingV3; + public: - Color3BSettingV3(); + Color3BSettingV3(PrivateMarker); cocos2d::ccColor3B getDefaultValue() const override; Result<> isValid(cocos2d::ccColor3B value) const override; @@ -346,8 +378,12 @@ namespace geode { cocos2d::ccColor4B& getValueMut() const override; Result<> onParse(std::string const& key, std::string const& modID, matjson::Value const& json) override; + private: + class PrivateMarker {}; + friend class SettingV3; + public: - Color4BSettingV3(); + Color4BSettingV3(PrivateMarker); cocos2d::ccColor4B getDefaultValue() const override; Result<> isValid(cocos2d::ccColor4B value) const override; diff --git a/loader/src/loader/SettingV3.cpp b/loader/src/loader/SettingV3.cpp index e919dd9e..2e80637f 100644 --- a/loader/src/loader/SettingV3.cpp +++ b/loader/src/loader/SettingV3.cpp @@ -38,16 +38,16 @@ Result> SettingV3::parseBuiltin(std::string const& ke root.needs("type").into(type); std::shared_ptr ret; switch (hash(type)) { - case hash("bool"): ret = std::make_shared(); break; - case hash("int"): ret = std::make_shared(); break; - case hash("float"): ret = std::make_shared(); break; - case hash("string"): ret = std::make_shared(); break; - case hash("rgb"): case hash("color"): ret = std::make_shared(); break; - case hash("rgba"): ret = std::make_shared(); break; - case hash("path"): case hash("file"): ret = std::make_shared(); break; - case hash("title"): ret = std::make_shared(); break; + case hash("bool"): ret = std::make_shared(BoolSettingV3::PrivateMarker()); break; + case hash("int"): ret = std::make_shared(IntSettingV3::PrivateMarker()); break; + case hash("float"): ret = std::make_shared(FloatSettingV3::PrivateMarker()); break; + case hash("string"): ret = std::make_shared(StringSettingV3::PrivateMarker()); break; + case hash("rgb"): case hash("color"): ret = std::make_shared(Color3BSettingV3::PrivateMarker()); break; + case hash("rgba"): ret = std::make_shared(Color4BSettingV3::PrivateMarker()); break; + case hash("path"): case hash("file"): ret = std::make_shared(FileSettingV3::PrivateMarker()); break; + case hash("title"): ret = std::make_shared(TitleSettingV3::PrivateMarker()); break; default: - case hash("custom"): ret = std::make_shared(); break; + case hash("custom"): ret = std::make_shared(UnresolvedCustomSettingV3::PrivateMarker()); break; } GEODE_UNWRAP(ret->parse(key, modID, json)); return root.ok(std::move(ret)); @@ -100,7 +100,7 @@ public: std::string title; }; -TitleSettingV3::TitleSettingV3() : m_impl(std::make_shared()) {} +TitleSettingV3::TitleSettingV3(PrivateMarker) : m_impl(std::make_shared()) {} std::string TitleSettingV3::getTitle() const { return m_impl->title; @@ -134,7 +134,7 @@ void TitleSettingV3::reset() {} // replace this comment with it // put it riiiiiight here -UnresolvedCustomSettingV3::UnresolvedCustomSettingV3() : m_impl(std::make_shared()) {} +UnresolvedCustomSettingV3::UnresolvedCustomSettingV3(PrivateMarker) : m_impl(std::make_shared()) {} Result<> UnresolvedCustomSettingV3::onParse(std::string const& key, std::string const& modID, matjson::Value const& json) { m_impl->json = json; @@ -177,7 +177,7 @@ public: bool defaultValue; }; -BoolSettingV3::BoolSettingV3() : m_impl(std::make_shared()) {} +BoolSettingV3::BoolSettingV3(PrivateMarker) : m_impl(std::make_shared()) {} bool& BoolSettingV3::getValueMut() const { return m_impl->value; @@ -244,7 +244,7 @@ public: } controls; }; -IntSettingV3::IntSettingV3() : m_impl(std::make_shared()) {} +IntSettingV3::IntSettingV3(PrivateMarker) : m_impl(std::make_shared()) {} int64_t& IntSettingV3::getValueMut() const { return m_impl->value; @@ -374,7 +374,7 @@ public: } controls; }; -FloatSettingV3::FloatSettingV3() : m_impl(std::make_shared()) {} +FloatSettingV3::FloatSettingV3(PrivateMarker) : m_impl(std::make_shared()) {} double& FloatSettingV3::getValueMut() const { return m_impl->value; @@ -496,7 +496,7 @@ public: std::optional> oneOf; }; -StringSettingV3::StringSettingV3() : m_impl(std::make_shared()) {} +StringSettingV3::StringSettingV3(PrivateMarker) : m_impl(std::make_shared()) {} std::string& StringSettingV3::getValueMut() const { return m_impl->value; @@ -580,7 +580,7 @@ public: std::optional> filters; }; -FileSettingV3::FileSettingV3() : m_impl(std::make_shared()) {} +FileSettingV3::FileSettingV3(PrivateMarker) : m_impl(std::make_shared()) {} std::filesystem::path& FileSettingV3::getValueMut() const { return m_impl->value; @@ -669,7 +669,7 @@ public: ccColor3B defaultValue; }; -Color3BSettingV3::Color3BSettingV3() : m_impl(std::make_shared()) {} +Color3BSettingV3::Color3BSettingV3(PrivateMarker) : m_impl(std::make_shared()) {} ccColor3B& Color3BSettingV3::getValueMut() const { return m_impl->value; @@ -725,7 +725,7 @@ public: ccColor4B defaultValue; }; -Color4BSettingV3::Color4BSettingV3() : m_impl(std::make_shared()) {} +Color4BSettingV3::Color4BSettingV3(PrivateMarker) : m_impl(std::make_shared()) {} ccColor4B& Color4BSettingV3::getValueMut() const { return m_impl->value;