universal type data access

This commit is contained in:
BlackMATov
2021-12-05 06:02:30 +07:00
parent 2c00f330f5
commit d7526cc20d
2 changed files with 28 additions and 22 deletions

View File

@@ -73,6 +73,11 @@ namespace meta_hpp
std::same_as<T, pointer_type> || std::same_as<T, pointer_type> ||
std::same_as<T, reference_type> || std::same_as<T, reference_type> ||
std::same_as<T, void_type>; std::same_as<T, void_type>;
template < type_family T >
auto data_access(const T& type) {
return type.data_;
}
} }
template < detail::type_family T, detail::type_family U > template < detail::type_family T, detail::type_family U >
@@ -157,6 +162,7 @@ namespace meta_hpp
void_type as_void() const noexcept; void_type as_void() const noexcept;
private: private:
detail::type_data_base_ptr data_; detail::type_data_base_ptr data_;
friend auto detail::data_access(const any_type&);
}; };
class array_type final { class array_type final {
@@ -173,8 +179,8 @@ namespace meta_hpp
std::size_t get_extent() const noexcept; std::size_t get_extent() const noexcept;
any_type get_data_type() const noexcept; any_type get_data_type() const noexcept;
private: private:
friend class any_type;
detail::array_type_data_ptr data_; detail::array_type_data_ptr data_;
friend auto detail::data_access(const array_type&);
}; };
class class_type final { class class_type final {
@@ -235,8 +241,8 @@ namespace meta_hpp
method get_method_with(std::string_view name, std::vector<any_type> args) const noexcept; method get_method_with(std::string_view name, std::vector<any_type> args) const noexcept;
method get_method_with(std::string_view name, std::initializer_list<any_type> args) const noexcept; method get_method_with(std::string_view name, std::initializer_list<any_type> args) const noexcept;
private: private:
friend class any_type;
detail::class_type_data_ptr data_; detail::class_type_data_ptr data_;
friend auto detail::data_access(const class_type&);
}; };
class ctor_type final { class ctor_type final {
@@ -255,8 +261,8 @@ namespace meta_hpp
any_type get_argument_type(std::size_t index) const noexcept; any_type get_argument_type(std::size_t index) const noexcept;
const std::vector<any_type>& get_argument_types() const noexcept; const std::vector<any_type>& get_argument_types() const noexcept;
private: private:
friend class any_type;
detail::ctor_type_data_ptr data_; detail::ctor_type_data_ptr data_;
friend auto detail::data_access(const ctor_type&);
}; };
class enum_type final { class enum_type final {
@@ -280,8 +286,8 @@ namespace meta_hpp
std::optional<std::string> value_to_name(Value&& value) const noexcept; std::optional<std::string> value_to_name(Value&& value) const noexcept;
std::optional<value> name_to_value(std::string_view name) const noexcept; std::optional<value> name_to_value(std::string_view name) const noexcept;
private: private:
friend class any_type;
detail::enum_type_data_ptr data_; detail::enum_type_data_ptr data_;
friend auto detail::data_access(const enum_type&);
}; };
class function_type final { class function_type final {
@@ -300,8 +306,8 @@ namespace meta_hpp
any_type get_argument_type(std::size_t index) const noexcept; any_type get_argument_type(std::size_t index) const noexcept;
const std::vector<any_type>& get_argument_types() const noexcept; const std::vector<any_type>& get_argument_types() const noexcept;
private: private:
friend class any_type;
detail::function_type_data_ptr data_; detail::function_type_data_ptr data_;
friend auto detail::data_access(const function_type&);
}; };
class member_type final { class member_type final {
@@ -318,8 +324,8 @@ namespace meta_hpp
class_type get_owner_type() const noexcept; class_type get_owner_type() const noexcept;
any_type get_value_type() const noexcept; any_type get_value_type() const noexcept;
private: private:
friend class any_type;
detail::member_type_data_ptr data_; detail::member_type_data_ptr data_;
friend auto detail::data_access(const member_type&);
}; };
class method_type final { class method_type final {
@@ -339,8 +345,8 @@ namespace meta_hpp
any_type get_argument_type(std::size_t index) const noexcept; any_type get_argument_type(std::size_t index) const noexcept;
const std::vector<any_type>& get_argument_types() const noexcept; const std::vector<any_type>& get_argument_types() const noexcept;
private: private:
friend class any_type;
detail::method_type_data_ptr data_; detail::method_type_data_ptr data_;
friend auto detail::data_access(const method_type&);
}; };
class number_type final { class number_type final {
@@ -356,8 +362,8 @@ namespace meta_hpp
std::size_t get_size() const noexcept; std::size_t get_size() const noexcept;
private: private:
friend class any_type;
detail::number_type_data_ptr data_; detail::number_type_data_ptr data_;
friend auto detail::data_access(const number_type&);
}; };
class pointer_type final { class pointer_type final {
@@ -373,8 +379,8 @@ namespace meta_hpp
any_type get_data_type() const noexcept; any_type get_data_type() const noexcept;
private: private:
friend class any_type;
detail::pointer_type_data_ptr data_; detail::pointer_type_data_ptr data_;
friend auto detail::data_access(const pointer_type&);
}; };
class reference_type final { class reference_type final {
@@ -390,8 +396,8 @@ namespace meta_hpp
any_type get_data_type() const noexcept; any_type get_data_type() const noexcept;
private: private:
friend class any_type;
detail::reference_type_data_ptr data_; detail::reference_type_data_ptr data_;
friend auto detail::data_access(const reference_type&);
}; };
class void_type final { class void_type final {
@@ -405,8 +411,8 @@ namespace meta_hpp
type_id get_id() const noexcept; type_id get_id() const noexcept;
bitflags<void_flags> get_flags() const noexcept; bitflags<void_flags> get_flags() const noexcept;
private: private:
friend class any_type;
detail::void_type_data_ptr data_; detail::void_type_data_ptr data_;
friend auto detail::data_access(const void_type&);
}; };
} }

