template < class T >
T* FindInstance( void )
{
for( int i(0); i < pGObjects->m_count; i++ )
{
UObject* pObject = pGObjects->m_data[ i ];
if( pObject &&
pObject->IsA( T::StaticClass() ) &&
!strstr( pObject->getName(), "Default__" ) )
return (T*)pObject;
}
return NULL;
}
template< class T >
T* UObject::FindObject ( char* objectName )
{
for ( int i = 0; i < pGObjects->m_count; ++i )
{
UObject* object = pGObjects->m_data[ i ];
if ( object
&& !strcmp( object->getFullName(), objectName ) )
return ( T* )object;
}
return NULL;
}
bool UObject::IsA( UClass* objectClass )
{ // loop through this class and all supers to find a match
for ( UClass* C = this->Class; C; C = ( UClass* )C->m_superField )
{
if ( C == objectClass )
return true; //match found
}
return false; //no match
}
char* UObject::getName( void )
{
if ( this->Name.m_index >= 0
&& this->Name.m_index < pGNames->m_count
&& pGNames->m_data[ this->Name.m_index ] )
return pGNames->m_data[ this->Name.m_index ]->m_name;
return "(invalid name)";
}
char* UObject::getNameCPP( void )
{
char objectName[ 256 ];
if( this->IsA( UClass::StaticClass() ) )
{
UClass* classPtr = ( UClass* )this;
while ( classPtr )
{ //if 0 (strings match) pre-fix A for Actor
if ( !strcmp( classPtr->getName(), "Actor" ) )
{
strcpy( objectName, "A" );
break;
}//pre-fix U for UObject
else if ( !strcmp( classPtr->getName(), "Object" ) )
{
strcpy( objectName, "U" );
break;
}
//Loop the supers
classPtr = ( UClass* )classPtr->m_superField;
}
}
else //Not a UClass
strcpy( objectName, "F" );
strcat( objectName, this->getName() ); //Join the name to pre-fix
return objectName; //Return pre-fixed name
}
char* UObject::getFullName( void )
{
static char result[ 256 ];
strcpy( result, "(invalid name)" ); //Start with invalid name
if ( this->Outer //Not dealing with outermost
&& this->Class ) //Make sure this class instance is valid
{
if ( this->Outer->Outer ) //Has 2 outers
sprintf( result, "%s %s.%s.%s", this->Class->getName(), this->Outer->Outer->getName(), this->Outer->getName(), this->getName() );
else //Has 1
sprintf( result, "%s %s.%s", this->Class->getName(), this->Outer->getName(), this->getName() );
}
return result; //Return either invalid or name with packages
}