Esempio n. 1
0
// FindObjectByScopedName
//------------------------------------------------------------------------------
/*static*/ Object * ReflectionInfo::FindObjectByScopedName( const AString & scopedName )
{
	// split into individual names
	Array< AString > names;
	scopedName.Tokenize( names, '.' );
	const size_t size = names.GetSize();
	ASSERT( size );

	const Array< Object * > * children = &s_RootObjects;

	size_t depth = 0;

	for (;;)
	{
		// find object at this scope
		Object * currentObj = nullptr;
		const AString & lookingFor = names[ depth ];
		const size_t numChildren = children->GetSize();
		for ( size_t i=0; i<numChildren; ++i )
		{
			Object * thisChild = ( *children )[ i ];
			if ( thisChild->GetName() == lookingFor )
			{
				currentObj = thisChild;
				break;
			}
		}

		if ( currentObj == nullptr )
		{
			return nullptr; // not found
		}

		// are we at the final object?
		if ( depth == ( size - 1 ) )
		{
			return currentObj; // success
		}

		// is this a container?
		Container * currentContainer = DynamicCast< Container >( currentObj );
		if ( currentContainer == nullptr )
		{
			return nullptr; // no more child objects
		}

		children = &currentContainer->GetChildren();
		depth++;
	}
}