mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-14 11:40:35 +07:00
family id for infos
This commit is contained in:
@@ -22,7 +22,7 @@ namespace meta_hpp
|
||||
class class_ {
|
||||
public:
|
||||
explicit class_(std::string id)
|
||||
: info_(std::move(id)) {}
|
||||
: info_{get_family_id<Class>(), std::move(id)} {}
|
||||
|
||||
const class_info& info() const noexcept {
|
||||
return info_;
|
||||
|
||||
@@ -27,9 +27,14 @@ namespace meta_hpp
|
||||
class_info& operator=(class_info&&) = default;
|
||||
class_info& operator=(const class_info&) = default;
|
||||
|
||||
class_info(std::string id)
|
||||
: id_(std::move(id)) {}
|
||||
class_info(family_id fid, std::string id)
|
||||
: fid_(std::move(fid))
|
||||
, id_(std::move(id)) {}
|
||||
public:
|
||||
const family_id& fid() const noexcept {
|
||||
return fid_;
|
||||
}
|
||||
|
||||
const std::string& id() const noexcept {
|
||||
return id_;
|
||||
}
|
||||
@@ -114,6 +119,7 @@ namespace meta_hpp
|
||||
detail::merge_with(variables_, other.variables_, &variable_info::merge_with_);
|
||||
}
|
||||
private:
|
||||
family_id fid_;
|
||||
std::string id_;
|
||||
std::map<std::string, class_info, std::less<>> classes_;
|
||||
std::map<std::string, data_info, std::less<>> datas_;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace meta_hpp
|
||||
static_assert(std::is_member_object_pointer_v<decltype(Field)>);
|
||||
|
||||
explicit field_(std::string id)
|
||||
: info_(std::move(id)) {
|
||||
: info_{get_family_id<decltype(Field)>(), std::move(id)} {
|
||||
info_.getter_ = &field_detail::getter<Field>;
|
||||
info_.setter_ = &field_detail::setter<Field>;
|
||||
}
|
||||
|
||||
@@ -68,9 +68,14 @@ namespace meta_hpp
|
||||
field_info& operator=(field_info&&) = default;
|
||||
field_info& operator=(const field_info&) = default;
|
||||
|
||||
field_info(std::string id)
|
||||
: id_(std::move(id)) {}
|
||||
field_info(family_id fid, std::string id)
|
||||
: fid_(std::move(fid))
|
||||
, id_(std::move(id)) {}
|
||||
public:
|
||||
const family_id& fid() const noexcept {
|
||||
return fid_;
|
||||
}
|
||||
|
||||
const std::string& id() const noexcept {
|
||||
return id_;
|
||||
}
|
||||
@@ -105,6 +110,7 @@ namespace meta_hpp
|
||||
detail::merge_with(datas_, other.datas_, &data_info::merge_with_);
|
||||
}
|
||||
private:
|
||||
family_id fid_;
|
||||
std::string id_;
|
||||
value(*getter_)(const void*);
|
||||
void(*setter_)(void*, value);
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace meta_hpp
|
||||
static_assert(std::is_function_v<std::remove_pointer_t<decltype(Function)>>);
|
||||
|
||||
explicit function_(std::string id)
|
||||
: info_(std::move(id)) {
|
||||
: info_{get_family_id<decltype(Function)>(), std::move(id)} {
|
||||
info_.invoke_ = &function_detail::invoke<Function>;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,9 +75,14 @@ namespace meta_hpp
|
||||
function_info& operator=(function_info&&) = default;
|
||||
function_info& operator=(const function_info&) = default;
|
||||
|
||||
function_info(std::string id)
|
||||
: id_(std::move(id)) {}
|
||||
function_info(family_id fid, std::string id)
|
||||
: fid_(std::move(fid))
|
||||
, id_(std::move(id)) {}
|
||||
public:
|
||||
const family_id& fid() const noexcept {
|
||||
return fid_;
|
||||
}
|
||||
|
||||
const std::string& id() const noexcept {
|
||||
return id_;
|
||||
}
|
||||
@@ -112,6 +117,7 @@ namespace meta_hpp
|
||||
detail::merge_with(datas_, other.datas_, &data_info::merge_with_);
|
||||
}
|
||||
private:
|
||||
family_id fid_;
|
||||
std::string id_;
|
||||
value(*invoke_)(value*, std::size_t);
|
||||
std::map<std::string, data_info, std::less<>> datas_;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <any>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
@@ -44,6 +45,48 @@ namespace meta_hpp
|
||||
template < auto Variable > class variable_;
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
struct family_id {
|
||||
using underlying_type = std::size_t;
|
||||
underlying_type id{};
|
||||
|
||||
friend bool operator<(family_id l, family_id r) noexcept {
|
||||
return l.id < r.id;
|
||||
}
|
||||
};
|
||||
|
||||
namespace family_id_detail
|
||||
{
|
||||
template < typename Void = void >
|
||||
class type_family_base {
|
||||
static_assert(
|
||||
std::is_void_v<Void>,
|
||||
"unexpected internal error");
|
||||
protected:
|
||||
static family_id::underlying_type last_id_;
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
class type_family final : public type_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 Void >
|
||||
family_id::underlying_type type_family_base<Void>::last_id_{};
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
family_id get_family_id() noexcept {
|
||||
return family_id_detail::type_family<T>::id();
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
template < typename Signature >
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace meta_hpp
|
||||
static_assert(std::is_member_function_pointer_v<decltype(Method)>);
|
||||
|
||||
explicit method_(std::string id)
|
||||
: info_(std::move(id)) {
|
||||
: info_{get_family_id<decltype(Method)>(), std::move(id)} {
|
||||
info_.invoke_ = &method_detail::invoke<Method>;
|
||||
info_.cinvoke_ = &method_detail::cinvoke<Method>;
|
||||
}
|
||||
|
||||
@@ -132,9 +132,14 @@ namespace meta_hpp
|
||||
method_info& operator=(method_info&&) = default;
|
||||
method_info& operator=(const method_info&) = default;
|
||||
|
||||
method_info(std::string id)
|
||||
: id_(std::move(id)) {}
|
||||
method_info(family_id fid, std::string id)
|
||||
: fid_(std::move(fid))
|
||||
, id_(std::move(id)) {}
|
||||
public:
|
||||
const family_id& fid() const noexcept {
|
||||
return fid_;
|
||||
}
|
||||
|
||||
const std::string& id() const noexcept {
|
||||
return id_;
|
||||
}
|
||||
@@ -171,6 +176,7 @@ namespace meta_hpp
|
||||
detail::merge_with(datas_, other.datas_, &data_info::merge_with_);
|
||||
}
|
||||
private:
|
||||
family_id fid_;
|
||||
std::string id_;
|
||||
value(*invoke_)(void*, value*, std::size_t);
|
||||
value(*cinvoke_)(const void*, value*, std::size_t);
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace meta_hpp
|
||||
class variable_ {
|
||||
public:
|
||||
explicit variable_(std::string id)
|
||||
: info_(std::move(id)) {
|
||||
: info_{get_family_id<decltype(Variable)>(), std::move(id)} {
|
||||
info_.getter_ = &variable_detail::getter<Variable>;
|
||||
info_.setter_ = &variable_detail::setter<Variable>;
|
||||
}
|
||||
|
||||
@@ -63,9 +63,14 @@ namespace meta_hpp
|
||||
variable_info& operator=(variable_info&&) = default;
|
||||
variable_info& operator=(const variable_info&) = default;
|
||||
|
||||
variable_info(std::string id)
|
||||
: id_(std::move(id)) {}
|
||||
variable_info(family_id fid, std::string id)
|
||||
: fid_(std::move(fid))
|
||||
, id_(std::move(id)) {}
|
||||
public:
|
||||
const family_id& fid() const noexcept {
|
||||
return fid_;
|
||||
}
|
||||
|
||||
const std::string& id() const noexcept {
|
||||
return id_;
|
||||
}
|
||||
@@ -103,6 +108,7 @@ namespace meta_hpp
|
||||
detail::merge_with(datas_, other.datas_, &data_info::merge_with_);
|
||||
}
|
||||
private:
|
||||
family_id fid_;
|
||||
std::string id_;
|
||||
value(*getter_)();
|
||||
void(*setter_)(value);
|
||||
|
||||
Reference in New Issue
Block a user