limit dv::value templated constructors & refactor
This commit is contained in:
parent
827a09b1d0
commit
4ae141d982
@ -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<objects::Object>();
|
||||
break;
|
||||
case value_type::list:
|
||||
val.list = std::make_shared<objects::List>();
|
||||
break;
|
||||
case value_type::bytes:
|
||||
val.bytes = nullptr; // no default size
|
||||
break;
|
||||
case value_type::string:
|
||||
val.string = std::make_unique<std::string>("");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
value& value::operator[](const key_t& key) {
|
||||
check_type(type, value_type::object);
|
||||
return (*val.object)[key];
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace util {
|
||||
@ -179,12 +178,24 @@ namespace dv {
|
||||
}
|
||||
public:
|
||||
value() : type(value_type::none) {}
|
||||
value(value_type type);
|
||||
|
||||
template<class T>
|
||||
value(T v) {
|
||||
/// @brief Constructor for fundamental types
|
||||
template<typename T>
|
||||
value(T v, typename std::enable_if_t<std::is_fundamental<T>::value, int*> = 0) {
|
||||
this->operator=(v);
|
||||
}
|
||||
value(std::string v) {
|
||||
this->operator=(std::move(v));
|
||||
}
|
||||
value(std::shared_ptr<objects::Object> v) {
|
||||
this->operator=(std::move(v));
|
||||
}
|
||||
value(std::shared_ptr<objects::List> v) {
|
||||
this->operator=(std::move(v));
|
||||
}
|
||||
value(std::shared_ptr<objects::Bytes> 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<std::string(const value&)>;
|
||||
}
|
||||
|
||||
namespace dv {
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
|
||||
namespace scripting {
|
||||
using common_func = std::function<dv::value(const std::vector<dv::value>&)>;
|
||||
using value_to_string_func = std::function<std::string(const dv::value&)>;
|
||||
|
||||
runnable create_runnable(
|
||||
const scriptenv& env,
|
||||
@ -70,7 +71,7 @@ namespace scripting {
|
||||
const std::string& file = "<string>"
|
||||
);
|
||||
|
||||
dv::to_string_func create_tostring(
|
||||
value_to_string_func create_tostring(
|
||||
const scriptenv& env,
|
||||
const std::string& src,
|
||||
const std::string& file = "<string>"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user