JSBPackage.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 JSBPackageWriter;
  31. class JSBPackage : public Object
  32. {
  33. friend class JSPackageWriter;
  34. friend class CSPackageWriter;
  35. OBJECT(JSBPackage)
  36. public:
  37. enum BindingType
  38. {
  39. JAVASCRIPT,
  40. CSHARP
  41. };
  42. JSBPackage(Context* context);
  43. virtual ~JSBPackage();
  44. bool Load(const String& packageFolder);
  45. Vector<SharedPtr<JSBModule>>& GetModules() {return modules_;}
  46. void PreprocessModules();
  47. void ProcessModules();
  48. const String& GetName() { return name_; }
  49. const String& GetNamespace() { return namespace_; }
  50. /// Returns whether bindings for a specific type should be generated for this package
  51. bool GenerateBindings(BindingType type) { return bindingTypes_.Contains(type); }
  52. JSBClass* GetClass(const String& name);
  53. PODVector<JSBClass*>& GetAllClasses() { return allClasses_; }
  54. void RegisterClass(JSBClass* cls) {allClasses_.Push(cls); }
  55. // get a class by name across all loaded packages
  56. static JSBClass* GetClassAllPackages(const String& name);
  57. JSBEnum* GetEnum(const String& name);
  58. // get an enum by name across all loaded packages
  59. static JSBEnum* GetEnumAllPackages(const String& name);
  60. bool ContainsConstant(const String& constantName);
  61. static bool ContainsConstantAllPackages(const String& constantName);
  62. void GenerateSource(JSBPackageWriter& packageWriter);
  63. private:
  64. // The name of the package
  65. String name_;
  66. // The name of the C++ namespace if any
  67. String namespace_;
  68. Vector<SharedPtr<JSBPackage> > dependencies_;
  69. HashMap<String, Vector<String>> moduleExcludes_;
  70. Vector<SharedPtr<JSBModule> > modules_;
  71. PODVector<JSBClass*> allClasses_;
  72. PODVector<BindingType> bindingTypes_;
  73. static Vector<SharedPtr<JSBPackage> > allPackages_;
  74. };
  75. }