20 #ifndef FACTORY_IMPL_H 21 #define FACTORY_IMPL_H 23 #ifndef SHEAF_DLL_SPEC_H 24 #include "SheafSystem/sheaf_dll_spec.h" 28 #include "SheafSystem/factory.h" 31 #ifndef ASSERT_CONTRACT_H 32 #include "SheafSystem/assert_contract.h" 35 #ifndef NAMESPACE_POSET_H 36 #include "SheafSystem/namespace_poset.h" 71 typename prototypes_map_type::iterator itr = _prototypes_map.begin();
72 while(itr != _prototypes_map.end())
77 _prototypes_map.clear();
81 ensure(unexecutable(
"All prototypes have been deleted."));
97 require(contains_prototype(xclient_class_name));
101 result = _prototypes_map.find(xclient_class_name)->second->clone();
106 ensure(unexecutable(
"result is default constructed"));
113 template <
typename T>
114 template <
typename S>
123 require(contains_prototype(xclient_class_name));
127 result = new_instance(xclient_class_name);
128 result->initialize(xarg);
133 ensure(result->is_initialized());
141 template <
typename T>
148 require(xprototype != 0);
158 std::string lclass_name = xprototype->class_name();
160 #ifdef DIAGNOSTIC_OUTPUT 162 cout <<
"in factory<T>::insert_prototype lclass_name = " 167 typename prototypes_map_type::value_type lval(lclass_name, xprototype);
168 _prototypes_map.insert(lval);
172 ensure(contains_prototype(xprototype->class_name()));
179 template <
typename T>
188 if(!xclass_name.empty())
190 typename prototypes_map_type::iterator itr = _prototypes_map.find(xclass_name);
191 if(itr != _prototypes_map.end())
193 T* lproto = itr->second;
194 _prototypes_map.erase(itr);
202 ensure(!contains_prototype(xclass_name));
209 template <
typename T>
221 !xclass_name.empty() &&
222 (_prototypes_map.find(xclass_name) != _prototypes_map.end());
236 template <
typename T>
246 template <
typename T>
247 std::ostream& operator << (std::ostream& xos, const factory<T>& xf)
256 for(litr = xf._prototypes_map.begin(); litr != xf._prototypes_map.end(); ++litr)
258 xos <<
" class: " << litr->first << std::endl;
271 #endif // ifndef FACTORY_IMPL_H bool contains_prototype(const std::string &xclass_name) const
True if the set of prototypes contains a prototype for handles of type xclass_name.
A factory for instanting descendants of an abstract type T, given the class name of the descendant...
T * new_instance(const std::string &xclient_class_name)
Creates an instance of type xclient_class_name.
Namespace for the sheaves component of the sheaf system.
virtual ~factory()
Destructor.
factory()
Default constructor.
void insert_prototype(T *xprototype)
Sets xprototype as the prototype for its client class.
void delete_prototype(const std::string &xclass_name)
Removes the prototype for handles of type xclass_name.