MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / createType

Method createType

Engine/source/persistence/taml/taml.cpp:941–1024  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

939//-----------------------------------------------------------------------------
940
941SimObject* Taml::createType( StringTableEntry typeName, const Taml* pTaml, const char* pProgenitorSuffix )
942{
943 // Debug Profiling.
944 PROFILE_SCOPE(Taml_CreateType);
945
946 typedef HashTable<StringTableEntry, AbstractClassRep*> typeClassHash;
947 static typeClassHash mClassMap;
948
949 // Sanity!
950 AssertFatal( typeName != NULL, "Taml: Type cannot be NULL" );
951
952 // Find type.
953 typeClassHash::Iterator typeItr = mClassMap.find( typeName );
954
955 // Found type?
956 if ( typeItr == mClassMap.end() )
957 {
958 // No, so find type.
959 AbstractClassRep* pClassRep = AbstractClassRep::getClassList();
960 while( pClassRep )
961 {
962 // Is this the type?
963 if( dStricmp( pClassRep->getClassName(), typeName ) == 0 )
964 {
965 // Yes, so insert it.
966 typeItr = mClassMap.insertUnique( typeName, pClassRep );
967 break;
968 }
969
970 // Next type.
971 pClassRep = pClassRep->getNextClass();
972 }
973
974 // Did we find the type?
975 if ( typeItr == mClassMap.end() )
976 {
977 // No, so warn and fail.
978 Con::warnf( "Taml: Failed to create type '%s' as such a registered type could not be found.", typeName );
979 return NULL;
980 }
981 }
982
983 // Create the object.
984 ConsoleObject* pConsoleObject = typeItr->value->create();
985
986 // NOTE: It is important that we don't register the object here as many objects rely on the fact that
987 // fields are set prior to the object being registered. Registering here will invalid those assumptions.
988
989 // Fetch the SimObject.
990 SimObject* pSimObject = dynamic_cast<SimObject*>( pConsoleObject );
991
992 // Was it a SimObject?
993 if ( pSimObject == NULL )
994 {
995 // No, so warn.
996 Con::warnf( "Taml: Failed to create type '%s' as it is not a SimObject.", typeName );
997
998 // Destroy object and fail.

Callers

nothing calls this directly

Calls 12

dStricmpFunction · 0.85
warnfFunction · 0.85
dSprintfFunction · 0.85
insertUniqueMethod · 0.80
getNextClassMethod · 0.80
getProgenitorUpdateMethod · 0.80
setProgenitorFileMethod · 0.80
getFilePathBufferMethod · 0.80
findMethod · 0.45
endMethod · 0.45
getClassNameMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected