Package.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 _PACKAGE_H
  23. #define _PACKAGE_H
  24. #ifdef PUAP_NAMESPACE_CHANGE
  25. #ifndef _STRINGTABLE_H_
  26. #include "string/stringTable.h"
  27. #endif
  28. #ifndef _TVECTOR_H_
  29. #include "core/tVector.h"
  30. #endif
  31. #ifndef _CONSOLETYPES_H_
  32. #include "console/consoleTypes.h"
  33. #endif
  34. #include "tHashTable.h"
  35. #include "Namespace.h"
  36. class ExprEvalState;
  37. struct FunctionDecl;
  38. class CodeBlock;
  39. class AbstractClassRep;
  40. class Package
  41. {
  42. enum {
  43. MaxActivePackages = 512,
  44. };
  45. public:
  46. StringTableEntry mName;
  47. Package *mParent;
  48. AbstractClassRep *mClassRep;
  49. U32 mRefCountToParent;
  50. const char* mUsage;
  51. // Script defined usage strings need to be cleaned up. This
  52. // field indicates whether or not the usage was set from script.
  53. bool mCleanUpUsage;
  54. int mActivePosition;
  55. Package();
  56. ~Package();
  57. typedef tHashTable<StringTableEntry, Namespace*>::Iterator nameSpaceIterator;
  58. typedef tHashTable<StringTableEntry, Package*>::Iterator packageIterator;
  59. tHashTable<StringTableEntry, Namespace*> *mChildNamespaceList;
  60. tHashTable<StringTableEntry, Package*> *mChildPackageList;
  61. Namespace *mDefaultNamespace;
  62. //-Mat, maybe put these into ExprEvalState
  63. static Package *smRootPackage;
  64. static Package *smMainPackage;
  65. static void init();
  66. static void shutdown();
  67. static Package *getRootPackage() { return smRootPackage; }
  68. static Package *getMainNamespacePackage() { return smMainPackage; }
  69. //this namespace be be the child of smMainPackage
  70. static Namespace *getMainNamespace() { return smMainPackage->getDefaultNamespace(); }
  71. //this will find the most recently activated package
  72. static Package *getCurrentPackage();
  73. static Package *findPackage(StringTableEntry);
  74. static Package *findAndCreatePackage(StringTableEntry name);
  75. static void activatePackage(StringTableEntry name);
  76. static void deactivatePackage(StringTableEntry name);
  77. static void dumpNamespaces( bool dumpScript = true, bool dumpEngine = true );
  78. static void unlinkPackages();
  79. static void relinkPackages();
  80. //Namespace::Entry *lookupEntryInActivePackages( StringTableEntry, StringTableEntry );
  81. static Namespace *lookupNamespaceInActivePackages( StringTableEntry);
  82. Namespace *getDefaultNamespace() { return mDefaultNamespace; }
  83. //-Mat functions to help with new Namespace organization
  84. Namespace *findNamespace(StringTableEntry name);
  85. Namespace *findAndCreateNamespace(StringTableEntry name);
  86. Namespace *addAndCreateNamespace( StringTableEntry );
  87. Namespace *addNamespace( Namespace* );
  88. Namespace *swapNamespace( Namespace* );
  89. Package *addPackage(Package*);
  90. void activate(int activePosition) { mActivePosition = activePosition; }
  91. void deActivate() { mActivePosition = -1; }
  92. bool isActive() { return mActivePosition != -1; }
  93. private:
  94. //private so that we can make sure no Namespace has a NULL parent because of this
  95. //use SwapNamespace to "remove" a namespace (it will get moved to the MainPackage)
  96. Namespace *removeNamespace( Namespace* );
  97. };
  98. #else
  99. //normal TGB
  100. #endif //PUAP_NAMESPACE_CHANGE
  101. #endif// _PACKAGE_H