moduleDefinition.h
Engine/source/module/moduleDefinition.h
Classes:
class
class
Module dependency.
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2013 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _MODULE_DEFINITION_H 25#define _MODULE_DEFINITION_H 26 27#ifndef _ASSET_DEFINITION_H_ 28#include "assets/assetDefinition.h" 29#endif 30 31#ifndef _SIMSET_H_ 32#include "console/simSet.h" 33#endif 34 35#ifndef _SIMBASE_H_ 36#include "console/simBase.h" 37#endif 38 39#ifndef _TVECTOR_H_ 40#include "core/util/tVector.h" 41#endif 42 43#ifndef _STRINGUNIT_H_ 44#include "core/strings/stringUnit.h" 45#endif 46 47//----------------------------------------------------------------------------- 48 49class ModuleManager; 50 51//----------------------------------------------------------------------------- 52 53/// @ingroup moduleGroup 54/// @see moduleGroup 55class ModuleDefinition : public SimSet 56{ 57 friend class ModuleManager; 58 59private: 60 typedef SimSet Parent; 61 62public: 63 /// Module dependency. 64 struct ModuleDependency 65 { 66 ModuleDependency() : 67 mModuleId( StringTable->EmptyString() ), 68 mVersionId( 0 ) 69 { 70 } 71 72 ModuleDependency( StringTableEntry moduleId, const U32 versionId ) : 73 mModuleId( moduleId ), 74 mVersionId( versionId ) 75 { 76 } 77 78 StringTableEntry mModuleId; 79 U32 mVersionId; 80 }; 81 typedef Vector<ModuleDependency> typeModuleDependencyVector; 82 typedef Vector<AssetDefinition*> typeModuleAssetsVector; 83 84private: 85 /// Module definition. 86 StringTableEntry mModuleId; 87 U32 mVersionId; 88 U32 mBuildId; 89 bool mEnabled; 90 bool mSynchronized; 91 bool mDeprecated; 92 bool mCriticalMerge; 93 StringTableEntry mModuleDescription; 94 StringTableEntry mAuthor;; 95 StringTableEntry mModuleGroup; 96 StringTableEntry mModuleType; 97 typeModuleDependencyVector mDependencies; 98 StringTableEntry mScriptFile; 99 StringTableEntry mCreateFunction; 100 StringTableEntry mDestroyFunction; 101 102 /// Modules assets. 103 StringTableEntry mAssetTagsManifest; 104 typeModuleAssetsVector mModuleAssets; 105 106 /// Module location. 107 StringTableEntry mModulePath; 108 StringTableEntry mModuleFile; 109 StringTableEntry mModuleFilePath; 110 StringTableEntry mModuleScriptFilePath; 111 112 /// Miscellaneous. 113 StringTableEntry mSignature; 114 S32 mLoadCount; 115 SimObjectId mScopeSet; 116 bool mLocked; 117 ModuleManager* mpModuleManager; 118 119private: 120 inline bool checkUnlocked( void ) const { if ( mLocked ) { Con::warnf("Ignoring changes for locked module definition."); } return !mLocked; } 121 inline void setModuleManager( ModuleManager* pModuleManager ) { mpModuleManager = pModuleManager; } 122 123public: 124 ModuleDefinition(); 125 virtual ~ModuleDefinition() {} 126 127 /// Engine. 128 static void initPersistFields(); 129 130 /// Module definition. 131 inline void setModuleId( const char* pModuleId ) { if ( checkUnlocked() ) { mModuleId = StringTable->insert(pModuleId); } } 132 inline StringTableEntry getModuleId( void ) const { return mModuleId; } 133 inline void setVersionId( const U32 versionId ) { if ( checkUnlocked() ) { mVersionId = versionId; } } 134 inline U32 getVersionId( void ) const { return mVersionId; } 135 inline void setBuildId( const U32 buildId ) { if ( checkUnlocked() ) { mBuildId = buildId; } } 136 inline U32 getBuildId( void ) const { return mBuildId; } 137 inline void setEnabled( const bool enabled ) { if ( checkUnlocked() ) { mEnabled = enabled; } } 138 inline bool getEnabled( void ) const { return mEnabled; } 139 inline void setSynchronized( const bool synchronized ) { if ( checkUnlocked() ) { mSynchronized = synchronized; } } 140 inline bool getSynchronized( void ) const { return mSynchronized; } 141 inline void setDeprecated( const bool deprecated ) { if ( checkUnlocked() ) { mDeprecated = deprecated; } } 142 inline bool getDeprecated( void ) const { return mDeprecated; } 143 inline void setCriticalMerge( const bool mergeCritical ) { if ( checkUnlocked() ) { mCriticalMerge = mergeCritical; } } 144 inline bool getCriticalMerge( void ) const { return mCriticalMerge; } 145 inline void setModuleDescription( const char* pModuleDescription ) { if ( checkUnlocked() ) { mModuleDescription = StringTable->insert(pModuleDescription); } } 146 inline StringTableEntry getModuleDescription( void ) const { return mModuleDescription; } 147 inline void setAuthor( const char* pAuthor ) { if ( checkUnlocked() ) { mAuthor = StringTable->insert(pAuthor); } } 148 inline StringTableEntry getAuthor( void ) const { return mAuthor; } 149 inline void setModuleGroup( const char* pModuleGroup ) { if ( checkUnlocked() ) { mModuleGroup = StringTable->insert(pModuleGroup); } } 150 inline StringTableEntry getModuleGroup( void ) const { return mModuleGroup; } 151 inline void setModuleType( const char* pModuleType ) { if ( checkUnlocked() ) { mModuleType = StringTable->insert(pModuleType); } } 152 inline StringTableEntry getModuleType( void ) const { return mModuleType; } 153 inline void setDependencies( const typeModuleDependencyVector& dependencies ) { if ( checkUnlocked() ) { mDependencies.clear(); mDependencies.merge(dependencies); } } 154 inline const typeModuleDependencyVector& getDependencies( void ) const { return mDependencies; } 155 inline void setScriptFile( const char* pScriptFile ) { if ( checkUnlocked() ) { mScriptFile = StringTable->insert(pScriptFile); } } 156 inline StringTableEntry getScriptFile( void ) const { return mScriptFile; } 157 inline void setCreateFunction( const char* pCreateFunction ) { if ( checkUnlocked() ) { mCreateFunction = StringTable->insert(pCreateFunction); } } 158 inline StringTableEntry getCreateFunction( void ) const { return mCreateFunction; } 159 inline void setDestroyFunction( const char* pDestroyFunction ) { if ( checkUnlocked() ) { mDestroyFunction = StringTable->insert(pDestroyFunction); } } 160 inline StringTableEntry getDestroyFunction( void ) const { return mDestroyFunction; } 161 inline SimObjectId getScopeSet( void ) const { return mScopeSet; } 162 163 /// Module assets. 164 inline void setAssetTagsManifest( const char* pTagsAssetManifest ) { if ( checkUnlocked() ) { mAssetTagsManifest = StringTable->insert(pTagsAssetManifest); } } 165 inline StringTableEntry getAssetTagsManifest( void ) const { return mAssetTagsManifest; } 166 inline typeModuleAssetsVector& getModuleAssets( void ) { return mModuleAssets; } 167 168 /// Module location. 169 inline void setModulePath( const char* pModulePath ) { if ( checkUnlocked() ) { mModulePath = StringTable->insert(pModulePath); } } 170 inline StringTableEntry getModulePath( void ) const { return mModulePath; } 171 inline void setModuleFile( const char* pModuleDefinitionFile ) { if ( checkUnlocked() ) { mModuleFile = StringTable->insert(pModuleDefinitionFile); } } 172 inline StringTableEntry getModuleFile( void ) const { return mModuleFile; } 173 inline void setModuleFilePath( const char* pModuleDefinitionFilePath ) { if ( checkUnlocked() ) { mModuleFilePath = StringTable->insert(pModuleDefinitionFilePath); } } 174 inline StringTableEntry getModuleFilePath( void ) const { return mModuleFilePath; } 175 inline void setModuleScriptFilePath( const char* pModuleScriptFilePath ) { if ( checkUnlocked() ) { mModuleScriptFilePath = StringTable->insert(pModuleScriptFilePath); } } 176 inline StringTableEntry getModuleScriptFilePath( void ) const { return mModuleScriptFilePath; } 177 178 /// Specialized dependency control. 179 inline U32 getDependencyCount( void ) const { return mDependencies.size(); } 180 bool getDependency( const U32 dependencyIndex, ModuleDependency& dependency ) const; 181 bool addDependency( const char* pModuleId, const U32 versionId ); 182 bool removeDependency( const char* pModuleId ); 183 184 /// Miscellaneous. 185 inline void setSignature( const char* pSignature ) { if ( checkUnlocked() ) { mSignature = StringTable->insert(pSignature); } } 186 inline StringTableEntry getSignature( void ) const { return mSignature; } 187 inline void increaseLoadCount( void ) { ++mLoadCount; } 188 inline void reduceLoadCount( void ) { --mLoadCount; } 189 inline S32 getLoadCount( void ) const { return mLoadCount; } 190 inline void setLocked( const bool status ) { mLocked = status; } 191 inline bool getLocked( void ) const { return mLocked; } 192 inline ModuleManager* getModuleManager( void ) const { return mpModuleManager; } 193 bool save( void ); 194 195 /// Declare Console Object. 196 DECLARE_CONOBJECT( ModuleDefinition ); 197 198protected: 199 static bool setModuleId(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setModuleId( data ); return false; } 200 static bool setVersionId(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setVersionId((U32)dAtoi(data)); return false; } 201 static bool setBuildId(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setBuildId((U32)dAtoi(data)); return false; } 202 static bool writeBuildId( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getBuildId() != 0; } 203 static bool setEnabled(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setEnabled(dAtob(data)); return false; } 204 static bool writeEnabled( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getEnabled() == false; } 205 static bool setSynchronized(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setSynchronized(dAtob(data)); return false; } 206 static bool writeSynchronized( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getSynchronized() == true; } 207 static bool setDeprecated(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setDeprecated(dAtob(data)); return false; } 208 static bool writeDeprecated( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getDeprecated() == true; } 209 static bool writeCriticalMerge( void* obj, StringTableEntry pFieldName ){ return static_cast<ModuleDefinition*>(obj)->getCriticalMerge() == true; } 210 static bool setModuleDescription(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setModuleDescription(data); return false; } 211 static bool writeModuleDescription( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getModuleDescription() != StringTable->EmptyString(); } 212 static bool setAuthor(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setAuthor(data); return false; } 213 static bool writeAuthor(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getAuthor() != StringTable->EmptyString(); } 214 static bool setModuleGroup(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setModuleGroup(data); return false; } 215 static bool setModuleType(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setModuleType(data); return false; } 216 static bool writeModuleType(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getModuleType() != StringTable->EmptyString(); } 217 static bool setScriptFile(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setScriptFile(data); return false; } 218 static bool writeScriptFile(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getScriptFile() != StringTable->EmptyString(); } 219 static bool setCreateFunction(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setCreateFunction(data); return false; } 220 static bool writeCreateFunction(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getCreateFunction() != StringTable->EmptyString(); } 221 static bool setDestroyFunction(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setDestroyFunction(data); return false; } 222 static bool writeDestroyFunction(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getDestroyFunction() != StringTable->EmptyString(); } 223 224 /// Asset manifest. 225 static bool setAssetTagsManifest(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setAssetTagsManifest(data); return false; } 226 static bool writeAssetTagsManifest(void* obj, StringTableEntry pFieldName) { return static_cast<ModuleDefinition*>(obj)->getAssetTagsManifest() != StringTable->EmptyString(); } 227 static const char* getScopeSet(void* obj, const char* data) { return Con::getIntArg(static_cast<ModuleDefinition*>(obj)->getScopeSet()); } 228 229 static bool setDependencies(void* obj, const char* index, const char* data) 230 { 231 // Fetch module dependencies. 232 ModuleDefinition::typeModuleDependencyVector moduleDependencies; 233 234 // Fetch dependency value. 235 const char* pDependencyValue = data; 236 237 char slotUnit[256]; 238 char slotName[256]; 239 char slotValue[256]; 240 241 // Fetch definition word count. 242 const U32 dependencyWordCount = StringUnit::getUnitCount( pDependencyValue, "," ); 243 244 // Do we have any dependencies specified? 245 if ( dependencyWordCount > 0 ) 246 { 247 // Yes, so iterate dependencies. 248 for ( U32 dependencyIndex = 0; dependencyIndex < dependencyWordCount; ++dependencyIndex ) 249 { 250 // Fetch slot. 251 dStrcpy( slotUnit, StringUnit::getUnit( pDependencyValue, dependencyIndex, "," ) ); 252 253 // Fetch slot name and value. 254 dStrcpy( slotName, StringUnit::getUnit( slotUnit, 0, "=" ) ); 255 dStrcpy( slotValue, StringUnit::getUnit( slotUnit, 1, "=" ) ); 256 257 // Fetch module Id. 258 StringTableEntry moduleId = StringTable->insert( slotName ); 259 260 // Fetch version Id. 261 const U32 versionId = slotValue[0] == '*' ? 0 : dAtoi(slotValue); 262 263 // Populate module dependency. 264 ModuleDefinition::ModuleDependency dependency( moduleId, versionId ); 265 266 // Store dependency. 267 moduleDependencies.push_back( dependency ); 268 } 269 } 270 271 // Set dependencies. 272 static_cast<ModuleDefinition*>(obj)->setDependencies( moduleDependencies ); 273 274 return false; 275 } 276 static const char* getDependencies(void* obj, const char* data) 277 { 278 // Fetch module dependencies. 279 const ModuleDefinition::typeModuleDependencyVector& moduleDependencies = static_cast<ModuleDefinition*>(obj)->getDependencies(); 280 281 // Finish if no dependencies. 282 if ( moduleDependencies.size() == 0 ) 283 return StringTable->EmptyString(); 284 285 // Get a return buffer. 286 const S32 bufferSize = 1024; 287 char* pReturnBuffer = Con::getReturnBuffer(bufferSize); 288 pReturnBuffer[0] = '\0'; 289 290 // Set buffer limits. 291 char* pValueBuffer = pReturnBuffer; 292 S32 bufferLeft = bufferSize; 293 U32 used; 294 295 // Iterate module dependencies. 296 for ( ModuleDefinition::typeModuleDependencyVector::const_iterator dependencyItr = moduleDependencies.begin(); dependencyItr < moduleDependencies.end(); ++dependencyItr ) 297 { 298 // Fetch module dependency. 299 const ModuleDefinition::ModuleDependency* pDependency = dependencyItr; 300 301 // Fetch version Id. 302 const char* pVersionId = pDependency->mVersionId == 0 ? "*" : avar("%d", pDependency->mVersionId ); 303 304 if ( dependencyItr == moduleDependencies.begin() ) 305 { 306 // Write out a field/value pair 307 used = dSprintf( pValueBuffer, bufferLeft, "%s=%s", pDependency->mModuleId, pVersionId ); 308 pValueBuffer += used; 309 bufferLeft -= used; 310 } 311 else 312 { 313 // Write out a field/value pair 314 used = dSprintf( pValueBuffer, bufferLeft, ",%s=%s", pDependency->mModuleId, pVersionId ); 315 pValueBuffer += used; 316 bufferLeft -= used; 317 } 318 319 // Sanity. 320 AssertFatal( bufferLeft > 0, "Cannot format module dependencies as we ran out of buffer." ); 321 } 322 323 return pReturnBuffer; 324 } 325 static bool writeDependencies( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getDependencies().size() > 0; } 326 static const char* getSignature(void* obj, const char* data) { return static_cast<ModuleDefinition*>(obj)->getSignature(); } 327}; 328 329#endif // _MODULE_DEFINITION_H 330 331
