class_db.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /**************************************************************************/
  2. /* class_db.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef CLASS_DB_H
  31. #define CLASS_DB_H
  32. #include "core/object/method_bind.h"
  33. #include "core/object/object.h"
  34. #include "core/string/print_string.h"
  35. // Makes callable_mp readily available in all classes connecting signals.
  36. // Needs to come after method_bind and object have been included.
  37. #include "core/object/callable_method_pointer.h"
  38. #include "core/templates/hash_set.h"
  39. #include <type_traits>
  40. #define DEFVAL(m_defval) (m_defval)
  41. #define DEFVAL_ARRAY DEFVAL(ClassDB::default_array_arg)
  42. #ifdef DEBUG_METHODS_ENABLED
  43. struct MethodDefinition {
  44. StringName name;
  45. Vector<StringName> args;
  46. MethodDefinition() {}
  47. MethodDefinition(const char *p_name) :
  48. name(p_name) {}
  49. MethodDefinition(const StringName &p_name) :
  50. name(p_name) {}
  51. };
  52. MethodDefinition D_METHODP(const char *p_name, const char *const **p_args, uint32_t p_argcount);
  53. template <typename... VarArgs>
  54. MethodDefinition D_METHOD(const char *p_name, const VarArgs... p_args) {
  55. const char *args[sizeof...(p_args) + 1] = { p_args..., nullptr }; // +1 makes sure zero sized arrays are also supported.
  56. const char *const *argptrs[sizeof...(p_args) + 1];
  57. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  58. argptrs[i] = &args[i];
  59. }
  60. return D_METHODP(p_name, sizeof...(p_args) == 0 ? nullptr : (const char *const **)argptrs, sizeof...(p_args));
  61. }
  62. #else
  63. // When DEBUG_METHODS_ENABLED is set this will let the engine know
  64. // the argument names for easier debugging.
  65. #define D_METHOD(m_c, ...) m_c
  66. #endif
  67. class ClassDB {
  68. public:
  69. enum APIType {
  70. API_CORE,
  71. API_EDITOR,
  72. API_EXTENSION,
  73. API_EDITOR_EXTENSION,
  74. API_NONE
  75. };
  76. public:
  77. struct PropertySetGet {
  78. int index;
  79. StringName setter;
  80. StringName getter;
  81. MethodBind *_setptr = nullptr;
  82. MethodBind *_getptr = nullptr;
  83. Variant::Type type;
  84. };
  85. struct ClassInfo {
  86. APIType api = API_NONE;
  87. ClassInfo *inherits_ptr = nullptr;
  88. void *class_ptr = nullptr;
  89. ObjectGDExtension *gdextension = nullptr;
  90. HashMap<StringName, MethodBind *> method_map;
  91. HashMap<StringName, LocalVector<MethodBind *>> method_map_compatibility;
  92. HashMap<StringName, int64_t> constant_map;
  93. struct EnumInfo {
  94. List<StringName> constants;
  95. bool is_bitfield = false;
  96. };
  97. HashMap<StringName, EnumInfo> enum_map;
  98. HashMap<StringName, MethodInfo> signal_map;
  99. List<PropertyInfo> property_list;
  100. HashMap<StringName, PropertyInfo> property_map;
  101. #ifdef DEBUG_METHODS_ENABLED
  102. List<StringName> constant_order;
  103. List<StringName> method_order;
  104. HashSet<StringName> methods_in_properties;
  105. List<MethodInfo> virtual_methods;
  106. HashMap<StringName, MethodInfo> virtual_methods_map;
  107. HashMap<StringName, Vector<Error>> method_error_values;
  108. HashMap<StringName, List<StringName>> linked_properties;
  109. #endif
  110. HashMap<StringName, PropertySetGet> property_setget;
  111. StringName inherits;
  112. StringName name;
  113. bool disabled = false;
  114. bool exposed = false;
  115. bool reloadable = false;
  116. bool is_virtual = false;
  117. bool is_runtime = false;
  118. // The bool argument indicates the need to postinitialize.
  119. Object *(*creation_func)(bool) = nullptr;
  120. ClassInfo() {}
  121. ~ClassInfo() {}
  122. };
  123. template <typename T>
  124. static Object *creator(bool p_notify_postinitialize) {
  125. Object *ret = new ("") T;
  126. ret->_initialize();
  127. if (p_notify_postinitialize) {
  128. ret->_postinitialize();
  129. }
  130. return ret;
  131. }
  132. static RWLock lock;
  133. static HashMap<StringName, ClassInfo> classes;
  134. static HashMap<StringName, StringName> resource_base_extensions;
  135. static HashMap<StringName, StringName> compat_classes;
  136. #ifdef TOOLS_ENABLED
  137. static HashMap<StringName, ObjectGDExtension> placeholder_extensions;
  138. #endif
  139. #ifdef DEBUG_METHODS_ENABLED
  140. static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_compatibility, const MethodDefinition &method_name, const Variant **p_defs, int p_defcount);
  141. #else
  142. static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_compatibility, const char *method_name, const Variant **p_defs, int p_defcount);
  143. #endif
  144. static APIType current_api;
  145. static HashMap<APIType, uint32_t> api_hashes_cache;
  146. static void _add_class2(const StringName &p_class, const StringName &p_inherits);
  147. static HashMap<StringName, HashMap<StringName, Variant>> default_values;
  148. static HashSet<StringName> default_values_cached;
  149. // Native structs, used by binder
  150. struct NativeStruct {
  151. String ccode; // C code to create the native struct, fields separated by ; Arrays accepted (even containing other structs), also function pointers. All types must be Godot types.
  152. uint64_t struct_size; // local size of struct, for comparison
  153. };
  154. static HashMap<StringName, NativeStruct> native_structs;
  155. static Array default_array_arg;
  156. static bool is_default_array_arg(const Array &p_array);
  157. private:
  158. // Non-locking variants of get_parent_class and is_parent_class.
  159. static StringName _get_parent_class(const StringName &p_class);
  160. static bool _is_parent_class(const StringName &p_class, const StringName &p_inherits);
  161. static void _bind_compatibility(ClassInfo *type, MethodBind *p_method);
  162. static MethodBind *_bind_vararg_method(MethodBind *p_bind, const StringName &p_name, const Vector<Variant> &p_default_args, bool p_compatibility);
  163. static void _bind_method_custom(const StringName &p_class, MethodBind *p_method, bool p_compatibility);
  164. static Object *_instantiate_internal(const StringName &p_class, bool p_require_real_class = false, bool p_notify_postinitialize = true);
  165. static bool _can_instantiate(ClassInfo *p_class_info);
  166. public:
  167. // DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
  168. template <typename T>
  169. static void _add_class() {
  170. _add_class2(T::get_class_static(), T::get_parent_class_static());
  171. }
  172. template <typename T>
  173. static void register_class(bool p_virtual = false) {
  174. GLOBAL_LOCK_FUNCTION;
  175. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  176. T::initialize_class();
  177. ClassInfo *t = classes.getptr(T::get_class_static());
  178. ERR_FAIL_NULL(t);
  179. t->creation_func = &creator<T>;
  180. t->exposed = true;
  181. t->is_virtual = p_virtual;
  182. t->class_ptr = T::get_class_ptr_static();
  183. t->api = current_api;
  184. T::register_custom_data_to_otdb();
  185. }
  186. template <typename T>
  187. static void register_abstract_class() {
  188. GLOBAL_LOCK_FUNCTION;
  189. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  190. T::initialize_class();
  191. ClassInfo *t = classes.getptr(T::get_class_static());
  192. ERR_FAIL_NULL(t);
  193. t->exposed = true;
  194. t->class_ptr = T::get_class_ptr_static();
  195. t->api = current_api;
  196. //nothing
  197. }
  198. template <typename T>
  199. static void register_internal_class() {
  200. GLOBAL_LOCK_FUNCTION;
  201. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  202. T::initialize_class();
  203. ClassInfo *t = classes.getptr(T::get_class_static());
  204. ERR_FAIL_NULL(t);
  205. t->creation_func = &creator<T>;
  206. t->exposed = false;
  207. t->is_virtual = false;
  208. t->class_ptr = T::get_class_ptr_static();
  209. t->api = current_api;
  210. T::register_custom_data_to_otdb();
  211. }
  212. template <typename T>
  213. static void register_runtime_class() {
  214. GLOBAL_LOCK_FUNCTION;
  215. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  216. T::initialize_class();
  217. ClassInfo *t = classes.getptr(T::get_class_static());
  218. ERR_FAIL_NULL(t);
  219. ERR_FAIL_COND_MSG(t->inherits_ptr && !t->inherits_ptr->creation_func, vformat("Cannot register runtime class '%s' that descends from an abstract parent class.", T::get_class_static()));
  220. t->creation_func = &creator<T>;
  221. t->exposed = true;
  222. t->is_virtual = false;
  223. t->is_runtime = true;
  224. t->class_ptr = T::get_class_ptr_static();
  225. t->api = current_api;
  226. T::register_custom_data_to_otdb();
  227. }
  228. static void register_extension_class(ObjectGDExtension *p_extension);
  229. static void unregister_extension_class(const StringName &p_class, bool p_free_method_binds = true);
  230. template <typename T>
  231. static Object *_create_ptr_func(bool p_notify_postinitialize) {
  232. return T::create(p_notify_postinitialize);
  233. }
  234. template <typename T>
  235. static void register_custom_instance_class() {
  236. GLOBAL_LOCK_FUNCTION;
  237. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  238. T::initialize_class();
  239. ClassInfo *t = classes.getptr(T::get_class_static());
  240. ERR_FAIL_NULL(t);
  241. t->creation_func = &_create_ptr_func<T>;
  242. t->exposed = true;
  243. t->class_ptr = T::get_class_ptr_static();
  244. t->api = current_api;
  245. T::register_custom_data_to_otdb();
  246. }
  247. static void get_class_list(List<StringName> *p_classes);
  248. #ifdef TOOLS_ENABLED
  249. static void get_extensions_class_list(List<StringName> *p_classes);
  250. static void get_extension_class_list(const Ref<GDExtension> &p_extension, List<StringName> *p_classes);
  251. static ObjectGDExtension *get_placeholder_extension(const StringName &p_class);
  252. #endif
  253. static void get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
  254. static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
  255. static StringName get_parent_class_nocheck(const StringName &p_class);
  256. static bool get_inheritance_chain_nocheck(const StringName &p_class, Vector<StringName> &r_result);
  257. static StringName get_parent_class(const StringName &p_class);
  258. static StringName get_compatibility_remapped_class(const StringName &p_class);
  259. static bool class_exists(const StringName &p_class);
  260. static bool is_parent_class(const StringName &p_class, const StringName &p_inherits);
  261. static bool can_instantiate(const StringName &p_class);
  262. static bool is_abstract(const StringName &p_class);
  263. static bool is_virtual(const StringName &p_class);
  264. static Object *instantiate(const StringName &p_class);
  265. static Object *instantiate_no_placeholders(const StringName &p_class);
  266. static Object *instantiate_without_postinitialization(const StringName &p_class);
  267. static void set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance);
  268. static APIType get_api_type(const StringName &p_class);
  269. static uint32_t get_api_hash(APIType p_api);
  270. template <typename>
  271. struct member_function_traits;
  272. template <typename R, typename T, typename... Args>
  273. struct member_function_traits<R (T::*)(Args...)> {
  274. using return_type = R;
  275. };
  276. template <typename R, typename T, typename... Args>
  277. struct member_function_traits<R (T::*)(Args...) const> {
  278. using return_type = R;
  279. };
  280. template <typename R, typename... Args>
  281. struct member_function_traits<R (*)(Args...)> {
  282. using return_type = R;
  283. };
  284. template <typename N, typename M, typename... VarArgs>
  285. static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args) {
  286. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  287. const Variant *argptrs[sizeof...(p_args) + 1];
  288. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  289. argptrs[i] = &args[i];
  290. }
  291. MethodBind *bind = create_method_bind(p_method);
  292. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  293. bind->set_return_type_is_raw_object_ptr(true);
  294. }
  295. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  296. }
  297. template <typename N, typename M, typename... VarArgs>
  298. static MethodBind *bind_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
  299. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  300. const Variant *argptrs[sizeof...(p_args) + 1];
  301. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  302. argptrs[i] = &args[i];
  303. }
  304. MethodBind *bind = create_static_method_bind(p_method);
  305. bind->set_instance_class(p_class);
  306. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  307. bind->set_return_type_is_raw_object_ptr(true);
  308. }
  309. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  310. }
  311. template <typename N, typename M, typename... VarArgs>
  312. static MethodBind *bind_compatibility_method(N p_method_name, M p_method, VarArgs... p_args) {
  313. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  314. const Variant *argptrs[sizeof...(p_args) + 1];
  315. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  316. argptrs[i] = &args[i];
  317. }
  318. MethodBind *bind = create_method_bind(p_method);
  319. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  320. bind->set_return_type_is_raw_object_ptr(true);
  321. }
  322. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  323. }
  324. template <typename N, typename M, typename... VarArgs>
  325. static MethodBind *bind_compatibility_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
  326. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  327. const Variant *argptrs[sizeof...(p_args) + 1];
  328. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  329. argptrs[i] = &args[i];
  330. }
  331. MethodBind *bind = create_static_method_bind(p_method);
  332. bind->set_instance_class(p_class);
  333. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  334. bind->set_return_type_is_raw_object_ptr(true);
  335. }
  336. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  337. }
  338. template <typename M>
  339. static MethodBind *bind_vararg_method(uint32_t p_flags, const StringName &p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>(), bool p_return_nil_is_variant = true) {
  340. GLOBAL_LOCK_FUNCTION;
  341. MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
  342. ERR_FAIL_NULL_V(bind, nullptr);
  343. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  344. bind->set_return_type_is_raw_object_ptr(true);
  345. }
  346. return _bind_vararg_method(bind, p_name, p_default_args, false);
  347. }
  348. template <typename M>
  349. static MethodBind *bind_compatibility_vararg_method(uint32_t p_flags, const StringName &p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>(), bool p_return_nil_is_variant = true) {
  350. GLOBAL_LOCK_FUNCTION;
  351. MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
  352. ERR_FAIL_NULL_V(bind, nullptr);
  353. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  354. bind->set_return_type_is_raw_object_ptr(true);
  355. }
  356. return _bind_vararg_method(bind, p_name, p_default_args, true);
  357. }
  358. static void bind_method_custom(const StringName &p_class, MethodBind *p_method);
  359. static void bind_compatibility_method_custom(const StringName &p_class, MethodBind *p_method);
  360. static void add_signal(const StringName &p_class, const MethodInfo &p_signal);
  361. static bool has_signal(const StringName &p_class, const StringName &p_signal, bool p_no_inheritance = false);
  362. static bool get_signal(const StringName &p_class, const StringName &p_signal, MethodInfo *r_signal);
  363. static void get_signal_list(const StringName &p_class, List<MethodInfo> *p_signals, bool p_no_inheritance = false);
  364. static void add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
  365. static void add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
  366. static void add_property_array_count(const StringName &p_class, const String &p_label, const StringName &p_count_property, const StringName &p_count_setter, const StringName &p_count_getter, const String &p_array_element_prefix, uint32_t p_count_usage = PROPERTY_USAGE_DEFAULT);
  367. static void add_property_array(const StringName &p_class, const StringName &p_path, const String &p_array_element_prefix);
  368. static void add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
  369. static void set_property_default_value(const StringName &p_class, const StringName &p_name, const Variant &p_default);
  370. static void add_linked_property(const StringName &p_class, const String &p_property, const String &p_linked_property);
  371. static void get_property_list(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance = false, const Object *p_validator = nullptr);
  372. static bool get_property_info(const StringName &p_class, const StringName &p_property, PropertyInfo *r_info, bool p_no_inheritance = false, const Object *p_validator = nullptr);
  373. static void get_linked_properties_info(const StringName &p_class, const StringName &p_property, List<StringName> *r_properties, bool p_no_inheritance = false);
  374. static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = nullptr);
  375. static bool get_property(Object *p_object, const StringName &p_property, Variant &r_value);
  376. static bool has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance = false);
  377. static int get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
  378. static Variant::Type get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
  379. static StringName get_property_setter(const StringName &p_class, const StringName &p_property);
  380. static StringName get_property_getter(const StringName &p_class, const StringName &p_property);
  381. static bool has_method(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false);
  382. static void set_method_flags(const StringName &p_class, const StringName &p_method, int p_flags);
  383. static void get_method_list(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
  384. static void get_method_list_with_compatibility(const StringName &p_class, List<Pair<MethodInfo, uint32_t>> *p_methods_with_hash, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
  385. static bool get_method_info(const StringName &p_class, const StringName &p_method, MethodInfo *r_info, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
  386. static int get_method_argument_count(const StringName &p_class, const StringName &p_method, bool *r_is_valid = nullptr, bool p_no_inheritance = false);
  387. static MethodBind *get_method(const StringName &p_class, const StringName &p_name);
  388. static MethodBind *get_method_with_compatibility(const StringName &p_class, const StringName &p_name, uint64_t p_hash, bool *r_method_exists = nullptr, bool *r_is_deprecated = nullptr);
  389. static Vector<uint32_t> get_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
  390. static void add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual = true, const Vector<String> &p_arg_names = Vector<String>(), bool p_object_core = false);
  391. static void get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false);
  392. static void add_extension_class_virtual_method(const StringName &p_class, const GDExtensionClassVirtualMethodInfo *p_method_info);
  393. static void bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int64_t p_constant, bool p_is_bitfield = false);
  394. static void get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance = false);
  395. static int64_t get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = nullptr);
  396. static bool has_integer_constant(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  397. static StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  398. static StringName get_integer_constant_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  399. static void get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance = false);
  400. static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance = false);
  401. static bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  402. static bool is_enum_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  403. static void set_method_error_return_values(const StringName &p_class, const StringName &p_method, const Vector<Error> &p_values);
  404. static Vector<Error> get_method_error_return_values(const StringName &p_class, const StringName &p_method);
  405. static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid = nullptr);
  406. static void set_class_enabled(const StringName &p_class, bool p_enable);
  407. static bool is_class_enabled(const StringName &p_class);
  408. static bool is_class_exposed(const StringName &p_class);
  409. static bool is_class_reloadable(const StringName &p_class);
  410. static bool is_class_runtime(const StringName &p_class);
  411. static void add_resource_base_extension(const StringName &p_extension, const StringName &p_class);
  412. static void get_resource_base_extensions(List<String> *p_extensions);
  413. static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions);
  414. static bool is_resource_extension(const StringName &p_extension);
  415. static void add_compatibility_class(const StringName &p_class, const StringName &p_fallback);
  416. static StringName get_compatibility_class(const StringName &p_class);
  417. static void set_current_api(APIType p_api);
  418. static APIType get_current_api();
  419. static void cleanup_defaults();
  420. static void cleanup();
  421. static void register_native_struct(const StringName &p_name, const String &p_code, uint64_t p_current_size);
  422. static void get_native_struct_list(List<StringName> *r_names);
  423. static String get_native_struct_code(const StringName &p_name);
  424. static uint64_t get_native_struct_size(const StringName &p_name); // Used for asserting
  425. };
  426. #define BIND_ENUM_CONSTANT(m_constant) \
  427. ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant);
  428. #define BIND_BITFIELD_FLAG(m_constant) \
  429. ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_bitfield_name(m_constant, #m_constant), #m_constant, m_constant, true);
  430. #define BIND_CONSTANT(m_constant) \
  431. ::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
  432. #ifdef DEBUG_METHODS_ENABLED
  433. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr) {
  434. }
  435. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr, const Error &p_err) {
  436. arr.push_back(p_err);
  437. }
  438. template <typename... P>
  439. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr, const Error &p_err, P... p_args) {
  440. arr.push_back(p_err);
  441. errarray_add_str(arr, p_args...);
  442. }
  443. template <typename... P>
  444. _FORCE_INLINE_ Vector<Error> errarray(P... p_args) {
  445. Vector<Error> arr;
  446. errarray_add_str(arr, p_args...);
  447. return arr;
  448. }
  449. #define BIND_METHOD_ERR_RETURN_DOC(m_method, ...) \
  450. ::ClassDB::set_method_error_return_values(get_class_static(), m_method, errarray(__VA_ARGS__));
  451. #else
  452. #define BIND_METHOD_ERR_RETURN_DOC(m_method, ...)
  453. #endif
  454. #define GDREGISTER_CLASS(m_class) \
  455. if (m_class::_class_is_enabled) { \
  456. ::ClassDB::register_class<m_class>(); \
  457. }
  458. #define GDREGISTER_VIRTUAL_CLASS(m_class) \
  459. if (m_class::_class_is_enabled) { \
  460. ::ClassDB::register_class<m_class>(true); \
  461. }
  462. #define GDREGISTER_ABSTRACT_CLASS(m_class) \
  463. if (m_class::_class_is_enabled) { \
  464. ::ClassDB::register_abstract_class<m_class>(); \
  465. }
  466. #define GDREGISTER_INTERNAL_CLASS(m_class) \
  467. if (m_class::_class_is_enabled) { \
  468. ::ClassDB::register_internal_class<m_class>(); \
  469. }
  470. #define GDREGISTER_RUNTIME_CLASS(m_class) \
  471. if (m_class::_class_is_enabled) { \
  472. ::ClassDB::register_runtime_class<m_class>(); \
  473. }
  474. #define GDREGISTER_NATIVE_STRUCT(m_class, m_code) ClassDB::register_native_struct(#m_class, m_code, sizeof(m_class))
  475. #include "core/disabled_classes.gen.h"
  476. #endif // CLASS_DB_H