mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-16 14:09:02 +07:00
remove "auto Variable"
This commit is contained in:
@@ -37,7 +37,7 @@ namespace meta_hpp::field_detail
|
|||||||
void raw_setter(
|
void raw_setter(
|
||||||
[[maybe_unused]] FieldType field,
|
[[maybe_unused]] FieldType field,
|
||||||
[[maybe_unused]] instance instance,
|
[[maybe_unused]] instance instance,
|
||||||
value value)
|
[[maybe_unused]] value value)
|
||||||
{
|
{
|
||||||
using ft = detail::field_traits<FieldType>;
|
using ft = detail::field_traits<FieldType>;
|
||||||
using value_type = typename ft::value_type;
|
using value_type = typename ft::value_type;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace meta_hpp::method_detail
|
|||||||
std::optional<value> raw_cinvoke_impl(
|
std::optional<value> raw_cinvoke_impl(
|
||||||
[[maybe_unused]] MethodType method,
|
[[maybe_unused]] MethodType method,
|
||||||
[[maybe_unused]] cinstance instance,
|
[[maybe_unused]] cinstance instance,
|
||||||
value* args,
|
[[maybe_unused]] value* args,
|
||||||
std::index_sequence<Is...>)
|
std::index_sequence<Is...>)
|
||||||
{
|
{
|
||||||
using mt = detail::method_traits<MethodType>;
|
using mt = detail::method_traits<MethodType>;
|
||||||
|
|||||||
@@ -14,11 +14,11 @@
|
|||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
{
|
{
|
||||||
template < auto Variable >
|
template < typename VariableType >
|
||||||
class variable_ {
|
class variable_ {
|
||||||
public:
|
public:
|
||||||
explicit variable_(std::string id)
|
explicit variable_(std::string id, VariableType variable)
|
||||||
: info_{detail::auto_arg<META_HPP_AUTO_T(Variable)>, std::move(id)} {}
|
: info_{std::move(id), variable} {}
|
||||||
|
|
||||||
operator const variable_info&() const noexcept {
|
operator const variable_info&() const noexcept {
|
||||||
return info_;
|
return info_;
|
||||||
|
|||||||
@@ -14,17 +14,22 @@
|
|||||||
|
|
||||||
namespace meta_hpp::variable_detail
|
namespace meta_hpp::variable_detail
|
||||||
{
|
{
|
||||||
template < typename VariableType, VariableType Variable >
|
template < typename VariableType >
|
||||||
value getter() {
|
value raw_getter(
|
||||||
|
VariableType variable)
|
||||||
|
{
|
||||||
using vt = detail::variable_traits<std::remove_reference_t<VariableType>>;
|
using vt = detail::variable_traits<std::remove_reference_t<VariableType>>;
|
||||||
using value_type = typename vt::value_type;
|
using value_type = typename vt::value_type;
|
||||||
|
|
||||||
value_type typed_value{*Variable};
|
value_type typed_value{*variable};
|
||||||
return value{std::move(typed_value)};
|
return value{std::move(typed_value)};
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename VariableType, VariableType Variable >
|
template < typename VariableType >
|
||||||
void setter(value value) {
|
void raw_setter(
|
||||||
|
[[maybe_unused]] VariableType variable,
|
||||||
|
[[maybe_unused]] value value)
|
||||||
|
{
|
||||||
using vt = detail::variable_traits<std::remove_reference_t<VariableType>>;
|
using vt = detail::variable_traits<std::remove_reference_t<VariableType>>;
|
||||||
using value_type = typename vt::value_type;
|
using value_type = typename vt::value_type;
|
||||||
|
|
||||||
@@ -34,11 +39,26 @@ namespace meta_hpp::variable_detail
|
|||||||
throw std::logic_error("an attempt to set a variable with incorrect argument type");
|
throw std::logic_error("an attempt to set a variable with incorrect argument type");
|
||||||
}
|
}
|
||||||
|
|
||||||
*Variable = std::move(*typed_value);
|
*variable = std::move(*typed_value);
|
||||||
} else {
|
} else {
|
||||||
throw std::logic_error("an attempt to set a constant variable");
|
throw std::logic_error("an attempt to set a constant variable");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using variable_getter = std::function<value()>;
|
||||||
|
using variable_setter = std::function<void(value)>;
|
||||||
|
|
||||||
|
template < typename VariableType >
|
||||||
|
variable_getter make_getter(VariableType variable) {
|
||||||
|
using namespace std::placeholders;
|
||||||
|
return std::bind(&raw_getter<VariableType>, variable);
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename VariableType >
|
||||||
|
variable_setter make_setter(VariableType variable) {
|
||||||
|
using namespace std::placeholders;
|
||||||
|
return std::bind(&raw_setter<VariableType>, variable, _1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
@@ -89,18 +109,18 @@ namespace meta_hpp
|
|||||||
detail::merge_with(datas_, other.datas_, &data_info::merge);
|
detail::merge_with(datas_, other.datas_, &data_info::merge);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
template < auto Variable >
|
template < typename VariableType >
|
||||||
friend class variable_;
|
friend class variable_;
|
||||||
|
|
||||||
template < typename VariableType, VariableType Variable >
|
template < typename VariableType >
|
||||||
variable_info(detail::auto_arg_t<VariableType, Variable>, std::string id)
|
variable_info(std::string id, VariableType variable)
|
||||||
: id_{std::move(id)}
|
: id_{std::move(id)}
|
||||||
, getter_{&variable_detail::getter<VariableType, Variable>}
|
, getter_{variable_detail::make_getter(variable)}
|
||||||
, setter_{&variable_detail::setter<VariableType, Variable>} {}
|
, setter_{variable_detail::make_setter(variable)} {}
|
||||||
private:
|
private:
|
||||||
std::string id_;
|
std::string id_;
|
||||||
value(*getter_)();
|
variable_detail::variable_getter getter_;
|
||||||
void(*setter_)(value);
|
variable_detail::variable_setter setter_;
|
||||||
std::map<std::string, data_info, std::less<>> datas_;
|
std::map<std::string, data_info, std::less<>> datas_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ TEST_CASE("meta/class") {
|
|||||||
meta::function_("func", &clazz::func),
|
meta::function_("func", &clazz::func),
|
||||||
meta::method_("method", &clazz::method),
|
meta::method_("method", &clazz::method),
|
||||||
meta::method_("cmethod", &clazz::cmethod),
|
meta::method_("cmethod", &clazz::cmethod),
|
||||||
meta::variable_<&clazz::variable>("variable"),
|
meta::variable_("variable", &clazz::variable),
|
||||||
meta::variable_<&clazz::cvariable>("cvariable"));
|
meta::variable_("cvariable", &clazz::cvariable));
|
||||||
|
|
||||||
CHECK(clazz_info.get_class("clazz2"));
|
CHECK(clazz_info.get_class("clazz2"));
|
||||||
CHECK(clazz_info.get_field("field"));
|
CHECK(clazz_info.get_field("field"));
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ TEST_CASE("meta/data/variable") {
|
|||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
const meta::class_info clazz_info = meta::class_<clazz>("clazz")(
|
const meta::class_info clazz_info = meta::class_<clazz>("clazz")(
|
||||||
meta::variable_<&clazz::variable>("variable")(
|
meta::variable_("variable", &clazz::variable)(
|
||||||
meta::data_("hello"s, "world"s)
|
meta::data_("hello"s, "world"s)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ TEST_CASE("meta/namespace") {
|
|||||||
meta::class_<clazz>("clazz"),
|
meta::class_<clazz>("clazz"),
|
||||||
meta::function_("func", &func),
|
meta::function_("func", &func),
|
||||||
meta::namespace_("ns2"),
|
meta::namespace_("ns2"),
|
||||||
meta::variable_<&variable>("variable"),
|
meta::variable_("variable", &variable),
|
||||||
meta::variable_<&cvariable>("cvariable"));
|
meta::variable_("cvariable", &cvariable));
|
||||||
|
|
||||||
CHECK(ns_info.get_class("clazz"));
|
CHECK(ns_info.get_class("clazz"));
|
||||||
CHECK(ns_info.get_function("func"));
|
CHECK(ns_info.get_function("func"));
|
||||||
@@ -82,7 +82,7 @@ TEST_CASE("meta/namespace/merge") {
|
|||||||
meta::class_<clazz>{"clazz"},
|
meta::class_<clazz>{"clazz"},
|
||||||
meta::function_("func", &func),
|
meta::function_("func", &func),
|
||||||
meta::namespace_{"ns3"},
|
meta::namespace_{"ns3"},
|
||||||
meta::variable_<&variable>("variable")
|
meta::variable_("variable", &variable)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ TEST_CASE("meta/namespace/merge") {
|
|||||||
meta::function_("func2", &func),
|
meta::function_("func2", &func),
|
||||||
meta::namespace_{"ns3"}(
|
meta::namespace_{"ns3"}(
|
||||||
meta::namespace_{"ns4"},
|
meta::namespace_{"ns4"},
|
||||||
meta::variable_<&variable>("variable2")
|
meta::variable_("variable2", &variable)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -54,14 +54,14 @@ TEST_CASE("meta/registry") {
|
|||||||
meta::field_("x", &ivec2::x),
|
meta::field_("x", &ivec2::x),
|
||||||
meta::field_("y", &ivec2::y),
|
meta::field_("y", &ivec2::y),
|
||||||
meta::method_("dot", &ivec2::dot),
|
meta::method_("dot", &ivec2::dot),
|
||||||
meta::variable_<&ivec2::zero>("zero")
|
meta::variable_("zero", &ivec2::zero)
|
||||||
),
|
),
|
||||||
meta::class_<ivec3>("ivec3")(
|
meta::class_<ivec3>("ivec3")(
|
||||||
meta::field_("x", &ivec3::x),
|
meta::field_("x", &ivec3::x),
|
||||||
meta::field_("y", &ivec3::y),
|
meta::field_("y", &ivec3::y),
|
||||||
meta::field_("z", &ivec3::z),
|
meta::field_("z", &ivec3::z),
|
||||||
meta::method_("dot", &ivec3::dot),
|
meta::method_("dot", &ivec3::dot),
|
||||||
meta::variable_<&ivec3::zero>("zero")
|
meta::variable_("zero", &ivec3::zero)
|
||||||
),
|
),
|
||||||
meta::function_("iadd2", &iadd2),
|
meta::function_("iadd2", &iadd2),
|
||||||
meta::function_("iadd3", &iadd3)
|
meta::function_("iadd3", &iadd3)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ TEST_CASE("meta/type") {
|
|||||||
CHECK(namespace_type.is_namespace());
|
CHECK(namespace_type.is_namespace());
|
||||||
CHECK(namespace_type.get_namespace()->id() == "ns");
|
CHECK(namespace_type.get_namespace()->id() == "ns");
|
||||||
|
|
||||||
meta::type variable_type = meta::variable_<&clazz::variable>("variable");
|
meta::type variable_type = meta::variable_("variable", &clazz::variable);
|
||||||
CHECK(variable_type.is_variable());
|
CHECK(variable_type.is_variable());
|
||||||
CHECK(variable_type.get_variable()->id() == "variable");
|
CHECK(variable_type.get_variable()->id() == "variable");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ TEST_CASE("meta/variable") {
|
|||||||
namespace meta = meta_hpp;
|
namespace meta = meta_hpp;
|
||||||
|
|
||||||
SUBCASE("in_namespace") {
|
SUBCASE("in_namespace") {
|
||||||
meta::variable_<&variable> variable_{"variable"};
|
meta::variable_ variable_{"variable", &variable};
|
||||||
meta::variable_<&cvariable> cvariable_{"cvariable"};
|
meta::variable_ cvariable_{"cvariable", &cvariable};
|
||||||
|
|
||||||
const meta::variable_info& variable_info = variable_;
|
const meta::variable_info& variable_info = variable_;
|
||||||
const meta::variable_info& cvariable_info = cvariable_;
|
const meta::variable_info& cvariable_info = cvariable_;
|
||||||
@@ -60,8 +60,8 @@ TEST_CASE("meta/variable") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SUBCASE("in_class") {
|
SUBCASE("in_class") {
|
||||||
meta::variable_<&clazz::variable> variable_{"variable"};
|
meta::variable_ variable_{"variable", &clazz::variable};
|
||||||
meta::variable_<&clazz::cvariable> cvariable_{"cvariable"};
|
meta::variable_ cvariable_{"cvariable", &clazz::cvariable};
|
||||||
|
|
||||||
const meta::variable_info& variable_info = variable_;
|
const meta::variable_info& variable_info = variable_;
|
||||||
const meta::variable_info& cvariable_info = cvariable_;
|
const meta::variable_info& cvariable_info = cvariable_;
|
||||||
|
|||||||
Reference in New Issue
Block a user