gd_mono_class.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*************************************************************************/
  2. /* gd_mono_class.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  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 GD_MONO_CLASS_H
  31. #define GD_MONO_CLASS_H
  32. #include <mono/metadata/debug-helpers.h>
  33. #include "map.h"
  34. #include "ustring.h"
  35. #include "gd_mono_field.h"
  36. #include "gd_mono_header.h"
  37. #include "gd_mono_method.h"
  38. #include "gd_mono_utils.h"
  39. class GDMonoClass {
  40. struct MethodKey {
  41. struct Hasher {
  42. static _FORCE_INLINE_ uint32_t hash(const MethodKey &p_key) {
  43. uint32_t hash = 0;
  44. GDMonoUtils::hash_combine(hash, p_key.name.hash());
  45. GDMonoUtils::hash_combine(hash, HashMapHasherDefault::hash(p_key.params_count));
  46. return hash;
  47. }
  48. };
  49. _FORCE_INLINE_ bool operator==(const MethodKey &p_a) const {
  50. return p_a.params_count == params_count && p_a.name == name;
  51. }
  52. MethodKey() {}
  53. MethodKey(const StringName &p_name, int p_params_count) {
  54. name = p_name;
  55. params_count = p_params_count;
  56. }
  57. StringName name;
  58. int params_count;
  59. };
  60. StringName namespace_name;
  61. StringName class_name;
  62. MonoClass *mono_class;
  63. GDMonoAssembly *assembly;
  64. bool attrs_fetched;
  65. MonoCustomAttrInfo *attributes;
  66. bool methods_fetched;
  67. HashMap<MethodKey, GDMonoMethod *, MethodKey::Hasher> methods;
  68. bool fields_fetched;
  69. Map<StringName, GDMonoField *> fields;
  70. Vector<GDMonoField *> fields_list;
  71. friend class GDMonoAssembly;
  72. GDMonoClass(const StringName &p_namespace, const StringName &p_name, MonoClass *p_class, GDMonoAssembly *p_assembly);
  73. public:
  74. static MonoType *get_raw_type(GDMonoClass *p_class);
  75. bool is_assignable_from(GDMonoClass *p_from) const;
  76. _FORCE_INLINE_ StringName get_namespace() const { return namespace_name; }
  77. _FORCE_INLINE_ StringName get_name() const { return class_name; }
  78. _FORCE_INLINE_ MonoClass *get_raw() const { return mono_class; }
  79. _FORCE_INLINE_ const GDMonoAssembly *get_assembly() const { return assembly; }
  80. String get_full_name() const;
  81. GDMonoClass *get_parent_class();
  82. #ifdef TOOLS_ENABLED
  83. Vector<MonoClassField *> get_enum_fields();
  84. #endif
  85. bool has_method(const StringName &p_name);
  86. bool has_attribute(GDMonoClass *p_attr_class);
  87. MonoObject *get_attribute(GDMonoClass *p_attr_class);
  88. void fetch_attributes();
  89. void fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base);
  90. GDMonoMethod *get_method(const StringName &p_name);
  91. GDMonoMethod *get_method(const StringName &p_name, int p_params_count);
  92. GDMonoMethod *get_method(MonoMethod *p_raw_method);
  93. GDMonoMethod *get_method(MonoMethod *p_raw_method, const StringName &p_name);
  94. GDMonoMethod *get_method(MonoMethod *p_raw_method, const StringName &p_name, int p_params_count);
  95. GDMonoMethod *get_method_with_desc(const String &p_description, bool p_includes_namespace);
  96. GDMonoField *get_field(const StringName &p_name);
  97. const Vector<GDMonoField *> &get_all_fields();
  98. ~GDMonoClass();
  99. };
  100. #endif // GD_MONO_CLASS_H