void run() { for( AbstractClassRep* classRep = AbstractClassRep::getClassList(); classRep != NULL; classRep = classRep->getNextClass() ) { // Create object. ConsoleObject* object = classRep->create(); test( object, avar( "AbstractClassRep::create failed for class '%s'", classRep->getClassName() ) ); if( !object ) continue; // Make sure it's a SimObject. SimObject* simObject = dynamic_cast< SimObject* >( object ); if( !simObject ) { SAFE_DELETE( object ); continue; } // Register the object. bool result = simObject->registerObject(); test( result, avar( "registerObject failed for object of class '%s'", classRep->getClassName() ) ); if( result ) simObject->deleteObject(); else SAFE_DELETE( simObject ); } }
SimObject *loadObjectStream(Stream *stream) { const char *className = stream->readSTString(true); ConsoleObject *conObj = ConsoleObject::create(className); if(conObj == NULL) { Con::errorf("Sim::restoreObjectStream - Could not create object of class \"%s\"", className); return NULL; } SimObject *simObj = dynamic_cast<SimObject *>(conObj); if(simObj == NULL) { Con::errorf("Sim::restoreObjectStream - Object of class \"%s\" is not a SimObject", className); delete simObj; return NULL; } if( simObj->readObject(stream) && simObj->registerObject() ) return simObj; delete simObj; return NULL; }
SimObject* TamlBinaryReader::parseElement( Stream& stream, const U32 versionId ) { // Debug Profiling. PROFILE_SCOPE(TamlBinaryReader_ParseElement); SimObject* pSimObject = NULL; #ifdef TORQUE_DEBUG // Format the type location. char typeLocationBuffer[64]; dSprintf( typeLocationBuffer, sizeof(typeLocationBuffer), "Taml [format='binary' offset=%u]", stream.getPosition() ); #endif // Fetch element name. StringTableEntry typeName = stream.readSTString(); // Fetch object name. StringTableEntry objectName = stream.readSTString(); // Read references. U32 tamlRefId; U32 tamlRefToId; stream.read( &tamlRefId ); stream.read( &tamlRefToId ); // Do we have a reference to Id? if ( tamlRefToId != 0 ) { // Yes, so fetch reference. typeObjectReferenceHash::Iterator referenceItr = mObjectReferenceMap.find( tamlRefToId ); // Did we find the reference? if ( referenceItr == mObjectReferenceMap.end() ) { // No, so warn. Con::warnf( "Taml: Could not find a reference Id of '%d'", tamlRefToId ); return NULL; } // Return object. return referenceItr->value; } #ifdef TORQUE_DEBUG // Create type. pSimObject = Taml::createType( typeName, mpTaml, typeLocationBuffer ); #else // Create type. pSimObject = Taml::createType( typeName, mpTaml ); #endif // Finish if we couldn't create the type. if ( pSimObject == NULL ) return NULL; // Find Taml callbacks. TamlCallbacks* pCallbacks = dynamic_cast<TamlCallbacks*>( pSimObject ); // Are there any Taml callbacks? if ( pCallbacks != NULL ) { // Yes, so call it. mpTaml->tamlPreRead( pCallbacks ); } // Parse attributes. parseAttributes( stream, pSimObject, versionId ); // Does the object require a name? if ( objectName == StringTable->EmptyString() ) { // No, so just register anonymously. pSimObject->registerObject(); } else { // Yes, so register a named object. pSimObject->registerObject( objectName ); // Was the name assigned? if ( pSimObject->getName() != objectName ) { // No, so warn that the name was rejected. #ifdef TORQUE_DEBUG Con::warnf( "Taml::parseElement() - Registered an instance of type '%s' but a request to name it '%s' was rejected. This is typically because an object of that name already exists. '%s'", typeName, objectName, typeLocationBuffer ); #else Con::warnf( "Taml::parseElement() - Registered an instance of type '%s' but a request to name it '%s' was rejected. This is typically because an object of that name already exists.", typeName, objectName ); #endif } } // Do we have a reference Id? if ( tamlRefId != 0 ) { // Yes, so insert reference. mObjectReferenceMap.insertUnique( tamlRefId, pSimObject ); } // Parse custom elements. TamlCustomNodes customProperties; // Parse children. parseChildren( stream, pCallbacks, pSimObject, versionId ); // Parse custom elements. parseCustomElements( stream, pCallbacks, customProperties, versionId ); // Are there any Taml callbacks? if ( pCallbacks != NULL ) { // Yes, so call it. mpTaml->tamlPostRead( pCallbacks, customProperties ); } // Return object. return pSimObject; }