engineExports.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, 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
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell 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
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _ENGINEEXPORTS_H_
  23. #define _ENGINEEXPORTS_H_
  24. #ifndef _ENGINEOBJECT_H_
  25. #include "console/engineObject.h"
  26. #endif
  27. /// @file
  28. /// Foundation for the engine API export system.
  29. ///
  30. /// The engine DLL exposes a well-defined API that the control layer can
  31. /// use to interface with the engine. The structure of this API is accessible
  32. /// through
  33. ///
  34. /// The system is primarily meant to allow mechanical extraction and processing
  35. /// of the API. It is not meant to be used as a direct means to actually interface
  36. /// with the engine.
  37. ///
  38. /// All export classes are themselves EngineObjects so they can be used in the
  39. /// API. They are, however, all declared as non-instantiable classes.
  40. class EngineExportScope;
  41. DECLARE_SCOPE( ReflectionAPI );
  42. /// Kind of entity being exported.
  43. enum EngineExportKind
  44. {
  45. EngineExportKindScope, ///< A collection of exports grouped in a separate named scope.
  46. EngineExportKindFunction, ///< A function call across the interop border going either in or out.
  47. EngineExportKindType ///< A data type for data exchange between the engine and its control layer. Note that types are also scopes.
  48. };
  49. /// Information about an entity exported by the engine API. This is an abstract base
  50. /// class.
  51. class EngineExport : public StaticEngineObject
  52. {
  53. public:
  54. DECLARE_ABSTRACT_CLASS( EngineExport, StaticEngineObject );
  55. DECLARE_INSCOPE( ReflectionAPI );
  56. friend class EngineExportScope; // Default constructor.
  57. protected:
  58. /// Name of the export. Never NULL but will be an empty string for anonymous
  59. /// exports such as function types.
  60. const char* mExportName;
  61. /// Kind of export.
  62. EngineExportKind mExportKind;
  63. /// The scope in which this export is defined.
  64. EngineExportScope* mExportScope;
  65. /// Documentation string.
  66. const char* mDocString;
  67. /// Next export in the link chain of the export's scope.
  68. EngineExport* mNextExport;
  69. /// Protected constructor as this is an abstract class.
  70. ///
  71. /// @param name Export name.
  72. /// @param kind Export kind.
  73. /// @param scope Scope to export to.
  74. /// @param docString Documentation string.
  75. EngineExport( const char* name, EngineExportKind kind, EngineExportScope* scope, const char* docString );
  76. public:
  77. /// Return the name of the export.
  78. const char* getExportName() const { return mExportName; }
  79. /// Return the fully qualified name of this export starting from the global export scope.
  80. /// Qualifiers are separated with "::".
  81. String getFullyQualifiedExportName() const;
  82. /// Return the kind of entity being exported.
  83. EngineExportKind getExportKind() const { return mExportKind; }
  84. /// Return the scope that contains this export. All exports except the global scope
  85. /// itself are contained in a scope.
  86. EngineExportScope* getExportScope() const { return mExportScope; }
  87. /// Get the next export in the link chain of the export's associated scope.
  88. EngineExport* getNextExport() const { return mNextExport; }
  89. /// Return the documentation string for this type.
  90. const char* getDocString() const { return mDocString; }
  91. private:
  92. /// Special constructor for the global scope instance.
  93. EngineExport()
  94. : mExportName( "" ),
  95. mExportKind( EngineExportKindScope ),
  96. mExportScope( NULL ),
  97. mDocString(""),
  98. mNextExport( NULL ) {}
  99. };
  100. /// A group of engine exports.
  101. class EngineExportScope : public EngineExport
  102. {
  103. public:
  104. DECLARE_CLASS( EngineExportScope, EngineExport );
  105. friend class EngineExport; // mExports
  106. friend struct _GLOBALSCOPE; // smGlobalScope
  107. template< typename T > friend T* constructInPlace( T* );
  108. protected:
  109. /// Head of the link chain of exports for this scope.
  110. EngineExport* mExports;
  111. /// The global export scope singleton.
  112. static EngineExportScope smGlobalScope;
  113. public:
  114. /// Construct a new export scope.
  115. ///
  116. /// @param name Name of the scope inside its parent scope.
  117. /// @param scope Parent scope.
  118. /// @param docString Documentation string.
  119. EngineExportScope( const char* name, EngineExportScope* scope, const char* docString );
  120. /// Return the global export scope singleton. This is the root of the
  121. /// export hierarchy and thus directly or indirectly contains all
  122. /// entities exported by the engine.
  123. static EngineExportScope* getGlobalScope() { return &smGlobalScope; }
  124. /// Return the chain of exports associated with this scope.
  125. EngineExport* getExports() const { return mExports; }
  126. private:
  127. /// Constructor for the global scope.
  128. EngineExportScope(){}
  129. };
  130. /// @}
  131. #endif // !_ENGINEEXPORTS_H_