sandbox
Loading...
Searching...
No Matches
type.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_SCRIPTING_MANAGED_TYPE_HPP_
3#define LIBSBX_SCRIPTING_MANAGED_TYPE_HPP_
4
5#include <libsbx/scripting/managed/core.hpp>
6#include <libsbx/scripting/managed/string.hpp>
7#include <libsbx/scripting/managed/object.hpp>
8
9namespace sbx::scripting::managed {
10
11class type {
12
13 friend class host_instance;
14 friend class assembly;
15 friend class assembly_load_context;
16 friend class method_info;
17 friend class field_info;
18 friend class property_info;
19 friend class attribute;
20 friend class reflection_type;
21 friend class object;
22
23public:
24
25 auto get_full_name() const -> string;
26
27 auto get_base_type() -> type&;
28
29 auto get_type_id() const -> type_id;
30
31 auto operator==(const type& other) const -> bool;
32
33 operator bool() const;
34
35 template<typename... Args>
36 auto create_instance(Args&&... args) const -> object {
37 constexpr auto argument_count = sizeof...(args);
38
39 auto result = object{};
40
41 if constexpr (argument_count > 0) {
42 const auto arguments = std::array<void*, argument_count>{};
43 auto argument_types = std::array<managed_type, argument_count>{};
44
45 add_to_array<Args...>(arguments, argument_types, std::forward<Args>(args)..., std::make_index_sequence<argument_count>{});
46
47 result = _create_instance_internal(arguments.data(), argument_types.data(), argument_count);
48 } else {
49 result = _create_instance_internal(nullptr, nullptr, 0);
50 }
51
52 return result;
53 }
54
55private:
56
57 auto _create_instance_internal(const void** parameters, const managed_type* parameter_types, std::size_t length) const -> object;
58
59 type_id _id = -1;
60 type* _base_type = nullptr;
61 type* _element_type = nullptr;
62
63}; // class type
64
66
67public:
68
69 operator type&() const;
70
71public:
72
73 type_id _id = -1;
74
75}; // class reflection_type
76
77static_assert(offsetof(reflection_type, _id) == 0);
78static_assert(sizeof(reflection_type) == 4);
79
80} // namespace sbx::scripting::managed
81
82#endif // LIBSBX_SCRIPTING_MANAGED_TYPE_HPP_
Definition: assembly.hpp:27
Definition: attribute.hpp:11
Definition: field_info.hpp:14
Definition: method_info.hpp:14
Definition: object.hpp:89
Definition: property_info.hpp:14
Definition: string.hpp:11
Definition: type.hpp:11