mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 11:52:08 +07:00
remove all value family id
This commit is contained in:
@@ -66,13 +66,10 @@ namespace meta_hpp
|
||||
field_info& operator=(field_info&&) = default;
|
||||
field_info& operator=(const field_info&) = default;
|
||||
public:
|
||||
const family_id& fid() const noexcept {
|
||||
return fid_;
|
||||
}
|
||||
|
||||
const std::string& id() const noexcept {
|
||||
return id_;
|
||||
}
|
||||
|
||||
value get(cinstance instance) const {
|
||||
return getter_(instance);
|
||||
}
|
||||
@@ -99,7 +96,7 @@ namespace meta_hpp
|
||||
}
|
||||
|
||||
void merge(const field_info& other) {
|
||||
if ( fid() != other.fid() ) {
|
||||
if ( id() != other.id() ) {
|
||||
throw std::logic_error("field_info::merge failed");
|
||||
}
|
||||
detail::merge_with(datas_, other.datas_, &data_info::merge);
|
||||
@@ -110,12 +107,10 @@ namespace meta_hpp
|
||||
|
||||
template < typename FieldType, FieldType Field >
|
||||
field_info(detail::auto_arg_t<FieldType, Field>, std::string id)
|
||||
: fid_{get_value_family_id<FieldType, Field>()}
|
||||
, id_{std::move(id)}
|
||||
: id_{std::move(id)}
|
||||
, getter_{&field_detail::getter<FieldType, Field>}
|
||||
, setter_{&field_detail::setter<FieldType, Field>} {}
|
||||
private:
|
||||
family_id fid_;
|
||||
std::string id_;
|
||||
value(*getter_)(cinstance);
|
||||
void(*setter_)(instance, value);
|
||||
|
||||
@@ -60,10 +60,6 @@ namespace meta_hpp
|
||||
function_info& operator=(function_info&&) = default;
|
||||
function_info& operator=(const function_info&) = default;
|
||||
public:
|
||||
const family_id& fid() const noexcept {
|
||||
return fid_;
|
||||
}
|
||||
|
||||
const std::string& id() const noexcept {
|
||||
return id_;
|
||||
}
|
||||
@@ -95,7 +91,7 @@ namespace meta_hpp
|
||||
}
|
||||
|
||||
void merge(const function_info& other) {
|
||||
if ( fid() != other.fid() ) {
|
||||
if ( id() != other.id() ) {
|
||||
throw std::logic_error("function_info::merge failed");
|
||||
}
|
||||
detail::merge_with(datas_, other.datas_, &data_info::merge);
|
||||
@@ -106,11 +102,9 @@ namespace meta_hpp
|
||||
|
||||
template < typename FunctionType, FunctionType Function >
|
||||
function_info(detail::auto_arg_t<FunctionType, Function>, std::string id)
|
||||
: fid_{get_value_family_id<FunctionType, Function>()}
|
||||
, id_{std::move(id)}
|
||||
: id_{std::move(id)}
|
||||
, invoke_{&function_detail::invoke<FunctionType, Function>} {}
|
||||
private:
|
||||
family_id fid_;
|
||||
std::string id_;
|
||||
std::optional<value>(*invoke_)(value*, std::size_t);
|
||||
std::map<std::string, data_info, std::less<>> datas_;
|
||||
|
||||
@@ -78,27 +78,12 @@ namespace meta_hpp
|
||||
return self_id;
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T, T V >
|
||||
class value_family final : public family_base<> {
|
||||
public:
|
||||
static family_id id() noexcept {
|
||||
static family_id self_id{++last_id_};
|
||||
assert(self_id.id > 0u && "family_id overflow");
|
||||
return self_id;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
family_id get_type_family_id() noexcept {
|
||||
return family_id_detail::type_family<T>::id();
|
||||
}
|
||||
|
||||
template < typename T, T V >
|
||||
family_id get_value_family_id() noexcept {
|
||||
return family_id_detail::value_family<T, V>::id();
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
|
||||
@@ -110,10 +110,6 @@ namespace meta_hpp
|
||||
method_info& operator=(method_info&&) = default;
|
||||
method_info& operator=(const method_info&) = default;
|
||||
public:
|
||||
const family_id& fid() const noexcept {
|
||||
return fid_;
|
||||
}
|
||||
|
||||
const std::string& id() const noexcept {
|
||||
return id_;
|
||||
}
|
||||
@@ -155,7 +151,7 @@ namespace meta_hpp
|
||||
}
|
||||
|
||||
void merge(const method_info& other) {
|
||||
if ( fid() != other.fid() ) {
|
||||
if ( id() != other.id() ) {
|
||||
throw std::logic_error("method_info::merge failed");
|
||||
}
|
||||
detail::merge_with(datas_, other.datas_, &data_info::merge);
|
||||
@@ -166,12 +162,10 @@ namespace meta_hpp
|
||||
|
||||
template < typename MethodType, MethodType Method >
|
||||
method_info(detail::auto_arg_t<MethodType, Method>, std::string id)
|
||||
: fid_{get_value_family_id<MethodType, Method>()}
|
||||
, id_{std::move(id)}
|
||||
: id_{std::move(id)}
|
||||
, invoke_{&method_detail::invoke<MethodType, Method>}
|
||||
, cinvoke_{&method_detail::cinvoke<MethodType, Method>} {}
|
||||
private:
|
||||
family_id fid_;
|
||||
std::string id_;
|
||||
std::optional<value>(*invoke_)(instance, value*, std::size_t);
|
||||
std::optional<value>(*cinvoke_)(cinstance, value*, std::size_t);
|
||||
|
||||
@@ -27,12 +27,6 @@ namespace meta_hpp
|
||||
return detail::find_opt(types_, fid);
|
||||
}
|
||||
|
||||
template < typename T, T V >
|
||||
std::optional<type> resolve() const {
|
||||
const family_id fid = get_value_family_id<T, V>();
|
||||
return detail::find_opt(types_, fid);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
std::optional<type> resolve(T&&) const {
|
||||
const family_id fid = get_type_family_id<std::decay_t<T>>();
|
||||
@@ -149,7 +143,6 @@ namespace meta_hpp
|
||||
? info.id()
|
||||
: prefix + "::" + info.id();
|
||||
|
||||
detail::merge_with(types_, info.fid(), info, &type::merge);
|
||||
detail::merge_with(fields_, name, info, &field_info::merge);
|
||||
|
||||
info.visit(overloaded {
|
||||
@@ -165,7 +158,6 @@ namespace meta_hpp
|
||||
? info.id()
|
||||
: prefix + "::" + info.id();
|
||||
|
||||
detail::merge_with(types_, info.fid(), info, &type::merge);
|
||||
detail::merge_with(functions_, name, info, &function_info::merge);
|
||||
|
||||
info.visit(overloaded {
|
||||
@@ -181,7 +173,6 @@ namespace meta_hpp
|
||||
? info.id()
|
||||
: prefix + "::" + info.id();
|
||||
|
||||
detail::merge_with(types_, info.fid(), info, &type::merge);
|
||||
detail::merge_with(methods_, name, info, &method_info::merge);
|
||||
|
||||
info.visit(overloaded {
|
||||
@@ -212,7 +203,6 @@ namespace meta_hpp
|
||||
? info.id()
|
||||
: prefix + "::" + info.id();
|
||||
|
||||
detail::merge_with(types_, info.fid(), info, &type::merge);
|
||||
detail::merge_with(variables_, name, info, &variable_info::merge);
|
||||
|
||||
info.visit(overloaded {
|
||||
|
||||
@@ -53,10 +53,6 @@ namespace meta_hpp
|
||||
variable_info& operator=(variable_info&&) = default;
|
||||
variable_info& operator=(const variable_info&) = default;
|
||||
public:
|
||||
const family_id& fid() const noexcept {
|
||||
return fid_;
|
||||
}
|
||||
|
||||
const std::string& id() const noexcept {
|
||||
return id_;
|
||||
}
|
||||
@@ -87,7 +83,7 @@ namespace meta_hpp
|
||||
}
|
||||
|
||||
void merge(const variable_info& other) {
|
||||
if ( fid() != other.fid() ) {
|
||||
if ( id() != other.id() ) {
|
||||
throw std::logic_error("variable_info::merge failed");
|
||||
}
|
||||
detail::merge_with(datas_, other.datas_, &data_info::merge);
|
||||
@@ -98,12 +94,10 @@ namespace meta_hpp
|
||||
|
||||
template < typename VariableType, VariableType Variable >
|
||||
variable_info(detail::auto_arg_t<VariableType, Variable>, std::string id)
|
||||
: fid_{get_value_family_id<VariableType, Variable>()}
|
||||
, id_{std::move(id)}
|
||||
: id_{std::move(id)}
|
||||
, getter_{&variable_detail::getter<VariableType, Variable>}
|
||||
, setter_{&variable_detail::setter<VariableType, Variable>} {}
|
||||
private:
|
||||
family_id fid_;
|
||||
std::string id_;
|
||||
value(*getter_)();
|
||||
void(*setter_)(value);
|
||||
|
||||
@@ -17,36 +17,13 @@ namespace
|
||||
struct ivec2 {
|
||||
int x{};
|
||||
int y{};
|
||||
|
||||
static ivec2 zero;
|
||||
|
||||
int dot(ivec2 other) const {
|
||||
return x * other.x + y * other.y;
|
||||
}
|
||||
};
|
||||
|
||||
struct ivec3 {
|
||||
int x{};
|
||||
int y{};
|
||||
int z{};
|
||||
|
||||
static ivec3 zero;
|
||||
|
||||
int dot(ivec3 other) const {
|
||||
return x * other.x + y * other.y + z * other.z;
|
||||
}
|
||||
};
|
||||
|
||||
ivec2 ivec2::zero{};
|
||||
ivec3 ivec3::zero{};
|
||||
|
||||
ivec2 iadd2(ivec2 l, ivec2 r) {
|
||||
return {l.x + r.x, l.y + r.y};
|
||||
}
|
||||
|
||||
ivec3 iadd3(ivec3 l, ivec3 r) {
|
||||
return {l.x + r.x, l.y + r.y, l.z + r.z};
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("meta/family") {
|
||||
@@ -58,28 +35,4 @@ TEST_CASE("meta/family") {
|
||||
meta::class_info ivec3_info = meta::class_<ivec3>("ivec3");
|
||||
CHECK_FALSE(ivec2_info.fid() == ivec3_info.fid());
|
||||
}
|
||||
|
||||
SUBCASE("field") {
|
||||
meta::field_info x_info = meta::field_<&ivec2::x>("x");
|
||||
meta::field_info y_info = meta::field_<&ivec2::y>("y");
|
||||
CHECK_FALSE(x_info.fid() == y_info.fid());
|
||||
}
|
||||
|
||||
SUBCASE("function") {
|
||||
meta::function_info iadd2_info = meta::function_<&iadd2>("iadd2");
|
||||
meta::function_info iadd3_info = meta::function_<&iadd3>("iadd3");
|
||||
CHECK_FALSE(iadd2_info.fid() == iadd3_info.fid());
|
||||
}
|
||||
|
||||
SUBCASE("method") {
|
||||
meta::method_info dot2_info = meta::method_<&ivec2::dot>("dot");
|
||||
meta::method_info dot3_info = meta::method_<&ivec3::dot>("dot");
|
||||
CHECK_FALSE(dot2_info.fid() == dot3_info.fid());
|
||||
}
|
||||
|
||||
SUBCASE("variable") {
|
||||
meta::variable_info zero2_info = meta::variable_<&ivec2::zero>("zero");
|
||||
meta::variable_info zero3_info = meta::variable_<&ivec3::zero>("zero");
|
||||
CHECK_FALSE(zero2_info.fid() == zero3_info.fid());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,69 +89,6 @@ TEST_CASE("meta/registry") {
|
||||
CHECK(ivec3_info.id() == "ivec3");
|
||||
}
|
||||
|
||||
SUBCASE("field_template") {
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec2::x)>());
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec2::y)>());
|
||||
|
||||
const meta::type ivec2_x_type = registry.resolve<META_HPP_AUTO_T(&ivec2::x)>().value();
|
||||
const meta::type ivec2_y_type = registry.resolve<META_HPP_AUTO_T(&ivec2::y)>().value();
|
||||
|
||||
REQUIRE(ivec2_x_type.is_field());
|
||||
REQUIRE(ivec2_y_type.is_field());
|
||||
|
||||
const meta::field_info ivec2_x_info = ivec2_x_type.get_field().value();
|
||||
const meta::field_info ivec2_y_info = ivec2_y_type.get_field().value();
|
||||
|
||||
CHECK(ivec2_x_info.id() == "x");
|
||||
CHECK(ivec2_y_info.id() == "y");
|
||||
}
|
||||
|
||||
SUBCASE("field_instance") {
|
||||
CHECK_FALSE(registry.resolve(&ivec2::x));
|
||||
}
|
||||
|
||||
SUBCASE("function_template") {
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&iadd2)>());
|
||||
|
||||
const meta::type iadd2_type = registry.resolve<META_HPP_AUTO_T(&iadd2)>().value();
|
||||
REQUIRE(iadd2_type.is_function());
|
||||
|
||||
const meta::function_info iadd2_info = iadd2_type.get_function().value();
|
||||
CHECK(iadd2_info.id() == "iadd2");
|
||||
}
|
||||
|
||||
SUBCASE("function_instance") {
|
||||
CHECK_FALSE(registry.resolve(&iadd3));
|
||||
}
|
||||
|
||||
SUBCASE("method_template") {
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec2::dot)>());
|
||||
|
||||
const meta::type ivec2_dot_type = registry.resolve<META_HPP_AUTO_T(&ivec2::dot)>().value();
|
||||
REQUIRE(ivec2_dot_type.is_method());
|
||||
|
||||
const meta::method_info ivec2_dot_info = ivec2_dot_type.get_method().value();
|
||||
CHECK(ivec2_dot_info.id() == "dot");
|
||||
}
|
||||
|
||||
SUBCASE("method_instance") {
|
||||
CHECK_FALSE(registry.resolve(&ivec3::dot));
|
||||
}
|
||||
|
||||
SUBCASE("variable_template") {
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec2::zero)>());
|
||||
|
||||
const meta::type ivec2_zero_type = registry.resolve<META_HPP_AUTO_T(&ivec2::zero)>().value();
|
||||
REQUIRE(ivec2_zero_type.is_variable());
|
||||
|
||||
const meta::variable_info ivec2_x_info = ivec2_zero_type.get_variable().value();
|
||||
CHECK(ivec2_x_info.id() == "zero");
|
||||
}
|
||||
|
||||
SUBCASE("variable_instance") {
|
||||
CHECK_FALSE(registry.resolve(&ivec3::zero));
|
||||
}
|
||||
|
||||
SUBCASE("resolve/class") {
|
||||
ivec2 v2;
|
||||
ivec3 v3;
|
||||
@@ -190,110 +127,39 @@ TEST_CASE("meta/registry") {
|
||||
}
|
||||
|
||||
SUBCASE("resolve/field") {
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec2::x)>());
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec2::y)>());
|
||||
CHECK_FALSE(registry.resolve(&ivec2::x));
|
||||
CHECK_FALSE(registry.resolve(&ivec2::y));
|
||||
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec3::x)>());
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec3::y)>());
|
||||
CHECK_FALSE(registry.resolve(&ivec3::x));
|
||||
CHECK_FALSE(registry.resolve(&ivec3::y));
|
||||
|
||||
const meta::field_info v2_x_info = meta::field_<&ivec2::x>("x");
|
||||
const meta::field_info v2_y_info = meta::field_<&ivec2::y>("y");
|
||||
CHECK(v2_x_info.fid() != v2_y_info.fid());
|
||||
|
||||
const meta::field_info v3_x_info = meta::field_<&ivec3::x>("x");
|
||||
const meta::field_info v3_y_info = meta::field_<&ivec3::y>("y");
|
||||
CHECK(v3_x_info.fid() != v3_y_info.fid());
|
||||
|
||||
CHECK(v2_x_info.fid() != v3_x_info.fid());
|
||||
CHECK(v2_y_info.fid() != v3_y_info.fid());
|
||||
|
||||
CHECK(v2_x_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec2::x)>()->get_field()->fid());
|
||||
CHECK(v2_y_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec2::y)>()->get_field()->fid());
|
||||
|
||||
CHECK(v3_x_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec3::x)>()->get_field()->fid());
|
||||
CHECK(v3_y_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec3::y)>()->get_field()->fid());
|
||||
|
||||
{
|
||||
REQUIRE(registry.get_field_by_name("vmath::ivec2::x"));
|
||||
REQUIRE(registry.get_field_by_name("vmath::ivec2::y"));
|
||||
REQUIRE(registry.get_field_by_name("vmath::ivec3::x"));
|
||||
REQUIRE(registry.get_field_by_name("vmath::ivec3::y"));
|
||||
|
||||
CHECK(v2_x_info.fid() == registry.get_field_by_name("vmath::ivec2::x")->fid());
|
||||
CHECK(v2_y_info.fid() == registry.get_field_by_name("vmath::ivec2::y")->fid());
|
||||
CHECK(v3_x_info.fid() == registry.get_field_by_name("vmath::ivec3::x")->fid());
|
||||
CHECK(v3_y_info.fid() == registry.get_field_by_name("vmath::ivec3::y")->fid());
|
||||
}
|
||||
CHECK("x" == registry.get_field_by_name("vmath::ivec2::x")->id());
|
||||
CHECK("y" == registry.get_field_by_name("vmath::ivec2::y")->id());
|
||||
CHECK("x" == registry.get_field_by_name("vmath::ivec3::x")->id());
|
||||
CHECK("y" == registry.get_field_by_name("vmath::ivec3::y")->id());
|
||||
}
|
||||
|
||||
SUBCASE("resolve/function") {
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&iadd2)>());
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&iadd3)>());
|
||||
CHECK_FALSE(registry.resolve(&iadd2));
|
||||
CHECK_FALSE(registry.resolve(&iadd3));
|
||||
|
||||
const meta::function_info iadd2_info = meta::function_<&iadd2>("iadd2");
|
||||
const meta::function_info iadd3_info = meta::function_<&iadd3>("iadd3");
|
||||
CHECK(iadd2_info.fid() != iadd3_info.fid());
|
||||
|
||||
CHECK(iadd2_info.fid() == registry.resolve<META_HPP_AUTO_T(&iadd2)>()->get_function()->fid());
|
||||
CHECK(iadd3_info.fid() == registry.resolve<META_HPP_AUTO_T(&iadd3)>()->get_function()->fid());
|
||||
|
||||
{
|
||||
REQUIRE(registry.get_function_by_name("vmath::iadd2"));
|
||||
REQUIRE(registry.get_function_by_name("vmath::iadd3"));
|
||||
|
||||
CHECK(iadd2_info.fid() == registry.get_function_by_name("vmath::iadd2")->fid());
|
||||
CHECK(iadd3_info.fid() == registry.get_function_by_name("vmath::iadd3")->fid());
|
||||
}
|
||||
CHECK("iadd2" == registry.get_function_by_name("vmath::iadd2")->id());
|
||||
CHECK("iadd3" == registry.get_function_by_name("vmath::iadd3")->id());
|
||||
}
|
||||
|
||||
SUBCASE("resolve/method") {
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec2::dot)>());
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec3::dot)>());
|
||||
CHECK_FALSE(registry.resolve(&ivec2::dot));
|
||||
CHECK_FALSE(registry.resolve(&ivec3::dot));
|
||||
|
||||
const meta::method_info v2_dot_info = meta::method_<&ivec2::dot>("dot");
|
||||
const meta::method_info v3_dot_info = meta::method_<&ivec3::dot>("dot");
|
||||
CHECK(v2_dot_info.fid() != v3_dot_info.fid());
|
||||
|
||||
CHECK(v2_dot_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec2::dot)>()->get_method()->fid());
|
||||
CHECK(v3_dot_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec3::dot)>()->get_method()->fid());
|
||||
|
||||
{
|
||||
REQUIRE(registry.get_method_by_name("vmath::ivec2::dot"));
|
||||
REQUIRE(registry.get_method_by_name("vmath::ivec3::dot"));
|
||||
|
||||
CHECK(v2_dot_info.fid() == registry.get_method_by_name("vmath::ivec2::dot")->fid());
|
||||
CHECK(v3_dot_info.fid() == registry.get_method_by_name("vmath::ivec3::dot")->fid());
|
||||
}
|
||||
CHECK("dot" == registry.get_method_by_name("vmath::ivec2::dot")->id());
|
||||
CHECK("dot" == registry.get_method_by_name("vmath::ivec3::dot")->id());
|
||||
}
|
||||
|
||||
SUBCASE("resolve/variable") {
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec2::zero)>());
|
||||
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec3::zero)>());
|
||||
CHECK_FALSE(registry.resolve(&ivec2::zero));
|
||||
CHECK_FALSE(registry.resolve(&ivec3::zero));
|
||||
|
||||
const meta::variable_info v2_zero_info = meta::variable_<&ivec2::zero>("zero");
|
||||
const meta::variable_info v3_zero_info = meta::variable_<&ivec3::zero>("zero");
|
||||
CHECK(v2_zero_info.fid() != v3_zero_info.fid());
|
||||
|
||||
CHECK(v2_zero_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec2::zero)>()->get_variable()->fid());
|
||||
CHECK(v3_zero_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec3::zero)>()->get_variable()->fid());
|
||||
|
||||
{
|
||||
REQUIRE(registry.get_variable_by_name("vmath::ivec2::zero"));
|
||||
REQUIRE(registry.get_variable_by_name("vmath::ivec3::zero"));
|
||||
|
||||
CHECK(v2_zero_info.fid() == registry.get_variable_by_name("vmath::ivec2::zero")->fid());
|
||||
CHECK(v3_zero_info.fid() == registry.get_variable_by_name("vmath::ivec3::zero")->fid());
|
||||
}
|
||||
CHECK("zero" == registry.get_variable_by_name("vmath::ivec2::zero")->id());
|
||||
CHECK("zero" == registry.get_variable_by_name("vmath::ivec3::zero")->id());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user