diff --git a/headers/meta.hpp/meta_all.hpp b/headers/meta.hpp/meta_all.hpp index d903251..45fe3a7 100644 --- a/headers/meta.hpp/meta_all.hpp +++ b/headers/meta.hpp/meta_all.hpp @@ -31,6 +31,7 @@ #include "meta_states/function.hpp" #include "meta_states/member.hpp" #include "meta_states/method.hpp" +#include "meta_states/parameter.hpp" #include "meta_states/scope.hpp" #include "meta_states/variable.hpp" diff --git a/headers/meta.hpp/meta_base.hpp b/headers/meta.hpp/meta_base.hpp index 8591464..868a172 100644 --- a/headers/meta.hpp/meta_base.hpp +++ b/headers/meta.hpp/meta_base.hpp @@ -109,6 +109,7 @@ namespace meta_hpp class function; class member; class method; + class parameter; class scope; class variable; @@ -120,6 +121,7 @@ namespace meta_hpp struct function_state; struct member_state; struct method_state; + struct parameter_state; struct scope_state; struct variable_state; @@ -129,6 +131,7 @@ namespace meta_hpp using function_state_ptr = std::shared_ptr; using member_state_ptr = std::shared_ptr; using method_state_ptr = std::shared_ptr; + using parameter_state_ptr = std::shared_ptr; using scope_state_ptr = std::shared_ptr; using variable_state_ptr = std::shared_ptr; } diff --git a/headers/meta.hpp/meta_detail/state_family.hpp b/headers/meta.hpp/meta_detail/state_family.hpp index a580340..18c4865 100644 --- a/headers/meta.hpp/meta_detail/state_family.hpp +++ b/headers/meta.hpp/meta_detail/state_family.hpp @@ -18,6 +18,7 @@ namespace meta_hpp::detail std::is_same_v || std::is_same_v || std::is_same_v || + std::is_same_v || std::is_same_v || std::is_same_v; diff --git a/headers/meta.hpp/meta_states.hpp b/headers/meta.hpp/meta_states.hpp index 3f590cd..589bafe 100644 --- a/headers/meta.hpp/meta_states.hpp +++ b/headers/meta.hpp/meta_states.hpp @@ -267,6 +267,22 @@ namespace meta_hpp friend auto detail::state_access(const method&); }; + class parameter final { + public: + explicit parameter() = default; + explicit parameter(detail::parameter_state_ptr state); + + [[nodiscard]] bool is_valid() const noexcept; + [[nodiscard]] explicit operator bool() const noexcept; + + [[nodiscard]] const parameter_index& get_index() const noexcept; + [[nodiscard]] const any_type& get_type() const noexcept; + [[nodiscard]] const std::string& get_name() const noexcept; + private: + detail::parameter_state_ptr state_; + friend auto detail::state_access(const parameter&); + }; + class scope final { public: explicit scope() = default; @@ -440,6 +456,13 @@ namespace meta_hpp::detail [[nodiscard]] static method_state_ptr make(std::string name, Method method); }; + struct parameter_state final { + parameter_index index; + + template < typename Parameter > + [[nodiscard]] static parameter_state_ptr make(std::string name); + }; + struct scope_state final { scope_index index; diff --git a/headers/meta.hpp/meta_states/parameter.hpp b/headers/meta.hpp/meta_states/parameter.hpp new file mode 100644 index 0000000..4060458 --- /dev/null +++ b/headers/meta.hpp/meta_states/parameter.hpp @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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) + ******************************************************************************/ + +#pragma once + +#include "../meta_base.hpp" +#include "../meta_states.hpp" + +namespace meta_hpp::detail +{ + template < typename Parameter > + inline parameter_state_ptr parameter_state::make(std::string name) { + return std::make_shared(parameter_state{ + .index{parameter_index::make(std::move(name))}, + }); + } +} + +namespace meta_hpp +{ + + inline parameter::parameter(detail::parameter_state_ptr state) + : state_{std::move(state)} {} + + inline bool parameter::is_valid() const noexcept { + return !!state_; + } + + inline parameter::operator bool() const noexcept { + return is_valid(); + } + + inline const parameter_index& parameter::get_index() const noexcept { + return state_->index; + } + + inline const any_type& parameter::get_type() const noexcept { + return state_->index.get_type(); + } + + inline const std::string& parameter::get_name() const noexcept { + return state_->index.get_name(); + } +}