View File

@@ -31,37 +31,37 @@ namespace meta_hpp
} }
inline any_type::any_type(const array_type& other) noexcept inline any_type::any_type(const array_type& other) noexcept
: data_{other.data_} {} : data_{detail::data_access(other)} {}
inline any_type::any_type(const class_type& other) noexcept inline any_type::any_type(const class_type& other) noexcept
: data_{other.data_} {} : data_{detail::data_access(other)} {}
inline any_type::any_type(const ctor_type& other) noexcept inline any_type::any_type(const ctor_type& other) noexcept
: data_{other.data_} {} : data_{detail::data_access(other)} {}
inline any_type::any_type(const enum_type& other) noexcept inline any_type::any_type(const enum_type& other) noexcept
: data_{other.data_} {} : data_{detail::data_access(other)} {}
inline any_type::any_type(const function_type& other) noexcept inline any_type::any_type(const function_type& other) noexcept
: data_{other.data_} {} : data_{detail::data_access(other)} {}
inline any_type::any_type(const member_type& other) noexcept inline any_type::any_type(const member_type& other) noexcept
: data_{other.data_} {} : data_{detail::data_access(other)} {}
inline any_type::any_type(const method_type& other) noexcept inline any_type::any_type(const method_type& other) noexcept
: data_{other.data_} {} : data_{detail::data_access(other)} {}
inline any_type::any_type(const number_type& other) noexcept inline any_type::any_type(const number_type& other) noexcept
: data_{other.data_} {} : data_{detail::data_access(other)} {}
inline any_type::any_type(const pointer_type& other) noexcept inline any_type::any_type(const pointer_type& other) noexcept
: data_{other.data_} {} : data_{detail::data_access(other)} {}
inline any_type::any_type(const reference_type& other) noexcept inline any_type::any_type(const reference_type& other) noexcept
: data_{other.data_} {} : data_{detail::data_access(other)} {}
inline any_type::any_type(const void_type& other) noexcept inline any_type::any_type(const void_type& other) noexcept
: data_{other.data_} {} : data_{detail::data_access(other)} {}
inline bool any_type::is_array() const noexcept { inline bool any_type::is_array() const noexcept {
return data_ && data_->kind == type_kind::array_; return data_ && data_->kind == type_kind::array_;