Files
meta.hpp/manuals/api/types.md
2024-02-07 18:19:00 +07:00

11 KiB

API Types

Classes

type_id

class type_id final {
public:
    type_id() = default;
    ~type_id() = default;

    type_id(type_id&&) = default;
    type_id(const type_id&) = default;

    type_id& operator=(type_id&&) = default;
    type_id& operator=(const type_id&) = default;

    bool is_valid() const noexcept;
    explicit operator bool() const noexcept;

    void swap(type_id& other) noexcept;
    std::size_t get_hash() const noexcept;

    bool operator==(const type_id& other) const noexcept;
    std::strong_ordering operator<=>(const type_id& other) const noexcept;
};

type_base

template < type_family Type >
class type_base {
public:
    using id_type = type_id;

    type_base() = default;

    explicit type_base(data_ptr data);

    type_base(type_base&&) = default;
    type_base(const type_base&) = default;

    type_base& operator=(type_base&&) = default;
    type_base& operator=(const type_base&) = default;

    bool is_valid() const noexcept;
    explicit operator bool() const noexcept;

    std::size_t get_hash() const noexcept;

    id_type get_id() const noexcept;
    type_kind get_kind() const noexcept;
    const metadata_map& get_metadata() const noexcept;
};

any_type

class any_type final : public type_base<any_type> {
public:
    using type_base<any_type>::type_base;

    template < type_family Type >
    any_type(const Type& other) noexcept;

    template < type_family Type >
    bool is() const noexcept;
    bool is(type_kind kind) const noexcept;

    template < type_family Type >
    Type as() const noexcept;

    template < typename F >
    bool match(F&& f) const;

    bool is_array() const noexcept;
    bool is_class() const noexcept;
    bool is_constructor() const noexcept;
    bool is_destructor() const noexcept;
    bool is_enum() const noexcept;
    bool is_function() const noexcept;
    bool is_member() const noexcept;
    bool is_method() const noexcept;
    bool is_nullptr() const noexcept;
    bool is_number() const noexcept;
    bool is_pointer() const noexcept;
    bool is_reference() const noexcept;
    bool is_void() const noexcept;

    array_type as_array() const noexcept;
    class_type as_class() const noexcept;
    constructor_type as_constructor() const noexcept;
    destructor_type as_destructor() const noexcept;
    enum_type as_enum() const noexcept;
    function_type as_function() const noexcept;
    member_type as_member() const noexcept;
    method_type as_method() const noexcept;
    nullptr_type as_nullptr() const noexcept;
    number_type as_number() const noexcept;
    pointer_type as_pointer() const noexcept;
    reference_type as_reference() const noexcept;
    void_type as_void() const noexcept;
};

array_type

class array_type final : public type_base<array_type> {
public:
    using type_base<array_type>::type_base;
    array_bitflags get_flags() const noexcept;

    std::size_t get_extent() const noexcept;
    any_type get_data_type() const noexcept;
};

class_type

class class_type final : public type_base<class_type> {
public:
    using type_base<class_type>::type_base;
    class_bitflags get_flags() const noexcept;

    std::size_t get_size() const noexcept;
    std::size_t get_align() const noexcept;

    std::size_t get_arity() const noexcept;
    any_type get_argument_type(std::size_t position) const noexcept;
    const uvalue& get_argument_value(std::size_t position) const noexcept;
    const any_type_list& get_argument_types() const noexcept;
    const uvalue_list& get_argument_values() const noexcept;

    const class_list& get_base_classes() const noexcept;
    const constructor_list& get_constructors() const noexcept;
    const destructor_list& get_destructors() const noexcept;
    const function_list& get_functions() const noexcept;
    const member_list& get_members() const noexcept;
    const method_list& get_methods() const noexcept;
    const typedef_map& get_typedefs() const noexcept;
    const variable_list& get_variables() const noexcept;

    template < typename... Args >
    uvalue create(Args&&... args) const;
    template < typename... Args >
    uvalue create_at(void* mem, Args&&... args) const;

    template < typename Arg >
    bool destroy(Arg&& arg) const;
    bool destroy_at(void* mem) const;

    template < class_kind Derived >
    bool is_base_of() const noexcept;
    bool is_base_of(const class_type& derived) const noexcept;

    template < class_kind Derived >
    bool is_direct_base_of() const noexcept;
    bool is_direct_base_of(const class_type& derived) const noexcept;

    template < class_kind Base >
    bool is_derived_from() const noexcept;
    bool is_derived_from(const class_type& base) const noexcept;

    template < class_kind Base >
    bool is_direct_derived_from() const noexcept;
    bool is_direct_derived_from(const class_type& base) const noexcept;

