00001 #include "Factory.h"
00002 #include "XMLNode.h"
00003 #include "Error.h"
00004 #include "Application.h"
00005
00006 namespace RenderTools {
00007
00008 map< string, FactoryFunc > Factory::s_classes;
00009
00010 PropertyPtr Factory::create( const XMLNodePtr & xml ){
00011 map< string, FactoryFunc >::iterator i;
00012 if( xml ){
00013 i = s_classes.find( xml->getAttrib<string>( "type" ) );
00014 if( i != s_classes.end() ){
00016 if( PropertyPtr p = i->second( xml ) ){
00017 return( p );
00018 }
00019 }
00020 else{
00022 string error = string("trying to create unregistered class \"") + xml->getTagName() + string("\"");
00023 Error::error( Error::NULL_POINTER, __FILE__, __LINE__, error );
00024 }
00025 Error::error( Error::NULL_POINTER, __FILE__, __LINE__ );
00026 return( PropertyPtr() );
00027 }
00028 Error::warning( Error::NULL_POINTER, __FILE__, __LINE__ );
00029 return( PropertyPtr() );
00030 }
00031
00032 void Factory::registerClass( string className, FactoryFunc func ){
00033 s_classes[ className ] = func;
00034 }
00035
00036 bool Factory::isRegisteredClass( string className ){
00037 return( s_classes.find( className ) != s_classes.end() );
00038 }
00039
00040 };