mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 03:45:30 +07:00
parameter states for function, method and ctor
This commit is contained in:
@@ -199,7 +199,10 @@ namespace meta_hpp
|
||||
class parameter_index;
|
||||
class scope_index;
|
||||
class variable_index;
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
using class_set = std::set<class_type, std::less<>>;
|
||||
using class_map = std::map<std::string, class_type, std::less<>>;
|
||||
|
||||
@@ -214,4 +217,6 @@ namespace meta_hpp
|
||||
using method_map = std::map<method_index, method, std::less<>>;
|
||||
using scope_map = std::map<scope_index, scope, std::less<>>;
|
||||
using variable_map = std::map<variable_index, variable, std::less<>>;
|
||||
|
||||
using parameter_list = std::vector<parameter>;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,13 @@ namespace meta_hpp
|
||||
class_bind& ctor_(Policy = Policy{})
|
||||
requires detail::class_bind_ctor_kind<Class, Args...>;
|
||||
|
||||
template < typename... Args
|
||||
, ctor_policy_kind Policy = ctor_policy::as_object >
|
||||
class_bind& ctor_(
|
||||
std::initializer_list<std::string_view> pnames,
|
||||
Policy = Policy{})
|
||||
requires detail::class_bind_ctor_kind<Class, Args...>;
|
||||
|
||||
class_bind& dtor_()
|
||||
requires detail::class_bind_dtor_kind<Class>;
|
||||
|
||||
@@ -61,6 +68,14 @@ namespace meta_hpp
|
||||
, function_policy_kind Policy = function_policy::as_copy >
|
||||
class_bind& function_(std::string name, Function function, Policy = Policy{});
|
||||
|
||||
template < detail::function_kind Function
|
||||
, function_policy_kind Policy = function_policy::as_copy >
|
||||
class_bind& function_(
|
||||
std::string name,
|
||||
Function function,
|
||||
std::initializer_list<std::string_view> pnames,
|
||||
Policy = Policy{});
|
||||
|
||||
template < detail::member_kind Member
|
||||
, member_policy_kind Policy = member_policy::as_copy >
|
||||
class_bind& member_(std::string name, Member member, Policy = Policy{})
|
||||
@@ -71,6 +86,15 @@ namespace meta_hpp
|
||||
class_bind& method_(std::string name, Method method, Policy = Policy{})
|
||||
requires detail::class_bind_method_kind<Class, Method>;
|
||||
|
||||
template < detail::method_kind Method
|
||||
, method_policy_kind Policy = method_policy::as_copy >
|
||||
class_bind& method_(
|
||||
std::string name,
|
||||
Method method,
|
||||
std::initializer_list<std::string_view> pnames,
|
||||
Policy = Policy{})
|
||||
requires detail::class_bind_method_kind<Class, Method>;
|
||||
|
||||
template < detail::pointer_kind Pointer
|
||||
, variable_policy_kind Policy = variable_policy::as_copy >
|
||||
class_bind& variable_(std::string name, Pointer pointer, Policy = Policy{});
|
||||
@@ -114,6 +138,14 @@ namespace meta_hpp
|
||||
, function_policy_kind Policy = function_policy::as_copy >
|
||||
scope_bind& function_(std::string name, Function function, Policy = Policy{});
|
||||
|
||||
template < detail::function_kind Function
|
||||
, function_policy_kind Policy = function_policy::as_copy >
|
||||
scope_bind& function_(
|
||||
std::string name,
|
||||
Function function,
|
||||
std::initializer_list<std::string_view> pnames,
|
||||
Policy = Policy{});
|
||||
|
||||
template < detail::pointer_kind Pointer
|
||||
, variable_policy_kind Policy = variable_policy::as_copy >
|
||||
scope_bind& variable_(std::string name, Pointer pointer, Policy = Policy{});
|
||||
|
||||
@@ -24,11 +24,30 @@ namespace meta_hpp
|
||||
|
||||
template < detail::class_kind Class >
|
||||
template < typename... Args, ctor_policy_kind Policy >
|
||||
// NOLINTNEXTLINE(readability-named-parameter)
|
||||
class_bind<Class>& class_bind<Class>::ctor_(Policy)
|
||||
class_bind<Class>& class_bind<Class>::ctor_(Policy policy)
|
||||
requires detail::class_bind_ctor_kind<Class, Args...>
|
||||
{
|
||||
return ctor_<Args...>({}, policy);
|
||||
}
|
||||
|
||||
template < detail::class_kind Class >
|
||||
template < typename... Args, ctor_policy_kind Policy >
|
||||
class_bind<Class>& class_bind<Class>::ctor_(
|
||||
std::initializer_list<std::string_view> pnames,
|
||||
[[maybe_unused]] Policy policy)
|
||||
requires detail::class_bind_ctor_kind<Class, Args...>
|
||||
{
|
||||
auto ctor_state = detail::ctor_state::make<Policy, Class, Args...>();
|
||||
|
||||
if ( pnames.size() > ctor_state->parameters.size() ) {
|
||||
detail::throw_exception_with("provided parameter names don't match constructor argument count");
|
||||
}
|
||||
|
||||
for ( std::size_t i = 0; i < pnames.size(); ++i ) {
|
||||
parameter& param = ctor_state->parameters[i];
|
||||
detail::state_access(param)->name = std::string{std::data(pnames)[i]};
|
||||
}
|
||||
|
||||
data_->ctors.emplace(ctor_state->index, std::move(ctor_state));
|
||||
return *this;
|
||||
}
|
||||
@@ -58,17 +77,36 @@ namespace meta_hpp
|
||||
|
||||
template < detail::class_kind Class >
|
||||
template < detail::function_kind Function, function_policy_kind Policy >
|
||||
// NOLINTNEXTLINE(readability-named-parameter)
|
||||
class_bind<Class>& class_bind<Class>::function_(std::string name, Function function, Policy) {
|
||||
class_bind<Class>& class_bind<Class>::function_(std::string name, Function function, Policy policy) {
|
||||
return function_(std::move(name), std::move(function), {}, policy);
|
||||
}
|
||||
|
||||
template < detail::class_kind Class >
|
||||
template < detail::function_kind Function, function_policy_kind Policy >
|
||||
class_bind<Class>& class_bind<Class>::function_(
|
||||
std::string name,
|
||||
Function function,
|
||||
std::initializer_list<std::string_view> pnames,
|
||||
[[maybe_unused]] Policy policy)
|
||||
{
|
||||
auto function_state = detail::function_state::make<Policy>(std::move(name), std::move(function));
|
||||
|
||||
if ( pnames.size() > function_state->parameters.size() ) {
|
||||
detail::throw_exception_with("provided parameter names don't match function argument count");
|
||||
}
|
||||
|
||||
for ( std::size_t i = 0; i < pnames.size(); ++i ) {
|
||||
parameter& param = function_state->parameters[i];
|
||||
detail::state_access(param)->name = std::string{std::data(pnames)[i]};
|
||||
}
|
||||
|
||||
data_->functions.emplace(function_state->index, std::move(function_state));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template < detail::class_kind Class >
|
||||
template < detail::member_kind Member, member_policy_kind Policy >
|
||||
// NOLINTNEXTLINE(readability-named-parameter)
|
||||
class_bind<Class>& class_bind<Class>::member_(std::string name, Member member, Policy)
|
||||
class_bind<Class>& class_bind<Class>::member_(std::string name, Member member, [[maybe_unused]] Policy policy)
|
||||
requires detail::class_bind_member_kind<Class, Member>
|
||||
{
|
||||
auto member_state = detail::member_state::make<Policy>(std::move(name), std::move(member));
|
||||
@@ -78,19 +116,39 @@ namespace meta_hpp
|
||||
|
||||
template < detail::class_kind Class >
|
||||
template < detail::method_kind Method, method_policy_kind Policy >
|
||||
// NOLINTNEXTLINE(readability-named-parameter)
|
||||
class_bind<Class>& class_bind<Class>::method_(std::string name, Method method, Policy)
|
||||
class_bind<Class>& class_bind<Class>::method_(std::string name, Method method, Policy policy)
|
||||
requires detail::class_bind_method_kind<Class, Method>
|
||||
{
|
||||
return method_(std::move(name), std::move(method), {}, policy);
|
||||
}
|
||||
|
||||
template < detail::class_kind Class >
|
||||
template < detail::method_kind Method, method_policy_kind Policy >
|
||||
class_bind<Class>& class_bind<Class>::method_(
|
||||
std::string name,
|
||||
Method method,
|
||||
std::initializer_list<std::string_view> pnames,
|
||||
[[maybe_unused]] Policy policy)
|
||||
requires detail::class_bind_method_kind<Class, Method>
|
||||
{
|
||||
auto method_state = detail::method_state::make<Policy>(std::move(name), std::move(method));
|
||||
|
||||
if ( pnames.size() > method_state->parameters.size() ) {
|
||||
detail::throw_exception_with("provided parameter names don't match method argument count");
|
||||
}
|
||||
|
||||
for ( std::size_t i = 0; i < pnames.size(); ++i ) {
|
||||
parameter& param = method_state->parameters[i];
|
||||
detail::state_access(param)->name = std::string{std::data(pnames)[i]};
|
||||
}
|
||||
|
||||
data_->methods.emplace(method_state->index, std::move(method_state));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template < detail::class_kind Class >
|
||||
template < detail::pointer_kind Pointer, variable_policy_kind Policy >
|
||||
// NOLINTNEXTLINE(readability-named-parameter)
|
||||
class_bind<Class>& class_bind<Class>::variable_(std::string name, Pointer pointer, Policy) {
|
||||
class_bind<Class>& class_bind<Class>::variable_( std::string name, Pointer pointer, [[maybe_unused]] Policy policy) {
|
||||
auto variable_state = detail::variable_state::make<Policy>(std::move(name), std::move(pointer));
|
||||
data_->variables.emplace(variable_state->index, std::move(variable_state));
|
||||
return *this;
|
||||
|
||||
@@ -39,16 +39,34 @@ namespace meta_hpp
|
||||
}
|
||||
|
||||
template < detail::function_kind Function, function_policy_kind Policy >
|
||||
// NOLINTNEXTLINE(readability-named-parameter)
|
||||
scope_bind& scope_bind::function_(std::string name, Function function, Policy) {
|
||||
scope_bind& scope_bind::function_(std::string name, Function function, Policy policy) {
|
||||
return function_(std::move(name), std::move(function), {}, policy);
|
||||
}
|
||||
|
||||
template < detail::function_kind Function, function_policy_kind Policy >
|
||||
scope_bind& scope_bind::function_(
|
||||
std::string name,
|
||||
Function function,
|
||||
std::initializer_list<std::string_view> pnames,
|
||||
[[maybe_unused]] Policy policy)
|
||||
{
|
||||
auto function_state = detail::function_state::make<Policy>(std::move(name), std::move(function));
|
||||
|
||||
if ( pnames.size() > function_state->parameters.size() ) {
|
||||
detail::throw_exception_with("provided parameter names don't match function argument count");
|
||||
}
|
||||
|
||||
for ( std::size_t i = 0; i < pnames.size(); ++i ) {
|
||||
parameter& param = function_state->parameters[i];
|
||||
detail::state_access(param)->name = std::string{std::data(pnames)[i]};
|
||||
}
|
||||
|
||||
state_->functions.emplace(function_state->index, std::move(function_state));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template < detail::pointer_kind Pointer, variable_policy_kind Policy >
|
||||
// NOLINTNEXTLINE(readability-named-parameter)
|
||||
scope_bind& scope_bind::variable_(std::string name, Pointer pointer, Policy) {
|
||||
scope_bind& scope_bind::variable_(std::string name, Pointer pointer, [[maybe_unused]] Policy policy) {
|
||||
auto variable_state = detail::variable_state::make<Policy>(std::move(name), std::move(pointer));
|
||||
state_->variables.emplace(variable_state->index, std::move(variable_state));
|
||||
return *this;
|
||||
|
||||
@@ -120,6 +120,9 @@ namespace meta_hpp
|
||||
|
||||
template < typename... Args >
|
||||
[[nodiscard]] bool is_invocable_with(Args&&... args) const noexcept;
|
||||
|
||||
[[nodiscard]] parameter get_parameter(std::size_t position) const noexcept;
|
||||
[[nodiscard]] const parameter_list& get_parameters() const noexcept;
|
||||
private:
|
||||
detail::ctor_state_ptr state_;
|
||||
friend auto detail::state_access<ctor>(const ctor&);
|
||||
@@ -194,6 +197,9 @@ namespace meta_hpp
|
||||
|
||||
template < typename... Args >
|
||||
[[nodiscard]] bool is_invocable_with(Args&&... args) const noexcept;
|
||||
|
||||
[[nodiscard]] parameter get_parameter(std::size_t position) const noexcept;
|
||||
[[nodiscard]] const parameter_list& get_parameters() const noexcept;
|
||||
private:
|
||||
detail::function_state_ptr state_;
|
||||
friend auto detail::state_access<function>(const function&);
|
||||
@@ -262,6 +268,9 @@ namespace meta_hpp
|
||||
|
||||
template < typename Instance, typename... Args >
|
||||
[[nodiscard]] bool is_invocable_with(Instance&& instance, Args&&... args) const noexcept;
|
||||
|
||||
[[nodiscard]] parameter get_parameter(std::size_t position) const noexcept;
|
||||
[[nodiscard]] const parameter_list& get_parameters() const noexcept;
|
||||
private:
|
||||
detail::method_state_ptr state_;
|
||||
friend auto detail::state_access<method>(const method&);
|
||||
@@ -277,6 +286,7 @@ namespace meta_hpp
|
||||
|
||||
[[nodiscard]] const parameter_index& get_index() const noexcept;
|
||||
[[nodiscard]] const any_type& get_type() const noexcept;
|
||||
[[nodiscard]] std::size_t get_position() const noexcept;
|
||||
[[nodiscard]] const std::string& get_name() const noexcept;
|
||||
private:
|
||||
detail::parameter_state_ptr state_;
|
||||
@@ -392,6 +402,8 @@ namespace meta_hpp::detail
|
||||
invoke_impl invoke;
|
||||
is_invocable_with_impl is_invocable_with;
|
||||
|
||||
parameter_list parameters;
|
||||
|
||||
template < ctor_policy_kind Policy, class_kind Class, typename... Args >
|
||||
[[nodiscard]] static ctor_state_ptr make();
|
||||
};
|
||||
@@ -425,6 +437,8 @@ namespace meta_hpp::detail
|
||||
invoke_impl invoke;
|
||||
is_invocable_with_impl is_invocable_with;
|
||||
|
||||
parameter_list parameters;
|
||||
|
||||
template < function_policy_kind Policy, function_kind Function >
|
||||
[[nodiscard]] static function_state_ptr make(std::string name, Function function);
|
||||
};
|
||||
@@ -454,6 +468,8 @@ namespace meta_hpp::detail
|
||||
invoke_impl invoke;
|
||||
is_invocable_with_impl is_invocable_with;
|
||||
|
||||
parameter_list parameters;
|
||||
|
||||
template < method_policy_kind Policy, method_kind Method >
|
||||
[[nodiscard]] static method_state_ptr make(std::string name, Method method);
|
||||
};
|
||||
|
||||
@@ -88,6 +88,24 @@ namespace meta_hpp::detail
|
||||
ctor_state::is_invocable_with_impl make_ctor_is_invocable_with() {
|
||||
return &raw_ctor_is_invocable_with<Class, Args...>;
|
||||
}
|
||||
|
||||
template < class_kind Class, typename... Args >
|
||||
parameter_list make_ctor_parameters() {
|
||||
using ct = detail::ctor_traits<Class, Args...>;
|
||||
|
||||
parameter_list parameters;
|
||||
parameters.reserve(ct::arity);
|
||||
|
||||
// NOLINTNEXTLINE(readability-named-parameter)
|
||||
[¶meters]<std::size_t... Is>(std::index_sequence<Is...>) mutable {
|
||||
(parameters.push_back([]<std::size_t I>(){
|
||||
using P = detail::type_list_at_t<I, typename ct::argument_types>;
|
||||
return parameter{detail::parameter_state::make<P>(I)};
|
||||
}.template operator()<Is>()), ...);
|
||||
}(std::make_index_sequence<ct::arity>());
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp::detail
|
||||
@@ -98,6 +116,7 @@ namespace meta_hpp::detail
|
||||
.index{ctor_index::make<Class, Args...>()},
|
||||
.invoke{make_ctor_invoke<Policy, Class, Args...>()},
|
||||
.is_invocable_with{make_ctor_is_invocable_with<Class, Args...>()},
|
||||
.parameters{make_ctor_parameters<Class, Args...>()},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -160,4 +179,12 @@ namespace meta_hpp
|
||||
return state_->is_invocable_with({});
|
||||
}
|
||||
}
|
||||
|
||||
inline parameter ctor::get_parameter(std::size_t position) const noexcept {
|
||||
return position < state_->parameters.size() ? state_->parameters[position] : parameter{};
|
||||
}
|
||||
|
||||
inline const parameter_list& ctor::get_parameters() const noexcept {
|
||||
return state_->parameters;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,24 @@ namespace meta_hpp::detail
|
||||
function_state::is_invocable_with_impl make_function_is_invocable_with() {
|
||||
return &raw_function_is_invocable_with<Function>;
|
||||
}
|
||||
|
||||
template < function_kind Function >
|
||||
parameter_list make_function_parameters() {
|
||||
using ft = detail::function_traits<Function>;
|
||||
|
||||
parameter_list parameters;
|
||||
parameters.reserve(ft::arity);
|
||||
|
||||
// NOLINTNEXTLINE(readability-named-parameter)
|
||||
[¶meters]<std::size_t... Is>(std::index_sequence<Is...>) mutable {
|
||||
(parameters.push_back([]<std::size_t I>(){
|
||||
using P = detail::type_list_at_t<I, typename ft::argument_types>;
|
||||
return parameter{detail::parameter_state::make<P>(I)};
|
||||
}.template operator()<Is>()), ...);
|
||||
}(std::make_index_sequence<ft::arity>());
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp::detail
|
||||
@@ -104,6 +122,7 @@ namespace meta_hpp::detail
|
||||
.index{function_index::make<Function>(std::move(name))},
|
||||
.invoke{make_function_invoke<Policy>(std::move(function))},
|
||||
.is_invocable_with{make_function_is_invocable_with<Function>()},
|
||||
.parameters{make_function_parameters<Function>()},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -170,4 +189,12 @@ namespace meta_hpp
|
||||
return state_->is_invocable_with({});
|
||||
}
|
||||
}
|
||||
|
||||
inline parameter function::get_parameter(std::size_t position) const noexcept {
|
||||
return position < state_->parameters.size() ? state_->parameters[position] : parameter{};
|
||||
}
|
||||
|
||||
inline const parameter_list& function::get_parameters() const noexcept {
|
||||
return state_->parameters;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +107,24 @@ namespace meta_hpp::detail
|
||||
method_state::is_invocable_with_impl make_method_is_invocable_with() {
|
||||
return &raw_method_is_invocable_with<Method>;
|
||||
}
|
||||
|
||||
template < method_kind Method >
|
||||
parameter_list make_method_parameters() {
|
||||
using mt = detail::method_traits<Method>;
|
||||
|
||||
parameter_list parameters;
|
||||
parameters.reserve(mt::arity);
|
||||
|
||||
// NOLINTNEXTLINE(readability-named-parameter)
|
||||
[¶meters]<std::size_t... Is>(std::index_sequence<Is...>) mutable {
|
||||
(parameters.push_back([]<std::size_t I>(){
|
||||
using P = detail::type_list_at_t<I, typename mt::argument_types>;
|
||||
return parameter{detail::parameter_state::make<P>(I)};
|
||||
}.template operator()<Is>()), ...);
|
||||
}(std::make_index_sequence<mt::arity>());
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp::detail
|
||||
@@ -117,6 +135,7 @@ namespace meta_hpp::detail
|
||||
.index{method_index::make<Method>(std::move(name))},
|
||||
.invoke{make_method_invoke<Policy>(std::move(method))},
|
||||
.is_invocable_with{make_method_is_invocable_with<Method>()},
|
||||
.parameters{make_method_parameters<Method>()},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -186,4 +205,12 @@ namespace meta_hpp
|
||||
return state_->is_invocable_with(vinst, {});
|
||||
}
|
||||
}
|
||||
|
||||
inline parameter method::get_parameter(std::size_t position) const noexcept {
|
||||
return position < state_->parameters.size() ? state_->parameters[position] : parameter{};
|
||||
}
|
||||
|
||||
inline const parameter_list& method::get_parameters() const noexcept {
|
||||
return state_->parameters;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace meta_hpp
|
||||
[[nodiscard]] std::size_t get_size() const noexcept;
|
||||
|
||||
[[nodiscard]] std::size_t get_arity() const noexcept;
|
||||
[[nodiscard]] any_type get_argument_type(std::size_t index) const noexcept;
|
||||
[[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 ctor_map& get_ctors() const noexcept;
|
||||
@@ -219,7 +219,7 @@ namespace meta_hpp
|
||||
|
||||
[[nodiscard]] std::size_t get_arity() const noexcept;
|
||||
[[nodiscard]] any_type get_class_type() const noexcept;
|
||||
[[nodiscard]] any_type get_argument_type(std::size_t index) const noexcept;
|
||||
[[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept;
|
||||
[[nodiscard]] const std::vector<any_type>& get_argument_types() const noexcept;
|
||||
private:
|
||||
detail::ctor_type_data_ptr data_;
|
||||
@@ -281,7 +281,7 @@ namespace meta_hpp
|
||||
|
||||
[[nodiscard]] std::size_t get_arity() const noexcept;
|
||||
[[nodiscard]] any_type get_return_type() const noexcept;
|
||||
[[nodiscard]] any_type get_argument_type(std::size_t index) const noexcept;
|
||||
[[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept;
|
||||
[[nodiscard]] const std::vector<any_type>& get_argument_types() const noexcept;
|
||||
private:
|
||||
detail::function_type_data_ptr data_;
|
||||
@@ -320,7 +320,7 @@ namespace meta_hpp
|
||||
[[nodiscard]] std::size_t get_arity() const noexcept;
|
||||
[[nodiscard]] class_type get_owner_type() const noexcept;
|
||||
[[nodiscard]] any_type get_return_type() const noexcept;
|
||||
[[nodiscard]] any_type get_argument_type(std::size_t index) const noexcept;
|
||||
[[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept;
|
||||
[[nodiscard]] const std::vector<any_type>& get_argument_types() const noexcept;
|
||||
private:
|
||||
detail::method_type_data_ptr data_;
|
||||
|
||||
@@ -61,8 +61,8 @@ namespace meta_hpp
|
||||
return data_->argument_types.size();
|
||||
}
|
||||
|
||||
inline any_type class_type::get_argument_type(std::size_t index) const noexcept {
|
||||
return index < data_->argument_types.size() ? data_->argument_types[index] : any_type{};
|
||||
inline any_type class_type::get_argument_type(std::size_t position) const noexcept {
|
||||
return position < data_->argument_types.size() ? data_->argument_types[position] : any_type{};
|
||||
}
|
||||
|
||||
inline const std::vector<any_type>& class_type::get_argument_types() const noexcept {
|
||||
|
||||
@@ -55,8 +55,8 @@ namespace meta_hpp
|
||||
return data_->class_type;
|
||||
}
|
||||
|
||||
inline any_type ctor_type::get_argument_type(std::size_t index) const noexcept {
|
||||
return index < data_->argument_types.size() ? data_->argument_types[index] : any_type{};
|
||||
inline any_type ctor_type::get_argument_type(std::size_t position) const noexcept {
|
||||
return position < data_->argument_types.size() ? data_->argument_types[position] : any_type{};
|
||||
}
|
||||
|
||||
inline const std::vector<any_type>& ctor_type::get_argument_types() const noexcept {
|
||||
|
||||
@@ -55,8 +55,8 @@ namespace meta_hpp
|
||||
return data_->return_type;
|
||||
}
|
||||
|
||||
inline any_type function_type::get_argument_type(std::size_t index) const noexcept {
|
||||
return index < data_->argument_types.size() ? data_->argument_types[index] : any_type{};
|
||||
inline any_type function_type::get_argument_type(std::size_t position) const noexcept {
|
||||
return position < data_->argument_types.size() ? data_->argument_types[position] : any_type{};
|
||||
}
|
||||
|
||||
inline const std::vector<any_type>& function_type::get_argument_types() const noexcept {
|
||||
|
||||
@@ -60,8 +60,8 @@ namespace meta_hpp
|
||||
return data_->return_type;
|
||||
}
|
||||
|
||||
inline any_type method_type::get_argument_type(std::size_t index) const noexcept {
|
||||
return index < data_->argument_types.size() ? data_->argument_types[index] : any_type{};
|
||||
inline any_type method_type::get_argument_type(std::size_t position) const noexcept {
|
||||
return position < data_->argument_types.size() ? data_->argument_types[position] : any_type{};
|
||||
}
|
||||
|
||||
inline const std::vector<any_type>& method_type::get_argument_types() const noexcept {
|
||||
|
||||
72
untests/meta_states/function2_tests.cpp
Normal file
72
untests/meta_states/function2_tests.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ivec2 {
|
||||
int x{};
|
||||
int y{};
|
||||
|
||||
static ivec2 iadd(const ivec2& l, const ivec2& r) noexcept {
|
||||
return {l.x + r.x, l.y + r.y};
|
||||
}
|
||||
|
||||
static ivec2 isub(const ivec2& l, const ivec2& r) noexcept {
|
||||
return {l.x - r.x, l.y - r.y};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_states/function2") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
meta::class_<ivec2>()
|
||||
.function_("iadd", &ivec2::iadd, { "l" })
|
||||
.function_("isub", &ivec2::isub, { "l", "r" });
|
||||
|
||||
const meta::class_type ivec2_type = meta::resolve_type<ivec2>();
|
||||
REQUIRE(ivec2_type);
|
||||
|
||||
SUBCASE("iadd2") {
|
||||
const meta::function func = ivec2_type.get_function("iadd");
|
||||
REQUIRE(func);
|
||||
|
||||
CHECK(func.get_parameters().size() == 2);
|
||||
|
||||
REQUIRE(func.get_parameter(0));
|
||||
CHECK(func.get_parameter(0).get_type() == meta::resolve_type<const ivec2&>());
|
||||
CHECK(func.get_parameter(0).get_position() == 0);
|
||||
CHECK(func.get_parameter(0).get_name() == "l");
|
||||
|
||||
REQUIRE(func.get_parameter(1));
|
||||
CHECK(func.get_parameter(1).get_type() == meta::resolve_type<const ivec2&>());
|
||||
CHECK(func.get_parameter(1).get_position() == 1);
|
||||
CHECK(func.get_parameter(1).get_name() == "");
|
||||
|
||||
CHECK_FALSE(func.get_parameter(2));
|
||||
}
|
||||
|
||||
SUBCASE("isub2") {
|
||||
const meta::function func = ivec2_type.get_function("isub");
|
||||
REQUIRE(func);
|
||||
|
||||
REQUIRE(func.get_parameters().size() == 2);
|
||||
|
||||
REQUIRE(func.get_parameter(0));
|
||||
CHECK(func.get_parameter(0).get_type() == meta::resolve_type<const ivec2&>());
|
||||
CHECK(func.get_parameter(0).get_position() == 0);
|
||||
CHECK(func.get_parameter(0).get_name() == "l");
|
||||
|
||||
REQUIRE(func.get_parameter(1));
|
||||
CHECK(func.get_parameter(1).get_type() == meta::resolve_type<const ivec2&>());
|
||||
CHECK(func.get_parameter(1).get_position() == 1);
|
||||
CHECK(func.get_parameter(1).get_name() == "r");
|
||||
|
||||
CHECK_FALSE(func.get_parameter(2));
|
||||
}
|
||||
}
|
||||
45
untests/meta_states/method2_tests.cpp
Normal file
45
untests/meta_states/method2_tests.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ivec2 {
|
||||
int x{};
|
||||
int y{};
|
||||
|
||||
ivec2& add(const ivec2& other) {
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_states/method2") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
meta::class_<ivec2>()
|
||||
.method_("add", &ivec2::add, {"other"});
|
||||
|
||||
const meta::class_type ivec2_type = meta::resolve_type<ivec2>();
|
||||
REQUIRE(ivec2_type);
|
||||
|
||||
SUBCASE("add") {
|
||||
const meta::method add_m = ivec2_type.get_method("add");
|
||||
REQUIRE(add_m);
|
||||
|
||||
CHECK(add_m.get_parameters().size() == 1);
|
||||
|
||||
REQUIRE(add_m.get_parameter(0));
|
||||
CHECK(add_m.get_parameter(0).get_type() == meta::resolve_type<const ivec2&>());
|
||||
CHECK(add_m.get_parameter(0).get_position() == 0);
|
||||
CHECK(add_m.get_parameter(0).get_name() == "other");
|
||||
|
||||
CHECK_FALSE(add_m.get_parameter(1));
|
||||
}
|
||||
}
|
||||
@@ -44,8 +44,8 @@ TEST_CASE("meta/meta_states/scope") {
|
||||
.enum_<color>("color")
|
||||
.class_<ivec2>("ivec2")
|
||||
.class_<ivec3>("ivec3")
|
||||
.function_("iadd2", &iadd2)
|
||||
.function_("iadd3", &iadd3)
|
||||
.function_("iadd2", &iadd2, {"l", "r"})
|
||||
.function_("iadd3", &iadd3, {"l"})
|
||||
.variable_("static_ivec2", &static_ivec2)
|
||||
.variable_("static_const_ivec3", &static_const_ivec3);
|
||||
|
||||
@@ -96,8 +96,40 @@ TEST_CASE("meta/meta_states/scope") {
|
||||
const meta::function iadd2_func = math_scope.get_function("iadd2");
|
||||
REQUIRE(iadd2_func);
|
||||
|
||||
{
|
||||
CHECK(iadd2_func.get_parameters().size() == 2);
|
||||
|
||||
REQUIRE(iadd2_func.get_parameter(0));
|
||||
CHECK(iadd2_func.get_parameter(0).get_type() == meta::resolve_type<const ivec2&>());
|
||||
CHECK(iadd2_func.get_parameter(0).get_position() == 0);
|
||||
CHECK(iadd2_func.get_parameter(0).get_name() == "l");
|
||||
|
||||
REQUIRE(iadd2_func.get_parameter(1));
|
||||
CHECK(iadd2_func.get_parameter(1).get_type() == meta::resolve_type<const ivec2&>());
|
||||
CHECK(iadd2_func.get_parameter(1).get_position() == 1);
|
||||
CHECK(iadd2_func.get_parameter(1).get_name() == "r");
|
||||
|
||||
CHECK_FALSE(iadd2_func.get_parameter(2));
|
||||
}
|
||||
|
||||
const meta::function iadd3_func = math_scope.get_function("iadd3");
|
||||
REQUIRE(iadd3_func);
|
||||
|
||||
{
|
||||
CHECK(iadd3_func.get_parameters().size() == 2);
|
||||
|
||||
REQUIRE(iadd3_func.get_parameter(0));
|
||||
CHECK(iadd3_func.get_parameter(0).get_type() == meta::resolve_type<const ivec3&>());
|
||||
CHECK(iadd3_func.get_parameter(0).get_position() == 0);
|
||||
CHECK(iadd3_func.get_parameter(0).get_name() == "l");
|
||||
|
||||
REQUIRE(iadd3_func.get_parameter(1));
|
||||
CHECK(iadd3_func.get_parameter(1).get_type() == meta::resolve_type<const ivec3&>());
|
||||
CHECK(iadd3_func.get_parameter(1).get_position() == 1);
|
||||
CHECK(iadd3_func.get_parameter(1).get_name() == "");
|
||||
|
||||
CHECK_FALSE(iadd3_func.get_parameter(2));
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("variables") {
|
||||
|
||||
Reference in New Issue
Block a user