    function get_function(std::string_view name, bool recursively = true) const noexcept;
    member get_member(std::string_view name, bool recursively = true) const noexcept;
    method get_method(std::string_view name, bool recursively = true) const noexcept;
    any_type get_typedef(std::string_view name, bool recursively = true) const noexcept;
    variable get_variable(std::string_view name, bool recursively = true) const noexcept;

    template < typename... Args >
    constructor get_constructor_with() const noexcept;
    template < typename Iter >
    constructor get_constructor_with(Iter first, Iter last) const noexcept;
    constructor get_constructor_with(std::span<const any_type> args) const noexcept;
    constructor get_constructor_with(std::initializer_list<any_type> args) const noexcept;

    destructor get_destructor() const noexcept;

    template < typename... Args >
    function get_function_with(
        std::string_view name,
        bool recursively = true
    ) const noexcept;

    template < typename Iter >
    function get_function_with(
        std::string_view name,
        Iter first,
        Iter last,
        bool recursively = true
    ) const noexcept;

    function get_function_with(
        std::string_view name,
        std::span<const any_type> args,
        bool recursively = true
    ) const noexcept;

    function get_function_with(
        std::string_view name,
        std::initializer_list<any_type> args,
        bool recursively = true
    ) const noexcept;

    template < typename... Args >
    method get_method_with(
        std::string_view name,
        bool recursively = true
    ) const noexcept;

    template < typename Iter >
    method get_method_with(
        std::string_view name,
        Iter first,
        Iter last,
        bool recursively = true
    ) const noexcept;

    method get_method_with(
        std::string_view name,
        std::span<const any_type> args,
        bool recursively = true
    ) const noexcept;

    method get_method_with(
        std::string_view name,
        std::initializer_list<any_type> args,
        bool recursively = true
    ) const noexcept;
};

constructor_type

class constructor_type final : public type_base<constructor_type> {
public:
    using type_base<constructor_type>::type_base;
    constructor_bitflags get_flags() const noexcept;

    std::size_t get_arity() const noexcept;
    class_type get_owner_type() const noexcept;
    any_type get_argument_type(std::size_t position) const noexcept;
    const any_type_list& get_argument_types() const noexcept;
};

destructor_type

class destructor_type final : public type_base<destructor_type> {
public:
    using type_base<destructor_type>::type_base;
    destructor_bitflags get_flags() const noexcept;

    class_type get_owner_type() const noexcept;
};

enum_type

class enum_type final : public type_base<enum_type> {
public:
    using type_base<enum_type>::type_base;
    enum_bitflags get_flags() const noexcept;

    number_type get_underlying_type() const noexcept;

    const evalue_list& get_evalues() const noexcept;

    evalue get_evalue(std::string_view name) const noexcept;

    template < enum_kind Enum >
    std::string_view value_to_name(Enum value) const noexcept;
    const uvalue& name_to_value(std::string_view name) const noexcept;
};

function_type

class function_type final : public type_base<function_type> {
public:
    using type_base<function_type>::type_base;
    function_bitflags get_flags() const noexcept;

    std::size_t get_arity() const noexcept;
    any_type get_return_type() const noexcept;
    any_type get_argument_type(std::size_t position) const noexcept;
    const any_type_list& get_argument_types() const noexcept;
};

member_type

class member_type final : public type_base<member_type> {
public:
    using type_base<member_type>::type_base;
    member_bitflags get_flags() const noexcept;

    class_type get_owner_type() const noexcept;
    any_type get_value_type() const noexcept;
};

method_type

class method_type final : public type_base<method_type> {
public:
    using type_base<method_type>::type_base;
    method_bitflags get_flags() const noexcept;

    std::size_t get_arity() const noexcept;
    class_type get_owner_type() const noexcept;
    any_type get_return_type() const noexcept;
    any_type get_argument_type(std::size_t position) const noexcept;
    const any_type_list& get_argument_types() const noexcept;
};

nullptr_type

class nullptr_type final : public type_base<nullptr_type> {
public:
    using type_base<nullptr_type>::type_base;
};

number_type

class number_type final : public type_base<number_type> {
public:
    using type_base<number_type>::type_base;
    number_bitflags get_flags() const noexcept;

    std::size_t get_size() const noexcept;
    std::size_t get_align() const noexcept;
};

pointer_type

class pointer_type final : public type_base<pointer_type> {
public:
    using type_base<pointer_type>::type_base;
    pointer_bitflags get_flags() const noexcept;

    any_type get_data_type() const noexcept;
};

reference_type

class reference_type final : public type_base<reference_type> {
public:
    using type_base<reference_type>::type_base;
    reference_bitflags get_flags() const noexcept;

    any_type get_data_type() const noexcept;
};

void_type

class void_type final : public type_base<void_type> {
public:
    using type_base<void_type>::type_base;
};