typedefs instead class_ and enum_

This commit is contained in:
BlackMATov
2022-02-13 07:10:25 +07:00
parent 84619af864
commit e93f89d4e5
12 changed files with 94 additions and 136 deletions

View File

@@ -205,6 +205,7 @@ namespace meta_hpp
{
using argument_list = std::vector<argument>;
using metadata_map = std::map<std::string, uvalue, std::less<>>;
using typedef_map = std::map<std::string, any_type, std::less<>>;
using class_set = std::set<class_type, std::less<>>;
using class_map = std::map<std::string, class_type, std::less<>>;

View File

@@ -100,11 +100,6 @@ namespace meta_hpp
explicit class_bind(metadata_map metadata);
operator class_type() const noexcept;
// class_
template < detail::class_kind InternalClass >
class_bind& class_(std::string name);
// base_
template < detail::class_kind Base >
@@ -131,11 +126,6 @@ namespace meta_hpp
class_bind& destructor_(destructor_opts opts)
requires detail::class_bind_destructor_kind<Class>;
// enum_
template < detail::enum_kind InternalEnum >
class_bind& enum_(std::string name);
// function_
template < detail::function_kind Function
@@ -208,6 +198,11 @@ namespace meta_hpp
Policy = Policy{})
requires detail::class_bind_method_kind<Class, Method>;
// typdef_
template < typename Type >
class_bind& typedef_(std::string name);
// variable_
template < detail::pointer_kind Pointer
@@ -361,12 +356,6 @@ namespace meta_hpp
explicit scope_bind(std::string_view name, metadata_map metadata, static_tag);
operator scope() const noexcept;
template < detail::class_kind Class >
scope_bind& class_(std::string name);
template < detail::enum_kind Enum >
scope_bind& enum_(std::string name);
// function_
template < detail::function_kind Function
@@ -392,6 +381,11 @@ namespace meta_hpp
std::initializer_list<std::string_view> arguments,
Policy = Policy{});
// typedef_
template < typename Type >
scope_bind& typedef_(std::string name);
// variable_
template < detail::pointer_kind Pointer

View File

@@ -25,15 +25,6 @@ namespace meta_hpp
return class_type{data_};
}
// class_
template < detail::class_kind Class >
template < detail::class_kind InternalClass >
class_bind<Class>& class_bind<Class>::class_(std::string name) {
data_->classes.insert_or_assign(std::move(name), detail::resolve_type<InternalClass>());
return *this;
}
//
// base_
//
@@ -113,17 +104,6 @@ namespace meta_hpp
return *this;
}
//
// enum_
//
template < detail::class_kind Class >
template < detail::enum_kind InternalEnum >
class_bind<Class>& class_bind<Class>::enum_(std::string name) {
data_->enums.insert_or_assign(std::move(name), detail::resolve_type<InternalEnum>());
return *this;
}
//
// function_
//
@@ -293,6 +273,17 @@ namespace meta_hpp
return *this;
}
//
// typedef_
//
template < detail::class_kind Class >
template < typename Type >
class_bind<Class>& class_bind<Class>::typedef_(std::string name) {
data_->typedefs.insert_or_assign(std::move(name), detail::resolve_type<Type>());
return *this;
}
//
// variable_
//

View File

@@ -29,26 +29,6 @@ namespace meta_hpp
return scope{state_};
}
//
// class_
//
template < detail::class_kind Class >
scope_bind& scope_bind::class_(std::string name) {
state_->classes.insert_or_assign(std::move(name), detail::resolve_type<Class>());
return *this;
}
//
// enum_
//
template < detail::enum_kind Enum >
scope_bind& scope_bind::enum_(std::string name) {
state_->enums.insert_or_assign(std::move(name), detail::resolve_type<Enum>());
return *this;
}
//
// function_
//
@@ -113,6 +93,16 @@ namespace meta_hpp
return *this;
}
//
// typedef_
//
template < typename Type >
scope_bind& scope_bind::typedef_(std::string name) {
state_->typedefs.insert_or_assign(std::move(name), detail::resolve_type<Type>());
return *this;
}
//
// variable_
//

View File

@@ -329,14 +329,12 @@ namespace meta_hpp
[[nodiscard]] const std::string& get_name() const noexcept;
[[nodiscard]] const class_map& get_classes() const noexcept;
[[nodiscard]] const enum_map& get_enums() const noexcept;
[[nodiscard]] const function_map& get_functions() const noexcept;
[[nodiscard]] const typedef_map& get_typedefs() const noexcept;
[[nodiscard]] const variable_map& get_variables() const noexcept;
[[nodiscard]] class_type get_class(std::string_view name) const noexcept;
[[nodiscard]] enum_type get_enum(std::string_view name) const noexcept;
[[nodiscard]] function get_function(std::string_view name) const noexcept;
[[nodiscard]] any_type get_typedef(std::string_view name) const noexcept;
[[nodiscard]] variable get_variable(std::string_view name) const noexcept;
template < typename... Args >
@@ -529,9 +527,8 @@ namespace meta_hpp::detail
scope_index index;
metadata_map metadata;
class_map classes{};
enum_map enums{};
function_map functions{};
typedef_map typedefs{};
variable_map variables{};
[[nodiscard]] static scope_state_ptr make(std::string name, metadata_map metadata);

View File

