mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 03:45:30 +07:00
get internals from info
This commit is contained in:
@@ -50,6 +50,13 @@ namespace meta_hpp
|
||||
|
||||
template < typename F >
|
||||
void each_method(F&& f) const;
|
||||
|
||||
class_info get_class_by_name(std::string_view name) const noexcept;
|
||||
data_info get_data_by_name(std::string_view name) const noexcept;
|
||||
enum_info get_enum_by_name(std::string_view name) const noexcept;
|
||||
function_info get_function_by_name(std::string_view name) const noexcept;
|
||||
member_info get_member_by_name(std::string_view name) const noexcept;
|
||||
method_info get_method_by_name(std::string_view name) const noexcept;
|
||||
private:
|
||||
template < typename Class > friend class class_;
|
||||
|
||||
@@ -157,6 +164,30 @@ namespace meta_hpp
|
||||
std::invoke(f, name_info.second);
|
||||
}
|
||||
}
|
||||
|
||||
inline class_info class_info::get_class_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->classes, name);
|
||||
}
|
||||
|
||||
inline data_info class_info::get_data_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->datas, name);
|
||||
}
|
||||
|
||||
inline enum_info class_info::get_enum_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->enums, name);
|
||||
}
|
||||
|
||||
inline function_info class_info::get_function_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->functions, name);
|
||||
}
|
||||
|
||||
inline member_info class_info::get_member_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->members, name);
|
||||
}
|
||||
|
||||
inline method_info class_info::get_method_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->methods, name);
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
|
||||
@@ -26,6 +26,8 @@ namespace meta_hpp
|
||||
|
||||
template < typename F >
|
||||
void each_data(F&& f) const;
|
||||
|
||||
data_info get_data_by_name(std::string_view name) const noexcept;
|
||||
private:
|
||||
template < typename... Args > friend class ctor_;
|
||||
|
||||
@@ -74,6 +76,10 @@ namespace meta_hpp
|
||||
std::invoke(f, name_info.second);
|
||||
}
|
||||
}
|
||||
|
||||
inline data_info ctor_info::get_data_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->datas, name);
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace meta_hpp
|
||||
|
||||
template < typename F >
|
||||
void each_data(F&& f) const;
|
||||
|
||||
data_info get_data_by_name(std::string_view name) const noexcept;
|
||||
private:
|
||||
friend class data_;
|
||||
|
||||
@@ -77,6 +79,10 @@ namespace meta_hpp
|
||||
std::invoke(f, name_info.second);
|
||||
}
|
||||
}
|
||||
|
||||
inline data_info data_info::get_data_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->datas, name);
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
|
||||
@@ -31,6 +31,9 @@ namespace meta_hpp
|
||||
|
||||
template < typename F >
|
||||
void each_evalue(F&& f) const;
|
||||
|
||||
data_info get_data_by_name(std::string_view name) const noexcept;
|
||||
evalue_info get_evalue_by_name(std::string_view name) const noexcept;
|
||||
private:
|
||||
template < typename Enum > friend class enum_;
|
||||
|
||||
@@ -93,6 +96,14 @@ namespace meta_hpp
|
||||
std::invoke(f, name_info.second);
|
||||
}
|
||||
}
|
||||
|
||||
inline data_info enum_info::get_data_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->datas, name);
|
||||
}
|
||||
|
||||
inline evalue_info enum_info::get_evalue_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->evalues, name);
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace meta_hpp
|
||||
|
||||
template < typename F >
|
||||
void each_data(F&& f) const;
|
||||
|
||||
data_info get_data_by_name(std::string_view name) const noexcept;
|
||||
private:
|
||||
template < typename Enum > friend class evalue_;
|
||||
|
||||
@@ -80,6 +82,10 @@ namespace meta_hpp
|
||||
std::invoke(f, name_info.second);
|
||||
}
|
||||
}
|
||||
|
||||
inline data_info evalue_info::get_data_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->datas, name);
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace meta_hpp
|
||||
|
||||
template < typename F >
|
||||
void each_data(F&& f) const;
|
||||
|
||||
data_info get_data_by_name(std::string_view name) const noexcept;
|
||||
private:
|
||||
template < typename Function > friend class function_;
|
||||
|
||||
@@ -80,6 +82,10 @@ namespace meta_hpp
|
||||
std::invoke(f, name_info.second);
|
||||
}
|
||||
}
|
||||
|
||||
inline data_info function_info::get_data_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->datas, name);
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace meta_hpp
|
||||
|
||||
template < typename F >
|
||||
void each_data(F&& f) const;
|
||||
|
||||
data_info get_data_by_name(std::string_view name) const noexcept;
|
||||
private:
|
||||
template < typename Member > friend class member_;
|
||||
|
||||
@@ -80,6 +82,10 @@ namespace meta_hpp
|
||||
std::invoke(f, name_info.second);
|
||||
}
|
||||
}
|
||||
|
||||
inline data_info member_info::get_data_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->datas, name);
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace meta_hpp
|
||||
|
||||
template < typename F >
|
||||
void each_data(F&& f) const;
|
||||
|
||||
data_info get_data_by_name(std::string_view name) const noexcept;
|
||||
private:
|
||||
template < typename Method > friend class method_;
|
||||
|
||||
@@ -80,6 +82,10 @@ namespace meta_hpp
|
||||
std::invoke(f, name_info.second);
|
||||
}
|
||||
}
|
||||
|
||||
inline data_info method_info::get_data_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->datas, name);
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
|
||||
@@ -41,6 +41,12 @@ namespace meta_hpp
|
||||
|
||||
template < typename F >
|
||||
void each_namespace(F&& f) const;
|
||||
|
||||
class_info get_class_by_name(std::string_view name) const noexcept;
|
||||
data_info get_data_by_name(std::string_view name) const noexcept;
|
||||
enum_info get_enum_by_name(std::string_view name) const noexcept;
|
||||
function_info get_function_by_name(std::string_view name) const noexcept;
|
||||
namespace_info get_namespace_by_name(std::string_view name) const noexcept;
|
||||
private:
|
||||
friend class namespace_;
|
||||
|
||||
@@ -124,6 +130,26 @@ namespace meta_hpp
|
||||
std::invoke(f, name_info.second);
|
||||
}
|
||||
}
|
||||
|
||||
inline class_info namespace_info::get_class_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->classes, name);
|
||||
}
|
||||
|
||||
inline data_info namespace_info::get_data_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->datas, name);
|
||||
}
|
||||
|
||||
inline enum_info namespace_info::get_enum_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->enums, name);
|
||||
}
|
||||
|
||||
inline function_info namespace_info::get_function_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->functions, name);
|
||||
}
|
||||
|
||||
inline namespace_info namespace_info::get_namespace_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(state_->namespaces, name);
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
|
||||
@@ -24,14 +24,14 @@ namespace meta_hpp
|
||||
public:
|
||||
registry() = default;
|
||||
|
||||
class_info get_class_by_name(std::string_view name) const noexcept;
|
||||
data_info get_data_by_name(std::string_view name) const noexcept;
|
||||
enum_info get_enum_by_name(std::string_view name) const noexcept;
|
||||
evalue_info get_evalue_by_name(std::string_view name) const noexcept;
|
||||
function_info get_function_by_name(std::string_view name) const noexcept;
|
||||
member_info get_member_by_name(std::string_view name) const noexcept;
|
||||
method_info get_method_by_name(std::string_view name) const noexcept;
|
||||
namespace_info get_namespace_by_name(std::string_view name) const noexcept;
|
||||
class_info get_class_by_path(std::string_view path) const noexcept;
|
||||
data_info get_data_by_path(std::string_view path) const noexcept;
|
||||
enum_info get_enum_by_path(std::string_view path) const noexcept;
|
||||
evalue_info get_evalue_by_path(std::string_view path) const noexcept;
|
||||
function_info get_function_by_path(std::string_view path) const noexcept;
|
||||
member_info get_member_by_path(std::string_view path) const noexcept;
|
||||
method_info get_method_by_path(std::string_view path) const noexcept;
|
||||
namespace_info get_namespace_by_path(std::string_view path) const noexcept;
|
||||
public:
|
||||
template < typename... Internals >
|
||||
registry& operator()(Internals&&... internals);
|
||||
@@ -75,36 +75,36 @@ namespace meta_hpp
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
inline class_info registry::get_class_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(classes_, name);
|
||||
inline class_info registry::get_class_by_path(std::string_view path) const noexcept {
|
||||
return detail::find_or_default(classes_, path);
|
||||
}
|
||||
|
||||
inline data_info registry::get_data_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(datas_, name);
|
||||
inline data_info registry::get_data_by_path(std::string_view path) const noexcept {
|
||||
return detail::find_or_default(datas_, path);
|
||||
}
|
||||
|
||||
inline enum_info registry::get_enum_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(enums_, name);
|
||||
inline enum_info registry::get_enum_by_path(std::string_view path) const noexcept {
|
||||
return detail::find_or_default(enums_, path);
|
||||
}
|
||||
|
||||
inline evalue_info registry::get_evalue_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(evalues_, name);
|
||||
inline evalue_info registry::get_evalue_by_path(std::string_view path) const noexcept {
|
||||
return detail::find_or_default(evalues_, path);
|
||||
}
|
||||
|
||||
inline function_info registry::get_function_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(functions_, name);
|
||||
inline function_info registry::get_function_by_path(std::string_view path) const noexcept {
|
||||
return detail::find_or_default(functions_, path);
|
||||
}
|
||||
|
||||
inline member_info registry::get_member_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(members_, name);
|
||||
inline member_info registry::get_member_by_path(std::string_view path) const noexcept {
|
||||
return detail::find_or_default(members_, path);
|
||||
}
|
||||
|
||||
inline method_info registry::get_method_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(methods_, name);
|
||||
inline method_info registry::get_method_by_path(std::string_view path) const noexcept {
|
||||
return detail::find_or_default(methods_, path);
|
||||
}
|
||||
|
||||
inline namespace_info registry::get_namespace_by_name(std::string_view name) const noexcept {
|
||||
return detail::find_or_default(namespaces_, name);
|
||||
inline namespace_info registry::get_namespace_by_path(std::string_view path) const noexcept {
|
||||
return detail::find_or_default(namespaces_, path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,5 +19,28 @@ namespace meta_hpp
|
||||
|
||||
value(const value&) = default;
|
||||
value& operator=(const value&) = default;
|
||||
|
||||
template < typename T, typename Tp = std::decay_t<T>
|
||||
, std::enable_if_t<!std::is_same_v<Tp, value>, int> = 0 >
|
||||
value(T&& val)
|
||||
: raw_{std::forward<T>(val)} {}
|
||||
|
||||
template < typename T, typename Tp = std::decay_t<T>
|
||||
, std::enable_if_t<!std::is_same_v<Tp, value>, int> = 0 >
|
||||
value& operator=(T&& val) {
|
||||
value{std::forward<T>(val)}.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(value& other) noexcept {
|
||||
using std::swap;
|
||||
swap(raw_, other.raw_);
|
||||
}
|
||||
private:
|
||||
std::any raw_{};
|
||||
};
|
||||
|
||||
inline void swap(value& l, value& r) noexcept {
|
||||
l.swap(r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ TEST_CASE("features/infos/function") {
|
||||
function_{"arg_crref", &arg_crref}
|
||||
);
|
||||
|
||||
const function_info arg_copy_info = db.get_function_by_name("arg_copy");
|
||||
const function_info arg_ref_info = db.get_function_by_name("arg_ref");
|
||||
const function_info arg_cref_info = db.get_function_by_name("arg_cref");
|
||||
const function_info arg_rref_info = db.get_function_by_name("arg_rref");
|
||||
const function_info arg_crref_info = db.get_function_by_name("arg_crref");
|
||||
const function_info arg_not_exist_info = db.get_function_by_name("arg_not_exist");
|
||||
const function_info arg_copy_info = db.get_function_by_path("arg_copy");
|
||||
const function_info arg_ref_info = db.get_function_by_path("arg_ref");
|
||||
const function_info arg_cref_info = db.get_function_by_path("arg_cref");
|
||||
const function_info arg_rref_info = db.get_function_by_path("arg_rref");
|
||||
const function_info arg_crref_info = db.get_function_by_path("arg_crref");
|
||||
const function_info arg_not_exist_info = db.get_function_by_path("arg_not_exist");
|
||||
|
||||
REQUIRE(arg_copy_info);
|
||||
REQUIRE(arg_ref_info);
|
||||
|
||||
9
untests/features/registry/_registry_fwd.hpp
Normal file
9
untests/features/registry/_registry_fwd.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../meta_tests.hpp"
|
||||
70
untests/features/registry/registry_tests.cpp
Normal file
70
untests/features/registry/registry_tests.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "_registry_fwd.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace meta_hpp;
|
||||
using namespace std::string_literals;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ivec2 {
|
||||
int x{};
|
||||
int y{};
|
||||
|
||||
[[maybe_unused]] ivec2() = default;
|
||||
[[maybe_unused]] explicit ivec2(int v): x{v}, y{v} {}
|
||||
[[maybe_unused]] ivec2(int x, int y): x{x}, y{y} {}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("features/registry/registry") {
|
||||
auto db = registry{}(
|
||||
namespace_{"vmath"}(data_{"info", "vmath namespace"},
|
||||
class_<ivec2>{"ivec2"}(data_{"info", "ivec2 class"},
|
||||
ctor_<>{},
|
||||
ctor_<int>{},
|
||||
ctor_<int, int>{},
|
||||
member_{"x", &ivec2::x}(data_{"info", "x-coord"}),
|
||||
member_{"y", &ivec2::y}(data_{"info", "y-coord"})
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
{
|
||||
const namespace_info vmath_info = db.get_namespace_by_path("vmath");
|
||||
REQUIRE(vmath_info);
|
||||
CHECK(vmath_info.name() == "vmath");
|
||||
CHECK(vmath_info.get_data_by_name("info"));
|
||||
|
||||
const class_info ivec2_info = vmath_info.get_class_by_name("ivec2");
|
||||
REQUIRE(ivec2_info);
|
||||
CHECK(ivec2_info.name() == "ivec2");
|
||||
CHECK(ivec2_info.get_data_by_name("info"));
|
||||
|
||||
const member_info ivec2_x_info = ivec2_info.get_member_by_name("x");
|
||||
REQUIRE(ivec2_x_info);
|
||||
CHECK(ivec2_x_info.name() == "x");
|
||||
CHECK(ivec2_x_info.get_data_by_name("info"));
|
||||
}
|
||||
|
||||
{
|
||||
const class_info ivec2_info = db.get_class_by_path("vmath::ivec2");
|
||||
REQUIRE(ivec2_info);
|
||||
CHECK(ivec2_info.name() == "ivec2");
|
||||
|
||||
const member_info ivec2_x_info = db.get_member_by_path("vmath::ivec2::x");
|
||||
REQUIRE(ivec2_x_info);
|
||||
CHECK(ivec2_x_info.name() == "x");
|
||||
|
||||
const data_info ivec2_x_data_info = db.get_data_by_path("vmath::ivec2::x::info");
|
||||
REQUIRE(ivec2_x_data_info);
|
||||
CHECK(ivec2_x_data_info.name() == "info");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user