class_db.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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. HashMap<StringName, Vector<uint32_t>> virtual_methods_compat;
  112. StringName inherits;
  113. StringName name;
  114. bool disabled = false;
  115. bool exposed = false;
  116. bool reloadable = false;
  117. bool is_virtual = false;
  118. bool is_runtime = false;
  119. // The bool argument indicates the need to postinitialize.
  120. Object *(*creation_func)(bool) = nullptr;
  121. ClassInfo() {}
  122. ~ClassInfo() {}
  123. };
  124. template <typename T>
  125. static Object *creator(bool p_notify_postinitialize) {
  126. Object *ret = new ("") T;
  127. ret->_initialize();
  128. if (p_notify_postinitialize) {
  129. ret->_postinitialize();
  130. }
  131. return ret;
  132. }
  133. static RWLock lock;
  134. static HashMap<StringName, ClassInfo> classes;
  135. static HashMap<StringName, StringName> resource_base_extensions;
  136. static HashMap<StringName, StringName> compat_classes;
  137. #ifdef TOOLS_ENABLED
  138. static HashMap<StringName, ObjectGDExtension> placeholder_extensions;
  139. #endif
  140. #ifdef DEBUG_METHODS_ENABLED
  141. 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);
  142. #else
  143. 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);
  144. #endif
  145. static APIType current_api;
  146. static HashMap<APIType, uint32_t> api_hashes_cache;
  147. static void _add_class2(const StringName &p_class, const StringName &p_inherits);
  148. static HashMap<StringName, HashMap<StringName, Variant>> default_values;
  149. static HashSet<StringName> default_values_cached;
  150. // Native structs, used by binder
  151. struct NativeStruct {
  152. 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.
  153. uint64_t struct_size; // local size of struct, for comparison
  154. };
  155. static HashMap<StringName, NativeStruct> native_structs;
  156. static Array default_array_arg;
  157. static bool is_default_array_arg(const Array &p_array);
  158. private:
  159. // Non-locking variants of get_parent_class and is_parent_class.
  160. static StringName _get_parent_class(const StringName &p_class);
  161. static bool _is_parent_class(const StringName &p_class, const StringName &p_inherits);
  162. static void _bind_compatibility(ClassInfo *type, MethodBind *p_method);
  163. static MethodBind *_bind_vararg_method(MethodBind *p_bind, const StringName &p_name, const Vector<Variant> &p_default_args, bool p_compatibility);
  164. static void _bind_method_custom(const StringName &p_class, MethodBind *p_method, bool p_compatibility);
  165. static Object *_instantiate_internal(const StringName &p_class, bool p_require_real_class = false, bool p_notify_postinitialize = true);
  166. static bool _can_instantiate(ClassInfo *p_class_info);
  167. public:
  168. // DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
  169. template <typename T>
  170. static void _add_class() {
  171. _add_class2(T::get_class_static(), T::get_parent_class_static());
  172. }
  173. template <typename T>
  174. static void register_class(bool p_virtual = false) {
  175. GLOBAL_LOCK_FUNCTION;
  176. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  177. T::initialize_class();
  178. ClassInfo *t = classes.getptr(T::get_class_static());
  179. ERR_FAIL_NULL(t);
  180. t->creation_func = &creator<T>;
  181. t->exposed = true;
  182. t->is_virtual = p_virtual;
  183. t->class_ptr = T::get_class_ptr_static();
  184. t->api = current_api;
  185. T::register_custom_data_to_otdb();
  186. }
  187. template <typename T>
  188. static void register_abstract_class() {
  189. GLOBAL_LOCK_FUNCTION;
  190. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  191. T::initialize_class();
  192. ClassInfo *t = classes.getptr(T::get_class_static());
  193. ERR_FAIL_NULL(t);
  194. t->exposed = true;
  195. t->class_ptr = T::get_class_ptr_static();
  196. t->api = current_api;
  197. //nothing
  198. }
  199. template <typename T>
  200. static void register_internal_class() {
  201. GLOBAL_LOCK_FUNCTION;
  202. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  203. T::initialize_class();
  204. ClassInfo *t = classes.getptr(T::get_class_static());
  205. ERR_FAIL_NULL(t);
  206. t->creation_func = &creator<T>;
  207. t->exposed = false;
  208. t->is_virtual = false;
  209. t->class_ptr = T::get_class_ptr_static();
  210. t->api = current_api;
  211. T::register_custom_data_to_otdb();
  212. }
  213. template <typename T>
  214. static void register_runtime_class() {
  215. GLOBAL_LOCK_FUNCTION;
  216. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  217. T::initialize_class();
  218. ClassInfo *t = classes.getptr(T::get_class_static());
  219. ERR_FAIL_NULL(t);
  220. 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()));
  221. t->creation_func = &creator<T>;
  222. t->exposed = true;
  223. t->is_virtual = false;
  224. t->is_runtime = true;
  225. t->class_ptr = T::get_class_ptr_static();
  226. t->api = current_api;
  227. T::register_custom_data_to_otdb();
  228. }
  229. static void register_extension_class(ObjectGDExtension *p_extension);
  230. static void unregister_extension_class(const StringName &p_class, bool p_free_method_binds = true);
  231. template <typename T>
  232. static Object *_create_ptr_func(bool p_notify_postinitialize) {
  233. return T::create(p_notify_postinitialize);
  234. }
  235. template <typename T>
  236. static void register_custom_instance_class() {
  237. GLOBAL_LOCK_FUNCTION;
  238. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  239. T::initialize_class();
  240. ClassInfo *t = classes.getptr(T::get_class_static());
  241. ERR_FAIL_NULL(t);
  242. t->creation_func = &_create_ptr_func<T>;
  243. t->exposed = true;
  244. t->class_ptr = T::get_class_ptr_static();
  245. t->api = current_api;
  246. T::register_custom_data_to_otdb();
  247. }
  248. static void get_class_list(List<StringName> *p_classes);
  249. #ifdef TOOLS_ENABLED
  250. static void get_extensions_class_list(List<StringName> *p_classes);
  251. static void get_extension_class_list(const Ref<GDExtension> &p_extension, List<StringName> *p_classes);
  252. static ObjectGDExtension *get_placeholder_extension(const StringName &p_class);
  253. #endif
  254. static void get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
  255. static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
  256. static StringName get_parent_class_nocheck(const StringName &p_class);
  257. static bool get_inheritance_chain_nocheck(const StringName &p_class, Vector<StringName> &r_result);
  258. static StringName get_parent_class(const StringName &p_class);
  259. static StringName get_compatibility_remapped_class(const StringName &p_class);
  260. static bool class_exists(const StringName &p_class);
  261. static bool is_parent_class(const StringName &p_class, const StringName &p_inherits);
  262. static bool can_instantiate(const StringName &p_class);
  263. static bool is_abstract(const StringName &p_class);
  264. static bool is_virtual(const StringName &p_class);
  265. static Object *instantiate(const StringName &p_class);
  266. static Object *instantiate_no_placeholders(const StringName &p_class);
  267. static Object *instantiate_without_postinitialization(const StringName &p_class);
  268. static void set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance);
  269. static APIType get_api_type(const StringName &p_class);
  270. static uint32_t get_api_hash(APIType p_api);
  271. template <typename>
  272. struct member_function_traits;
  273. template <typename R, typename T, typename... Args>
  274. struct member_function_traits<R (T::*)(Args...)> {
  275. using return_type = R;
  276. };
  277. template <typename R, typename T, typename... Args>
  278. struct member_function_traits<R (T::*)(Args...) const> {
  279. using return_type = R;
  280. };
  281. template <typename R, typename... Args>
  282. struct member_function_traits<R (*)(Args...)> {
  283. using return_type = R;
  284. };
  285. template <typename N, typename M, typename... VarArgs>
  286. static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args) {
  287. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  288. const Variant *argptrs[sizeof...(p_args) + 1];
  289. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  290. argptrs[i] = &args[i];
  291. }
  292. MethodBind *bind = create_method_bind(p_method);
  293. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  294. bind->set_return_type_is_raw_object_ptr(true);
  295. }
  296. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  297. }
  298. template <typename N, typename M, typename... VarArgs>
  299. static MethodBind *bind_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
  300. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  301. const Variant *argptrs[sizeof...(p_args) + 1];
  302. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  303. argptrs[i] = &args[i];
  304. }
  305. MethodBind *bind = create_static_method_bind(p_method);
  306. bind->set_instance_class(p_class);
  307. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  308. bind->set_return_type_is_raw_object_ptr(true);
  309. }
  310. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  311. }
  312. template <typename N, typename M, typename... VarArgs>
  313. static MethodBind *bind_compatibility_method(N p_method_name, M p_method, VarArgs... p_args) {
  314. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  315. const Variant *argptrs[sizeof...(p_args) + 1];
  316. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  317. argptrs[i] = &args[i];
  318. }
  319. MethodBind *bind = create_method_bind(p_method);
  320. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  321. bind->set_return_type_is_raw_object_ptr(true);
  322. }
  323. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  324. }
  325. template <typename N, typename M, typename... VarArgs>
  326. static MethodBind *bind_compatibility_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
  327. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  328. const Variant *argptrs[sizeof...(p_args) + 1];
  329. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  330. argptrs[i] = &args[i];
  331. }
  332. MethodBind *bind = create_static_method_bind(p_method);
  333. bind->set_instance_class(p_class);
  334. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  335. bind->set_return_type_is_raw_object_ptr(true);
  336. }
  337. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  338. }
  339. template <typename M>
  340. 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) {
  341. GLOBAL_LOCK_FUNCTION;
  342. MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
  343. ERR_FAIL_NULL_V(bind, nullptr);
  344. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  345. bind->set_return_type_is_raw_object_ptr(true);
  346. }
  347. return _bind_vararg_method(bind, p_name, p_default_args, false);
  348. }
  349. template <typename M>
  350. 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) {
  351. GLOBAL_LOCK_FUNCTION;
  352. MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
  353. ERR_FAIL_NULL_V(bind, nullptr);
  354. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  355. bind->set_return_type_is_raw_object_ptr(true);
  356. }
  357. return _bind_vararg_method(bind, p_name, p_default_args, true);
  358. }
  359. static void bind_method_custom(const StringName &p_class, MethodBind *p_method);
  360. static void bind_compatibility_method_custom(const StringName &p_class, MethodBind *p_method);
  361. static void add_signal(const StringName &p_class, const MethodInfo &p_signal);
  362. static bool has_signal(const StringName &p_class, const StringName &p_signal, bool p_no_inheritance = false);
  363. static bool get_signal(const StringName &p_class, const StringName &p_signal, MethodInfo *r_signal);
  364. static void get_signal_list(const StringName &p_class, List<MethodInfo> *p_signals, bool p_no_inheritance = false);
  365. static void add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
  366. static void add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
  367. 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);
  368. static void add_property_array(const StringName &p_class, const StringName &p_path, const String &p_array_element_prefix);
  369. static void add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
  370. static void set_property_default_value(const StringName &p_class, const StringName &p_name, const Variant &p_default);
  371. static void add_linked_property(const StringName &p_class, const String &p_property, const String &p_linked_property);
  372. static void get_property_list(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance = false, const Object *p_validator = nullptr);
  373. 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);
  374. static void get_linked_properties_info(const StringName &p_class, const StringName &p_property, List<StringName> *r_properties, bool p_no_inheritance = false);
  375. static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = nullptr);
  376. static bool get_property(Object *p_object, const StringName &p_property, Variant &r_value);
  377. static bool has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance = false);
  378. static int get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
  379. static Variant::Type get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
  380. static StringName get_property_setter(const StringName &p_class, const StringName &p_property);
  381. static StringName get_property_getter(const StringName &p_class, const StringName &p_property);
  382. static bool has_method(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false);
  383. static void set_method_flags(const StringName &p_class, const StringName &p_method, int p_flags);
  384. static void get_method_list(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
  385. 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);
  386. 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);
  387. static int get_method_argument_count(const StringName &p_class, const StringName &p_method, bool *r_is_valid = nullptr, bool p_no_inheritance = false);
  388. static MethodBind *get_method(const StringName &p_class, const StringName &p_name);
  389. 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);
  390. static Vector<uint32_t> get_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
  391. 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);
  392. static void add_virtual_compatibility_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);
  393. static void get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false);
  394. static void add_extension_class_virtual_method(const StringName &p_class, const GDExtensionClassVirtualMethodInfo *p_method_info);
  395. static Vector<uint32_t> get_virtual_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
  396. 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);
  397. static void get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance = false);
  398. static int64_t get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = nullptr);
  399. static bool has_integer_constant(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  400. static StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  401. static StringName get_integer_constant_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  402. static void get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance = false);
  403. static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance = false);
  404. static bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  405. static bool is_enum_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  406. static void set_method_error_return_values(const StringName &p_class, const StringName &p_method, const Vector<Error> &p_values);
  407. static Vector<Error> get_method_error_return_values(const StringName &p_class, const StringName &p_method);
  408. static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid = nullptr);
  409. static void set_class_enabled(const StringName &p_class, bool p_enable);
  410. static bool is_class_enabled(const StringName &p_class);
  411. static bool is_class_exposed(const StringName &p_class);
  412. static bool is_class_reloadable(const StringName &p_class);
  413. static bool is_class_runtime(const StringName &p_class);
  414. static void add_resource_base_extension(const StringName &p_extension, const StringName &p_class);
  415. static void get_resource_base_extensions(List<String> *p_extensions);
  416. static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions);
  417. static bool is_resource_extension(const StringName &p_extension);
  418. static void add_compatibility_class(const StringName &p_class, const StringName &p_fallback);
  419. static StringName get_compatibility_class(const StringName &p_class);
  420. static void set_current_api(APIType p_api);
  421. static APIType get_current_api();
  422. static void cleanup_defaults();
  423. static void cleanup();
  424. static void register_native_struct(const StringName &p_name, const String &p_code, uint64_t p_current_size);
  425. static void get_native_struct_list(List<StringName> *r_names);
  426. static String get_native_struct_code(const StringName &p_name);
  427. static uint64_t get_native_struct_size(const StringName &p_name); // Used for asserting
  428. };
  429. #define BIND_ENUM_CONSTANT(m_constant) \
  430. ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant);
  431. #define BIND_BITFIELD_FLAG(m_constant) \
  432. ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_bitfield_name(m_constant, #m_constant), #m_constant, m_constant, true);
  433. #define BIND_CONSTANT(m_constant) \
  434. ::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
  435. #ifdef DEBUG_METHODS_ENABLED
  436. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr) {
  437. }
  438. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr, const Error &p_err) {
  439. arr.push_back(p_err);
  440. }
  441. template <typename... P>
  442. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr, const Error &p_err, P... p_args) {
  443. arr.push_back(p_err);
  444. errarray_add_str(arr, p_args...);
  445. }
  446. template <typename... P>
  447. _FORCE_INLINE_ Vector<Error> errarray(P... p_args) {
  448. Vector<Error> arr;
  449. errarray_add_str(arr, p_args...);
  450. return arr;
  451. }
  452. #define BIND_METHOD_ERR_RETURN_DOC(m_method, ...) \
  453. ::ClassDB::set_method_error_return_values(get_class_static(), m_method, errarray(__VA_ARGS__));
  454. #else
  455. #define BIND_METHOD_ERR_RETURN_DOC(m_method, ...)
  456. #endif
  457. #define GDREGISTER_CLASS(m_class) \
  458. if (m_class::_class_is_enabled) { \
  459. ::ClassDB::register_class<m_class>(); \
  460. }
  461. #define GDREGISTER_VIRTUAL_CLASS(m_class) \
  462. if (m_class::_class_is_enabled) { \
  463. ::ClassDB::register_class<m_class>(true); \
  464. }
  465. #define GDREGISTER_ABSTRACT_CLASS(m_class) \
  466. if (m_class::_class_is_enabled) { \
  467. ::ClassDB::register_abstract_class<m_class>(); \
  468. }
  469. #define GDREGISTER_INTERNAL_CLASS(m_class) \
  470. if (m_class::_class_is_enabled) { \
  471. ::ClassDB::register_internal_class<m_class>(); \
  472. }
  473. #define GDREGISTER_RUNTIME_CLASS(m_class) \
  474. if (m_class::_class_is_enabled) { \
  475. ::ClassDB::register_runtime_class<m_class>(); \
  476. }
  477. #define GDREGISTER_NATIVE_STRUCT(m_class, m_code) ClassDB::register_native_struct(#m_class, m_code, sizeof(m_class))
  478. #include "core/disabled_classes.gen.h"
  479. #endif // CLASS_DB_H