mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-16 22:17:02 +07:00
less work in registry classes
This commit is contained in:
@@ -22,11 +22,7 @@ namespace meta_hpp
|
|||||||
class class_ {
|
class class_ {
|
||||||
public:
|
public:
|
||||||
explicit class_(std::string id)
|
explicit class_(std::string id)
|
||||||
: info_{get_family_id<Class>(), std::move(id)} {}
|
: info_{detail::typename_arg<Class>, std::move(id)} {}
|
||||||
|
|
||||||
const class_info& info() const noexcept {
|
|
||||||
return info_;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator const class_info&() const noexcept {
|
operator const class_info&() const noexcept {
|
||||||
return info_;
|
return info_;
|
||||||
|
|||||||
@@ -116,8 +116,9 @@ namespace meta_hpp
|
|||||||
template < typename Class >
|
template < typename Class >
|
||||||
friend class class_;
|
friend class class_;
|
||||||
|
|
||||||
class_info(family_id fid, std::string id)
|
template < typename Class >
|
||||||
: fid_{std::move(fid)}
|
class_info(detail::typename_arg_t<Class>, std::string id)
|
||||||
|
: fid_{get_family_id<Class>()}
|
||||||
, id_{std::move(id)} {}
|
, id_{std::move(id)} {}
|
||||||
private:
|
private:
|
||||||
family_id fid_;
|
family_id fid_;
|
||||||
|
|||||||
@@ -15,11 +15,7 @@ namespace meta_hpp
|
|||||||
class data_ {
|
class data_ {
|
||||||
public:
|
public:
|
||||||
explicit data_(std::string id, value value)
|
explicit data_(std::string id, value value)
|
||||||
: info_(std::move(id), std::move(value)) {}
|
: info_{std::move(id), std::move(value)} {}
|
||||||
|
|
||||||
const data_info& info() const noexcept {
|
|
||||||
return info_;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator const data_info&() const noexcept {
|
operator const data_info&() const noexcept {
|
||||||
return info_;
|
return info_;
|
||||||
|
|||||||
@@ -20,14 +20,7 @@ namespace meta_hpp
|
|||||||
static_assert(std::is_member_object_pointer_v<decltype(Field)>);
|
static_assert(std::is_member_object_pointer_v<decltype(Field)>);
|
||||||
|
|
||||||
explicit field_(std::string id)
|
explicit field_(std::string id)
|
||||||
: info_{get_family_id<decltype(Field)>(), std::move(id)} {
|
: info_{detail::auto_arg<Field>, std::move(id)} {}
|
||||||
info_.getter_ = &field_detail::getter<Field>;
|
|
||||||
info_.setter_ = &field_detail::setter<Field>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const field_info& info() const noexcept {
|
|
||||||
return info_;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator const field_info&() const noexcept {
|
operator const field_info&() const noexcept {
|
||||||
return info_;
|
return info_;
|
||||||
|
|||||||
@@ -105,9 +105,12 @@ namespace meta_hpp
|
|||||||
template < auto Field >
|
template < auto Field >
|
||||||
friend class field_;
|
friend class field_;
|
||||||
|
|
||||||
field_info(family_id fid, std::string id)
|
template < typename FieldType, FieldType Field >
|
||||||
: fid_{std::move(fid)}
|
field_info(detail::auto_arg_t<Field>, std::string id)
|
||||||
, id_{std::move(id)} {}
|
: fid_{get_family_id<FieldType>()}
|
||||||
|
, id_{std::move(id)}
|
||||||
|
, getter_{&field_detail::getter<Field>}
|
||||||
|
, setter_{&field_detail::setter<Field>} {}
|
||||||
private:
|
private:
|
||||||
family_id fid_;
|
family_id fid_;
|
||||||
std::string id_;
|
std::string id_;
|
||||||
|
|||||||
@@ -20,13 +20,7 @@ namespace meta_hpp
|
|||||||
static_assert(std::is_function_v<std::remove_pointer_t<decltype(Function)>>);
|
static_assert(std::is_function_v<std::remove_pointer_t<decltype(Function)>>);
|
||||||
|
|
||||||
explicit function_(std::string id)
|
explicit function_(std::string id)
|
||||||
: info_{get_family_id<decltype(Function)>(), std::move(id)} {
|
: info_{detail::auto_arg<Function>, std::move(id)} {}
|
||||||
info_.invoke_ = &function_detail::invoke<Function>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const function_info& info() const noexcept {
|
|
||||||
return info_;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator const function_info&() const noexcept {
|
operator const function_info&() const noexcept {
|
||||||
return info_;
|
return info_;
|
||||||
|
|||||||
@@ -110,9 +110,11 @@ namespace meta_hpp
|
|||||||
template < auto Function >
|
template < auto Function >
|
||||||
friend class function_;
|
friend class function_;
|
||||||
|
|
||||||
function_info(family_id fid, std::string id)
|
template < typename FunctionType, FunctionType Function >
|
||||||
: fid_{std::move(fid)}
|
function_info(detail::auto_arg_t<Function>, std::string id)
|
||||||
, id_{std::move(id)} {}
|
: fid_{get_family_id<FunctionType>()}
|
||||||
|
, id_{std::move(id)}
|
||||||
|
, invoke_{&function_detail::invoke<Function>} {}
|
||||||
private:
|
private:
|
||||||
family_id fid_;
|
family_id fid_;
|
||||||
std::string id_;
|
std::string id_;
|
||||||
|
|||||||
@@ -22,30 +22,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
namespace meta_hpp
|
|
||||||
{
|
|
||||||
class value;
|
|
||||||
|
|
||||||
class registry;
|
|
||||||
class type;
|
|
||||||
|
|
||||||
class class_info;
|
|
||||||
class data_info;
|
|
||||||
class field_info;
|
|
||||||
class function_info;
|
|
||||||
class method_info;
|
|
||||||
class namespace_info;
|
|
||||||
class variable_info;
|
|
||||||
|
|
||||||
template < typename Class > class class_;
|
|
||||||
class data_;
|
|
||||||
template < auto Field > class field_;
|
|
||||||
template < auto Function > class function_;
|
|
||||||
template < auto Method > class method_;
|
|
||||||
class namespace_;
|
|
||||||
template < auto Variable > class variable_;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
{
|
{
|
||||||
struct family_id {
|
struct family_id {
|
||||||
@@ -119,6 +95,23 @@ namespace meta_hpp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace meta_hpp::detail
|
||||||
|
{
|
||||||
|
template < auto Arg >
|
||||||
|
struct auto_arg_t {
|
||||||
|
};
|
||||||
|
|
||||||
|
template < typename Arg >
|
||||||
|
struct typename_arg_t {
|
||||||
|
};
|
||||||
|
|
||||||
|
template < auto Arg >
|
||||||
|
inline auto_arg_t<Arg> auto_arg;
|
||||||
|
|
||||||
|
template < typename Arg >
|
||||||
|
inline typename_arg_t<Arg> typename_arg;
|
||||||
|
}
|
||||||
|
|
||||||
namespace meta_hpp::detail
|
namespace meta_hpp::detail
|
||||||
{
|
{
|
||||||
template < typename K, typename V, typename C, typename K2 >
|
template < typename K, typename V, typename C, typename K2 >
|
||||||
|
|||||||
@@ -20,14 +20,7 @@ namespace meta_hpp
|
|||||||
static_assert(std::is_member_function_pointer_v<decltype(Method)>);
|
static_assert(std::is_member_function_pointer_v<decltype(Method)>);
|
||||||
|
|
||||||
explicit method_(std::string id)
|
explicit method_(std::string id)
|
||||||
: info_{get_family_id<decltype(Method)>(), std::move(id)} {
|
: info_{detail::auto_arg<Method>, std::move(id)} {}
|
||||||
info_.invoke_ = &method_detail::invoke<Method>;
|
|
||||||
info_.cinvoke_ = &method_detail::cinvoke<Method>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const method_info& info() const noexcept {
|
|
||||||
return info_;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator const method_info&() const {
|
operator const method_info&() const {
|
||||||
return info_;
|
return info_;
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ namespace meta_hpp
|
|||||||
const std::string& id() const noexcept {
|
const std::string& id() const noexcept {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename... Args >
|
template < typename... Args >
|
||||||
value invoke(void* instance, Args&&... args) const {
|
value invoke(void* instance, Args&&... args) const {
|
||||||
std::array<value, sizeof...(Args)> vargs{{std::forward<Args>(args)...}};
|
std::array<value, sizeof...(Args)> vargs{{std::forward<Args>(args)...}};
|
||||||
@@ -172,9 +173,12 @@ namespace meta_hpp
|
|||||||
template < auto Method >
|
template < auto Method >
|
||||||
friend class method_;
|
friend class method_;
|
||||||
|
|
||||||
method_info(family_id fid, std::string id)
|
template < typename MethodType, MethodType Method >
|
||||||
: fid_{std::move(fid)}
|
method_info(detail::auto_arg_t<Method>, std::string id)
|
||||||
, id_{std::move(id)} {}
|
: fid_{get_family_id<MethodType>()}
|
||||||
|
, id_{std::move(id)}
|
||||||
|
, invoke_{&method_detail::invoke<Method>}
|
||||||
|
, cinvoke_{&method_detail::cinvoke<Method>} {}
|
||||||
private:
|
private:
|
||||||
family_id fid_;
|
family_id fid_;
|
||||||
std::string id_;
|
std::string id_;
|
||||||
|
|||||||
@@ -20,11 +20,7 @@ namespace meta_hpp
|
|||||||
class namespace_ {
|
class namespace_ {
|
||||||
public:
|
public:
|
||||||
explicit namespace_(std::string id)
|
explicit namespace_(std::string id)
|
||||||
: info_(std::move(id)) {}
|
: info_{std::move(id)} {}
|
||||||
|
|
||||||
const namespace_info& info() const noexcept {
|
|
||||||
return info_;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator const namespace_info&() const noexcept {
|
operator const namespace_info&() const noexcept {
|
||||||
return info_;
|
return info_;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace meta_hpp
|
|||||||
|
|
||||||
template < typename Info >
|
template < typename Info >
|
||||||
type(Info&& info)
|
type(Info&& info)
|
||||||
: info_(std::forward<Info>(info)) {}
|
: info_{std::forward<Info>(info)} {}
|
||||||
|
|
||||||
bool is_class() const noexcept { return std::holds_alternative<class_info>(info_); }
|
bool is_class() const noexcept { return std::holds_alternative<class_info>(info_); }
|
||||||
bool is_field() const noexcept { return std::holds_alternative<field_info>(info_); }
|
bool is_field() const noexcept { return std::holds_alternative<field_info>(info_); }
|
||||||
|
|||||||
@@ -18,14 +18,7 @@ namespace meta_hpp
|
|||||||
class variable_ {
|
class variable_ {
|
||||||
public:
|
public:
|
||||||
explicit variable_(std::string id)
|
explicit variable_(std::string id)
|
||||||
: info_{get_family_id<decltype(Variable)>(), std::move(id)} {
|
: info_{detail::auto_arg<Variable>, std::move(id)} {}
|
||||||
info_.getter_ = &variable_detail::getter<Variable>;
|
|
||||||
info_.setter_ = &variable_detail::setter<Variable>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const variable_info& info() const noexcept {
|
|
||||||
return info_;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator const variable_info&() const noexcept {
|
operator const variable_info&() const noexcept {
|
||||||
return info_;
|
return info_;
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ namespace meta_hpp
|
|||||||
const std::string& id() const noexcept {
|
const std::string& id() const noexcept {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
value get() const {
|
value get() const {
|
||||||
return getter_();
|
return getter_();
|
||||||
}
|
}
|
||||||
@@ -100,9 +101,12 @@ namespace meta_hpp
|
|||||||
template < auto Variable >
|
template < auto Variable >
|
||||||
friend class variable_;
|
friend class variable_;
|
||||||
|
|
||||||
variable_info(family_id fid, std::string id)
|
template < typename VariableType, VariableType Variable >
|
||||||
: fid_{std::move(fid)}
|
variable_info(detail::auto_arg_t<Variable>, std::string id)
|
||||||
, id_{std::move(id)} {}
|
: fid_{get_family_id<VariableType>()}
|
||||||
|
, id_{std::move(id)}
|
||||||
|
, getter_{&variable_detail::getter<Variable>}
|
||||||
|
, setter_{&variable_detail::setter<Variable>} {}
|
||||||
private:
|
private:
|
||||||
family_id fid_;
|
family_id fid_;
|
||||||
std::string id_;
|
std::string id_;
|
||||||
|
|||||||
Reference in New Issue
Block a user