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