mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 11:52:08 +07:00
static and local scopes
This commit is contained in:
@@ -57,7 +57,11 @@ namespace meta_hpp
|
||||
{
|
||||
class scope_bind final {
|
||||
public:
|
||||
explicit scope_bind(std::string_view name);
|
||||
struct local_tag {};
|
||||
struct static_tag {};
|
||||
|
||||
explicit scope_bind(std::string_view name, local_tag);
|
||||
explicit scope_bind(std::string_view name, static_tag);
|
||||
operator scope() const noexcept;
|
||||
|
||||
template < detail::class_kind Class >
|
||||
@@ -88,7 +92,11 @@ namespace meta_hpp
|
||||
return enum_bind<Enum>{};
|
||||
}
|
||||
|
||||
inline scope_bind scope_(std::string name) {
|
||||
return scope_bind{std::move(name)};
|
||||
inline scope_bind local_scope_(std::string name) {
|
||||
return scope_bind{std::move(name), scope_bind::local_tag()};
|
||||
}
|
||||
|
||||
inline scope_bind static_scope_(std::string name) {
|
||||
return scope_bind{std::move(name), scope_bind::static_tag()};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace meta_hpp
|
||||
{
|
||||
template < detail::class_kind Class >
|
||||
class_bind<Class>::class_bind()
|
||||
: data_{detail::get_type_data<Class>()} {}
|
||||
: data_{detail::class_type_data::get_static<Class>()} {}
|
||||
|
||||
template < detail::class_kind Class >
|
||||
class_bind<Class>::operator class_type() const noexcept {
|
||||
@@ -33,8 +33,7 @@ namespace meta_hpp
|
||||
template < detail::class_kind Base >
|
||||
class_bind<Class>& class_bind<Class>::base_() {
|
||||
static_assert(std::is_base_of_v<Base, Class>);
|
||||
auto base_data = detail::class_type_data::get<Base>();
|
||||
data_->bases.emplace(base_data);
|
||||
data_->bases.emplace(resolve_type<Base>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace meta_hpp
|
||||
{
|
||||
template < detail::enum_kind Enum >
|
||||
enum_bind<Enum>::enum_bind()
|
||||
: data_{detail::get_type_data<Enum>()} {}
|
||||
: data_{detail::enum_type_data::get_static<Enum>()} {}
|
||||
|
||||
template < detail::enum_kind Enum >
|
||||
enum_bind<Enum>::operator enum_type() const noexcept {
|
||||
|
||||
@@ -11,8 +11,11 @@
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
inline scope_bind::scope_bind(std::string_view name)
|
||||
: state_{detail::get_scope_state(name)} {}
|
||||
inline scope_bind::scope_bind(std::string_view name, local_tag)
|
||||
: state_{detail::scope_state::make(std::string{name})} {}
|
||||
|
||||
inline scope_bind::scope_bind(std::string_view name, static_tag)
|
||||
: state_{detail::scope_state::get_static(name)} {}
|
||||
|
||||
inline scope_bind::operator scope() const noexcept {
|
||||
return scope{state_};
|
||||
@@ -20,15 +23,13 @@ namespace meta_hpp
|
||||
|
||||
template < detail::class_kind Class >
|
||||
scope_bind& scope_bind::class_(std::string name) {
|
||||
auto class_data = detail::class_type_data::get<Class>();
|
||||
state_->classes.emplace(std::move(name), class_data);
|
||||
state_->classes.emplace(std::move(name), resolve_type<Class>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
template < detail::enum_kind Enum >
|
||||
scope_bind& scope_bind::enum_(std::string name) {
|
||||
auto enum_data = detail::enum_type_data::get<Enum>();
|
||||
state_->enums.emplace(std::move(name), enum_data);
|
||||
state_->enums.emplace(std::move(name), resolve_type<Enum>());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -295,7 +295,8 @@ namespace meta_hpp::detail
|
||||
function_map functions;
|
||||
variable_map variables;
|
||||
|
||||
static scope_state_ptr get(std::string_view name);
|
||||
static scope_state_ptr make(std::string name);
|
||||
static scope_state_ptr get_static(std::string_view name);
|
||||
|
||||
explicit scope_state(scope_index index);
|
||||
};
|
||||
@@ -319,14 +320,7 @@ namespace meta_hpp::detail
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
inline scope_state_ptr get_scope_state(std::string_view name) {
|
||||
return scope_state::get(name);
|
||||
}
|
||||
}
|
||||
|
||||
inline scope resolve_scope(std::string_view name) {
|
||||
return scope{detail::get_scope_state(name)};
|
||||
return scope{detail::scope_state::get_static(name)};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace meta_hpp::detail
|
||||
{
|
||||
template < class_kind Class, typename... Args >
|
||||
ctor_state_ptr ctor_state::make() {
|
||||
ctor_index index{ctor_type_data::get<Class, Args...>()};
|
||||
ctor_index index{ctor_type_data::get_static<Class, Args...>()};
|
||||
return std::make_shared<ctor_state>(std::move(index), type_list<Class>{}, type_list<Args...>{});
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace meta_hpp::detail
|
||||
{
|
||||
template < enum_kind Enum >
|
||||
evalue_state_ptr evalue_state::make(std::string name, Enum value) {
|
||||
evalue_index index{enum_type_data::get<Enum>(), std::move(name)};
|
||||
evalue_index index{enum_type_data::get_static<Enum>(), std::move(name)};
|
||||
return std::make_shared<evalue_state>(std::move(index), std::move(value));
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace meta_hpp::detail
|
||||
{
|
||||
template < function_kind Function >
|
||||
function_state_ptr function_state::make(std::string name, Function function) {
|
||||
function_index index{function_type_data::get<Function>(), std::move(name)};
|
||||
function_index index{function_type_data::get_static<Function>(), std::move(name)};
|
||||
return std::make_shared<function_state>(std::move(index), std::move(function));
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace meta_hpp::detail
|
||||
{
|
||||
template < member_kind Member >
|
||||
member_state_ptr member_state::make(std::string name, Member member) {
|
||||
member_index index{member_type_data::get<Member>(), std::move(name)};
|
||||
member_index index{member_type_data::get_static<Member>(), std::move(name)};
|
||||
return std::make_shared<member_state>(std::move(index), std::move(member));
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace meta_hpp::detail
|
||||
{
|
||||
template < method_kind Method >
|
||||
method_state_ptr method_state::make(std::string name, Method method) {
|
||||
method_index index{method_type_data::get<Method>(), std::move(name)};
|
||||
method_index index{method_type_data::get_static<Method>(), std::move(name)};
|
||||
return std::make_shared<method_state>(std::move(index), std::move(method));
|
||||
}
|
||||
|
||||
|
||||
@@ -11,15 +11,19 @@
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
inline scope_state_ptr scope_state::get(std::string_view name) {
|
||||
inline scope_state_ptr scope_state::make(std::string name) {
|
||||
scope_index index{std::move(name)};
|
||||
return std::make_shared<scope_state>(std::move(index));
|
||||
}
|
||||
|
||||
inline scope_state_ptr scope_state::get_static(std::string_view name) {
|
||||
static std::map<std::string, scope_state_ptr, std::less<>> states;
|
||||
|
||||
if ( auto iter = states.find(name); iter != states.end() ) {
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
auto state = std::make_shared<scope_state>(scope_index{std::string{name}});
|
||||
return states.emplace(std::string{name}, state).first->second;
|
||||
return states.emplace(std::string{name}, make(std::string{name})).first->second;
|
||||
}
|
||||
|
||||
inline scope_state::scope_state(scope_index index)
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace meta_hpp::detail
|
||||
{
|
||||
template < pointer_kind Pointer >
|
||||
variable_state_ptr variable_state::make(std::string name, Pointer pointer) {
|
||||
variable_index index{pointer_type_data::get<Pointer>(), std::move(name)};
|
||||
variable_index index{pointer_type_data::get_static<Pointer>(), std::move(name)};
|
||||
return std::make_shared<variable_state>(index, pointer);
|
||||
}
|
||||
|
||||
|
||||
@@ -421,7 +421,7 @@ namespace meta_hpp::detail
|
||||
const any_type data_type;
|
||||
|
||||
template < array_kind Array >
|
||||
static array_type_data_ptr get();
|
||||
static array_type_data_ptr get_static();
|
||||
|
||||
template < array_kind Array >
|
||||
explicit array_type_data(type_list<Array>);
|
||||
@@ -440,7 +440,7 @@ namespace meta_hpp::detail
|
||||
variable_map variables;
|
||||
|
||||
template < class_kind Class >
|
||||
static class_type_data_ptr get();
|
||||
static class_type_data_ptr get_static();
|
||||
|
||||
template < class_kind Class >
|
||||
explicit class_type_data(type_list<Class>);
|
||||
@@ -452,7 +452,7 @@ namespace meta_hpp::detail
|
||||
const std::vector<any_type> argument_types;
|
||||
|
||||
template < class_kind Class, typename... Args >
|
||||
static ctor_type_data_ptr get();
|
||||
static ctor_type_data_ptr get_static();
|
||||
|
||||
template < class_kind Class, typename... Args >
|
||||
explicit ctor_type_data(type_list<Class>, type_list<Args...>);
|
||||
@@ -465,7 +465,7 @@ namespace meta_hpp::detail
|
||||
evalue_map evalues;
|
||||
|
||||
template < enum_kind Enum >
|
||||
static enum_type_data_ptr get();
|
||||
static enum_type_data_ptr get_static();
|
||||
|
||||
template < enum_kind Enum >
|
||||
explicit enum_type_data(type_list<Enum>);
|
||||
@@ -477,7 +477,7 @@ namespace meta_hpp::detail
|
||||
const std::vector<any_type> argument_types;
|
||||
|
||||
template < function_kind Function >
|
||||
static function_type_data_ptr get();
|
||||
static function_type_data_ptr get_static();
|
||||
|
||||
template < function_kind Function >
|
||||
explicit function_type_data(type_list<Function>);
|
||||
@@ -489,7 +489,7 @@ namespace meta_hpp::detail
|
||||
const any_type value_type;
|
||||
|
||||
template < member_kind Member >
|
||||
static member_type_data_ptr get();
|
||||
static member_type_data_ptr get_static();
|
||||
|
||||
template < member_kind Member >
|
||||
explicit member_type_data(type_list<Member>);
|
||||
@@ -502,7 +502,7 @@ namespace meta_hpp::detail
|
||||
const std::vector<any_type> argument_types;
|
||||
|
||||
template < method_kind Method >
|
||||
static method_type_data_ptr get();
|
||||
static method_type_data_ptr get_static();
|
||||
|
||||
template < method_kind Method >
|
||||
explicit method_type_data(type_list<Method>);
|
||||
@@ -513,7 +513,7 @@ namespace meta_hpp::detail
|
||||
const std::size_t size;
|
||||
|
||||
template < number_kind Number >
|
||||
static number_type_data_ptr get();
|
||||
static number_type_data_ptr get_static();
|
||||
|
||||
template < number_kind Number >
|
||||
explicit number_type_data(type_list<Number>);
|
||||
@@ -524,7 +524,7 @@ namespace meta_hpp::detail
|
||||
const any_type data_type;
|
||||
|
||||
template < pointer_kind Pointer >
|
||||
static pointer_type_data_ptr get();
|
||||
static pointer_type_data_ptr get_static();
|
||||
|
||||
template < pointer_kind Pointer >
|
||||
explicit pointer_type_data(type_list<Pointer>);
|
||||
@@ -535,7 +535,7 @@ namespace meta_hpp::detail
|
||||
const any_type data_type;
|
||||
|
||||
template < reference_kind Reference >
|
||||
static reference_type_data_ptr get();
|
||||
static reference_type_data_ptr get_static();
|
||||
|
||||
template < reference_kind Reference >
|
||||
explicit reference_type_data(type_list<Reference>);
|
||||
@@ -545,7 +545,7 @@ namespace meta_hpp::detail
|
||||
const bitflags<void_flags> flags;
|
||||
|
||||
template < void_kind Void >
|
||||
static void_type_data_ptr get();
|
||||
static void_type_data_ptr get_static();
|
||||
|
||||
template < void_kind Void >
|
||||
explicit void_type_data(type_list<Void>);
|
||||
@@ -672,24 +672,18 @@ namespace meta_hpp
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template < typename T >
|
||||
kind_type_data_ptr<T> get_type_data() {
|
||||
static_assert(!std::is_const_v<T> && !std::is_volatile_v<T>);
|
||||
return kind_type_data<T>::template get<T>();
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
auto resolve_type() {
|
||||
using raw_type = std::remove_cv_t<T>;
|
||||
return detail::kind_type<raw_type>{detail::get_type_data<raw_type>()};
|
||||
|
||||
using kind_type = detail::kind_type<raw_type>;
|
||||
using kind_type_data = detail::kind_type_data<raw_type>;
|
||||
|
||||
return kind_type{kind_type_data::template get_static<raw_type>()};
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
auto resolve_type(T&&) {
|
||||
using raw_type = std::remove_cvref_t<T>;
|
||||
return detail::kind_type<raw_type>{detail::get_type_data<raw_type>()};
|
||||
return resolve_type<std::remove_reference_t<T>>();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace meta_hpp::detail
|
||||
struct array_tag {};
|
||||
|
||||
template < array_kind Array >
|
||||
array_type_data_ptr array_type_data::get() {
|
||||
array_type_data_ptr array_type_data::get_static() {
|
||||
static array_type_data_ptr data = std::make_shared<array_type_data>(type_list<Array>{});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace meta_hpp::detail
|
||||
struct class_tag {};
|
||||
|
||||
template < class_kind Class >
|
||||
class_type_data_ptr class_type_data::get() {
|
||||
class_type_data_ptr class_type_data::get_static() {
|
||||
static class_type_data_ptr data = std::make_shared<class_type_data>(type_list<Class>{});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace meta_hpp::detail
|
||||
struct ctor_tag {};
|
||||
|
||||
template < class_kind Class, typename... Args >
|
||||
ctor_type_data_ptr ctor_type_data::get() {
|
||||
ctor_type_data_ptr ctor_type_data::get_static() {
|
||||
static ctor_type_data_ptr data = std::make_shared<ctor_type_data>(type_list<Class>{}, type_list<Args...>{});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace meta_hpp::detail
|
||||
struct enum_tag {};
|
||||
|
||||
template < enum_kind Enum >
|
||||
enum_type_data_ptr enum_type_data::get() {
|
||||
enum_type_data_ptr enum_type_data::get_static() {
|
||||
static enum_type_data_ptr data = std::make_shared<enum_type_data>(type_list<Enum>{});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace meta_hpp::detail
|
||||
struct function_tag {};
|
||||
|
||||
template < function_kind Function >
|
||||
function_type_data_ptr function_type_data::get() {
|
||||
function_type_data_ptr function_type_data::get_static() {
|
||||
static function_type_data_ptr data = std::make_shared<function_type_data>(type_list<Function>{});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace meta_hpp::detail
|
||||
struct member_tag {};
|
||||
|
||||
template < member_kind Member >
|
||||
member_type_data_ptr member_type_data::get() {
|
||||
member_type_data_ptr member_type_data::get_static() {
|
||||
static member_type_data_ptr data = std::make_shared<member_type_data>(type_list<Member>{});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace meta_hpp::detail
|
||||
struct method_tag {};
|
||||
|
||||
template < method_kind Method >
|
||||
method_type_data_ptr method_type_data::get() {
|
||||
method_type_data_ptr method_type_data::get_static() {
|
||||
static method_type_data_ptr data = std::make_shared<method_type_data>(type_list<Method>{});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace meta_hpp::detail
|
||||
struct number_tag {};
|
||||
|
||||
template < number_kind Number >
|
||||
number_type_data_ptr number_type_data::get() {
|
||||
number_type_data_ptr number_type_data::get_static() {
|
||||
static number_type_data_ptr data = std::make_shared<number_type_data>(type_list<Number>{});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace meta_hpp::detail
|
||||
struct pointer_tag {};
|
||||
|
||||
template < pointer_kind Pointer >
|
||||
pointer_type_data_ptr pointer_type_data::get() {
|
||||
pointer_type_data_ptr pointer_type_data::get_static() {
|
||||
static pointer_type_data_ptr data = std::make_shared<pointer_type_data>(type_list<Pointer>{});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace meta_hpp::detail
|
||||
struct reference_tag {};
|
||||
|
||||
template < reference_kind Reference >
|
||||
reference_type_data_ptr reference_type_data::get() {
|
||||
reference_type_data_ptr reference_type_data::get_static() {
|
||||
static reference_type_data_ptr data = std::make_shared<reference_type_data>(type_list<Reference>{});
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace meta_hpp::detail
|
||||
struct void_tag {};
|
||||
|
||||
template < void_kind Void >
|
||||
void_type_data_ptr void_type_data::get() {
|
||||
void_type_data_ptr void_type_data::get_static() {
|
||||
static void_type_data_ptr data = std::make_shared<void_type_data>(type_list<Void>{});
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user