| 939 | //----------------------------------------------------------------------------- |
| 940 | |
| 941 | SimObject* 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. |
nothing calls this directly
no test coverage detected