dynamicTypes.cpp
Engine/source/console/dynamicTypes.cpp
Public Functions
VectorPtr< ConsoleBaseType * >
gConsoleTypeTable(__FILE__ , __LINE__ )
Detailed Description
Public Functions
gConsoleTypeTable(__FILE__ , __LINE__ )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 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#include "platform/platform.h" 25#include "console/dynamicTypes.h" 26#include "core/stringTable.h" 27#include "core/strings/stringFunctions.h" 28 29 30ConsoleBaseType* ConsoleBaseType::smListHead = NULL; 31S32 ConsoleBaseType::smConsoleTypeCount = 0; 32 33// And, we also privately store the types lookup table. 34static VectorPtr< ConsoleBaseType*> gConsoleTypeTable( __FILE__, __LINE__ ); 35 36 37//----------------------------------------------------------------------------- 38 39ConsoleBaseType::ConsoleBaseType( const S32 size, S32 *idPtr, const char *aTypeName ) 40 : mTypeSize( size ), 41 mInspectorFieldType( NULL ), 42 mTypeInfo( NULL ) 43{ 44 mTypeName = StringTable->insert( aTypeName ); 45 mTypeID = smConsoleTypeCount++; 46 *idPtr = mTypeID; 47 48 // Link ourselves into the list. 49 mListNext = smListHead; 50 smListHead = this; 51} 52 53//----------------------------------------------------------------------------- 54 55ConsoleBaseType *ConsoleBaseType::getListHead() 56{ 57 return smListHead; 58} 59 60//----------------------------------------------------------------------------- 61 62void ConsoleBaseType::initialize() 63{ 64 // Prep and empty the vector. 65 gConsoleTypeTable.setSize(smConsoleTypeCount+1); 66 dMemset(gConsoleTypeTable.address(), 0, sizeof(ConsoleBaseType*) * gConsoleTypeTable.size()); 67 68 // Walk the list and register each one with the console system. 69 ConsoleBaseType *walk = getListHead(); 70 while(walk) 71 { 72 const S32 id = walk->getTypeID(); 73 AssertFatal(gConsoleTypeTable[id]==<a href="/coding/file/types_8lint_8h/#types_8lint_8h_1a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, "ConsoleBaseType::initialize - encountered a table slot that contained something!"); 74 gConsoleTypeTable[id] = walk; 75 76 walk = walk->getListNext(); 77 } 78} 79 80//----------------------------------------------------------------------------- 81 82ConsoleBaseType* ConsoleBaseType::getType(const S32 typeID) 83{ 84 if( typeID == -1 || gConsoleTypeTable.size() <= typeID ) 85 return NULL; 86 87 return gConsoleTypeTable[ typeID ]; 88} 89 90//----------------------------------------------------------------------------- 91 92ConsoleBaseType* ConsoleBaseType::getTypeByName(const char *typeName) 93{ 94 ConsoleBaseType* walk = getListHead(); 95 while( walk != NULL ) 96 { 97 if( String::compare( walk->getTypeName(), typeName ) == 0 ) 98 return walk; 99 100 walk = walk->getListNext(); 101 } 102 103 return NULL; 104} 105 106//----------------------------------------------------------------------------- 107 108ConsoleBaseType * ConsoleBaseType::getTypeByClassName(const char *typeName) 109{ 110 ConsoleBaseType *walk = getListHead(); 111 while( walk != NULL ) 112 { 113 if( String::compare( walk->getTypeClassName(), typeName ) == 0 ) 114 return walk; 115 116 walk = walk->getListNext(); 117 } 118 119 return NULL; 120} 121