BsMonoAssembly.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsMonoPrerequisites.h"
  5. #include <mono/jit/jit.h>
  6. #include <mono/metadata/assembly.h>
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Mono
  10. * @{
  11. */
  12. /** Contains information about a single Mono (i.e. managed) assembly. */
  13. class BS_MONO_EXPORT MonoAssembly
  14. {
  15. public:
  16. /** Used for uniquely identifying a managed class, normally for use in containers. */
  17. struct ClassId
  18. {
  19. struct Hash
  20. {
  21. inline size_t operator()(const ClassId& v) const;
  22. };
  23. struct Equals
  24. {
  25. inline bool operator()(const ClassId &a, const ClassId &b) const;
  26. };
  27. ClassId();
  28. ClassId(const String& namespaceName, String name, ::MonoClass* genericInstance = nullptr);
  29. String namespaceName;
  30. String name;
  31. ::MonoClass* genericInstance;
  32. };
  33. public:
  34. virtual ~MonoAssembly();
  35. /** Returns the name of this assembly. */
  36. const String& getName() const { return mName; }
  37. /**
  38. * Attempts to find a managed class with the specified namespace and name in this assembly. Returns null if one
  39. * cannot be found.
  40. */
  41. MonoClass* getClass(const String& namespaceName, const String& name) const;
  42. /** Converts an internal mono representation of a class into engine class. */
  43. MonoClass* getClass(::MonoClass* rawMonoClass) const;
  44. /** Returns a list of all classes in the assembly. */
  45. const Vector<MonoClass*>& getAllClasses() const;
  46. /**
  47. * Invokes a zero-parameter static method in the format "Class::Method". Used primarily for invoking an assembly
  48. * entry point.
  49. */
  50. void invoke(const String& functionName);
  51. private:
  52. friend class MonoManager;
  53. MonoAssembly(const String& path, const String& name);
  54. /**
  55. * Attempts to find a managed class with the specified namespace and name in this assembly. Registers a new class
  56. * using the provided raw class if one cannot be found. Returns null provided raw class is null.
  57. */
  58. MonoClass* getClass(const String& namespaceName, const String& name, ::MonoClass* rawMonoClass) const;
  59. /** Loads an assembly into the specified domain. */
  60. void load(MonoDomain* domain);
  61. /**
  62. * Initializes an assembly from an internal mono image.
  63. *
  64. * @note
  65. * Normally used for assemblies that were already loaded by the managed runtime as dependencies.
  66. */
  67. void loadFromImage(MonoImage* image);
  68. /**
  69. * Unloads the assembly and all the types associated with it. Caller must ensure not to use any types from this
  70. * assembly after it has been unloaded.
  71. */
  72. void unload();
  73. /**
  74. * Returns true if the provided name represents a generic class.
  75. *
  76. * @note This method only analyzes the name to determine if it is in generic class format.
  77. */
  78. bool isGenericClass(const String& name) const;
  79. String mName;
  80. String mPath;
  81. MonoImage* mMonoImage;
  82. ::MonoAssembly* mMonoAssembly;
  83. bool mIsLoaded;
  84. bool mIsDependency;
  85. mutable UnorderedMap<ClassId, MonoClass*, ClassId::Hash, ClassId::Equals> mClasses;
  86. mutable UnorderedMap<::MonoClass*, MonoClass*> mClassesByRaw;
  87. mutable bool mHaveCachedClassList;
  88. mutable Vector<MonoClass*> mCachedClassList;
  89. };
  90. /** @} */
  91. }