From 4ae141d982e7f903913e220661aadfcfa0b0574d Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 19 Sep 2024 04:22:57 +0300 Subject: [PATCH] limit dv::value templated constructors & refactor --- src/data/dv.cpp | 19 ------------------ src/data/dv.hpp | 21 ++++++++++++++------ src/logic/scripting/scripting_functional.cpp | 2 +- src/logic/scripting/scripting_functional.hpp | 3 ++- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/data/dv.cpp b/src/data/dv.cpp index 11b57efe..dde856cd 100644 --- a/src/data/dv.cpp +++ b/src/data/dv.cpp @@ -5,25 +5,6 @@ #include "util/Buffer.hpp" namespace dv { - value::value(value_type type) : type(type) { - switch (type) { - case value_type::object: - val.object = std::make_shared(); - break; - case value_type::list: - val.list = std::make_shared(); - break; - case value_type::bytes: - val.bytes = nullptr; // no default size - break; - case value_type::string: - val.string = std::make_unique(""); - break; - default: - break; - } - } - value& value::operator[](const key_t& key) { check_type(type, value_type::object); return (*val.object)[key]; diff --git a/src/data/dv.hpp b/src/data/dv.hpp index 99e98d95..196575df 100644 --- a/src/data/dv.hpp +++ b/src/data/dv.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace util { @@ -179,12 +178,24 @@ namespace dv { } public: value() : type(value_type::none) {} - value(value_type type); - template - value(T v) { + /// @brief Constructor for fundamental types + template + value(T v, typename std::enable_if_t::value, int*> = 0) { this->operator=(v); } + value(std::string v) { + this->operator=(std::move(v)); + } + value(std::shared_ptr v) { + this->operator=(std::move(v)); + } + value(std::shared_ptr v) { + this->operator=(std::move(v)); + } + value(std::shared_ptr v) { + this->operator=(std::move(v)); + } value(const value& v) noexcept : type(value_type::none) { this->operator=(v); @@ -498,8 +509,6 @@ namespace dv { inline bool is_numeric(const value& val) { return val.isInteger() && val.isNumber(); } - - using to_string_func = std::function; } namespace dv { diff --git a/src/logic/scripting/scripting_functional.cpp b/src/logic/scripting/scripting_functional.cpp index 0b3a60c4..02398b49 100644 --- a/src/logic/scripting/scripting_functional.cpp +++ b/src/logic/scripting/scripting_functional.cpp @@ -160,7 +160,7 @@ vec2supplier scripting::create_vec2_supplier( }; } -dv::to_string_func scripting::create_tostring( +value_to_string_func scripting::create_tostring( const scriptenv& env, const std::string& src, const std::string& file ) { auto L = lua::get_main_thread(); diff --git a/src/logic/scripting/scripting_functional.hpp b/src/logic/scripting/scripting_functional.hpp index 7192adf7..2b962dee 100644 --- a/src/logic/scripting/scripting_functional.hpp +++ b/src/logic/scripting/scripting_functional.hpp @@ -9,6 +9,7 @@ namespace scripting { using common_func = std::function&)>; + using value_to_string_func = std::function; runnable create_runnable( const scriptenv& env, @@ -70,7 +71,7 @@ namespace scripting { const std::string& file = "" ); - dv::to_string_func create_tostring( + value_to_string_func create_tostring( const scriptenv& env, const std::string& src, const std::string& file = ""