@@ -58,36 +58,18 @@ namespace meta_hpp
return state_->index.get_name();
}
inline const class_map& scope::get_classes() const noexcept {
return state_->classes;
}
inline const enum_map& scope::get_enums() const noexcept {
return state_->enums;
}
inline const function_map& scope::get_functions() const noexcept {
return state_->functions;
}
inline const typedef_map& scope::get_typedefs() const noexcept {
return state_->typedefs;
}
inline const variable_map& scope::get_variables() const noexcept {
return state_->variables;
}
inline class_type scope::get_class(std::string_view name) const noexcept {
if ( auto iter = state_->classes.find(name); iter != state_->classes.end() ) {
return iter->second;
}
return class_type{};
}
inline enum_type scope::get_enum(std::string_view name) const noexcept {
if ( auto iter = state_->enums.find(name); iter != state_->enums.end() ) {
return iter->second;
}
return enum_type{};
}
inline function scope::get_function(std::string_view name) const noexcept {
for ( auto&& [index, function] : state_->functions ) {
if ( index.get_name() == name ) {
@@ -97,6 +79,15 @@ namespace meta_hpp
return function{};
}
inline any_type scope::get_typedef(std::string_view name) const noexcept {
for ( auto&& [index, type] : state_->typedefs ) {
if ( index == name ) {
return type;
}
}
return any_type{};
}
inline variable scope::get_variable(std::string_view name) const noexcept {
for ( auto&& [index, variable] : state_->variables ) {
if ( index.get_name() == name ) {

View File

@@ -155,14 +155,13 @@ namespace meta_hpp
[[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept;
[[nodiscard]] const std::vector<any_type>& get_argument_types() const noexcept;
[[nodiscard]] const class_map& get_classes() const noexcept;
[[nodiscard]] const class_set& get_bases() const noexcept;
[[nodiscard]] const constructor_map& get_ctors() const noexcept;
[[nodiscard]] const destructor_map& get_dtors() const noexcept;
[[nodiscard]] const enum_map& get_enums() const noexcept;
[[nodiscard]] const function_map& get_functions() const noexcept;
[[nodiscard]] const member_map& get_members() const noexcept;
[[nodiscard]] const method_map& get_methods() const noexcept;
[[nodiscard]] const typedef_map& get_typedefs() const noexcept;
[[nodiscard]] const variable_map& get_variables() const noexcept;
template < typename... Args >
@@ -182,11 +181,10 @@ namespace meta_hpp
[[nodiscard]] bool is_derived_from() const noexcept;
[[nodiscard]] bool is_derived_from(const class_type& base) const noexcept;
[[nodiscard]] class_type get_class(std::string_view name) const noexcept;
[[nodiscard]] enum_type get_enum(std::string_view name) const noexcept;
[[nodiscard]] function get_function(std::string_view name) const noexcept;
[[nodiscard]] member get_member(std::string_view name) const noexcept;
[[nodiscard]] method get_method(std::string_view name) const noexcept;
[[nodiscard]] any_type get_typedef(std::string_view name) const noexcept;
[[nodiscard]] variable get_variable(std::string_view name) const noexcept;
template < typename... Args >
@@ -487,14 +485,13 @@ namespace meta_hpp::detail
const std::size_t size;
const std::vector<any_type> argument_types;
class_map classes;
class_set bases;
constructor_map constructors;
destructor_map destructors;
enum_map enums;
function_map functions;
member_map members;
method_map methods;
typedef_map typedefs;
variable_map variables;
struct base_info final {

View File

@@ -73,10 +73,6 @@ namespace meta_hpp
return data_->argument_types;
}
inline const class_map& class_type::get_classes() const noexcept {
return data_->classes;
}
inline const class_set& class_type::get_bases() const noexcept {
return data_->bases;
}
@@ -89,10 +85,6 @@ namespace meta_hpp
return data_->destructors;
}
inline const enum_map& class_type::get_enums() const noexcept {
return data_->enums;
}
inline const function_map& class_type::get_functions() const noexcept {
return data_->functions;
}
@@ -105,6 +97,10 @@ namespace meta_hpp
return data_->methods;
}
inline const typedef_map& class_type::get_typedefs() const noexcept {
return data_->typedefs;
}
inline const variable_map& class_type::get_variables() const noexcept {
return data_->variables;
}
@@ -181,20 +177,6 @@ namespace meta_hpp
return false;
}
inline class_type class_type::get_class(std::string_view name) const noexcept {
if ( auto iter = data_->classes.find(name); iter != data_->classes.end() ) {
return iter->second;
}
return class_type{};
}
inline enum_type class_type::get_enum(std::string_view name) const noexcept {
if ( auto iter = data_->enums.find(name); iter != data_->enums.end() ) {
return iter->second;
}
return enum_type{};
}
inline function class_type::get_function(std::string_view name) const noexcept {
for ( auto&& [index, function] : data_->functions ) {
if ( index.get_name() == name ) {
@@ -243,6 +225,22 @@ namespace meta_hpp
return method{};
}
inline any_type class_type::get_typedef(std::string_view name) const noexcept {
for ( auto&& [index, type] : data_->typedefs ) {
if ( index == name ) {
return type;
}
}
for ( auto&& base : data_->bases ) {
if ( any_type type = base.get_typedef(name); type ) {
return type;
}
}
return any_type{};
}
inline variable class_type::get_variable(std::string_view name) const noexcept {
for ( auto&& [index, variable] : data_->variables ) {
if ( index.get_name() == name ) {