JSBPackage.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <Atomic/Core/Object.h>
  24. using namespace Atomic;
  25. namespace ToolCore
  26. {
  27. class JSBModule;
  28. class JSBClass;
  29. class JSBEnum;
  30. class JSBEvent;
  31. class JSBPackageWriter;
  32. class JSBPackage : public Object
  33. {
  34. friend class JSPackageWriter;
  35. friend class CSPackageWriter;
  36. ATOMIC_OBJECT(JSBPackage, Object)
  37. public:
  38. enum BindingType
  39. {
  40. JAVASCRIPT,
  41. CSHARP
  42. };
  43. JSBPackage(Context* context);
  44. virtual ~JSBPackage();
  45. bool Load(const String& packageFolder);
  46. Vector<SharedPtr<JSBModule>>& GetModules() {return modules_;}
  47. void PreprocessModules();
  48. void ProcessModules();
  49. const String& GetName() { return name_; }
  50. const String& GetNamespace() { return namespace_; }
  51. /// Returns whether bindings for a specific type should be generated for this package
  52. bool GenerateBindings(BindingType type) { return bindingTypes_.Contains(type); }
  53. JSBClass* GetClass(const String& name, bool includeInterfaces = false);
  54. PODVector<JSBClass*> GetAllClasses(bool includeInterfaces = false);
  55. void RegisterClass(JSBClass* cls) {allClasses_.Push(cls); }
  56. // get a class by name across all loaded packages
  57. static JSBClass* GetClassAllPackages(const String& name, bool includeInterfaces = false);
  58. JSBEnum* GetEnum(const String& name);
  59. // get an enum by name across all loaded packages
  60. static JSBEnum* GetEnumAllPackages(const String& name);
  61. bool ContainsConstant(const String& constantName);
  62. static bool ContainsConstantAllPackages(const String& constantName);
  63. /// Get an event from this package, matches on either eventID or eventName
  64. JSBEvent* GetEvent(const String& eventID, const String& eventName);
  65. // get an event by name across all loaded packages
  66. static JSBEvent* GetEventAllPackages(const String& eventID, const String& eventName);
  67. void GenerateSource(JSBPackageWriter& packageWriter);
  68. /// Define guard for the package as a whole
  69. String GetPlatformDefineGuard() const;
  70. const Vector<String>& GetPlatforms() const { return platforms_; }
  71. const HashMap<String, Vector<String>>& GetModuleExcludes() const { return moduleExcludes_; }
  72. private:
  73. // The name of the package
  74. String name_;
  75. // The name of the C++ namespace if any
  76. String namespace_;
  77. Vector<SharedPtr<JSBPackage> > dependencies_;
  78. Vector<String> platforms_;
  79. HashMap<String, Vector<String>> moduleExcludes_;
  80. Vector<SharedPtr<JSBModule> > modules_;
  81. PODVector<JSBClass*> allClasses_;
  82. PODVector<BindingType> bindingTypes_;
  83. static Vector<SharedPtr<JSBPackage> > allPackages_;
  84. };
  85. }