Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031
00035 template<typename BaseClass, typename IdentifierType>
00036 claw::pattern::factory
00037 <BaseClass, IdentifierType>::class_creator_base::~class_creator_base()
00038 {
00039
00040 }
00041
00042
00043
00044
00045
00049 template<typename BaseClass, typename IdentifierType>
00050 template<typename Derived>
00051 Derived* claw::pattern::factory
00052 <BaseClass, IdentifierType>::class_creator<Derived>::create() const
00053 {
00054 return new Derived;
00055 }
00056
00057
00058
00059
00060
00064 template<typename BaseClass, typename IdentifierType>
00065 claw::pattern::factory<BaseClass, IdentifierType>::~factory()
00066 {
00067 typename class_map::const_iterator it;
00068
00069 for (it=m_classes.begin(); it!=m_classes.end(); ++it)
00070 delete it->second;
00071 }
00072
00073
00082 template<typename BaseClass, typename IdentifierType>
00083 template<typename T>
00084 bool
00085 claw::pattern::factory<BaseClass, IdentifierType>::register_type
00086 ( const identifier_type& id )
00087 {
00088 typename class_map::iterator it = m_classes.find(id);
00089
00090 if ( it == m_classes.end() )
00091 {
00092 m_classes[id] = new class_creator<T>;
00093 return true;
00094 }
00095 else
00096 return false;
00097 }
00098
00099
00105 template<typename BaseClass, typename IdentifierType>
00106 typename claw::pattern::factory<BaseClass, IdentifierType>::base_class*
00107 claw::pattern::factory<BaseClass, IdentifierType>::create
00108 ( const identifier_type& id ) const
00109 {
00110 typename class_map::const_iterator it = m_classes.find(id);
00111
00112 if ( it==m_classes.end() )
00113 throw bad_type_identifier();
00114 else
00115 return it->second->create();
00116 }
00117
00118
00123 template<typename BaseClass, typename IdentifierType>
00124 bool claw::pattern::factory<BaseClass, IdentifierType>::is_known_type
00125 ( const identifier_type& id ) const
00126 {
00127 return m_classes.find(id) != m_classes.end();
00128 }