21 #ifndef FACTORY_2_IMPL_H 22 #define FACTORY_2_IMPL_H 24 #ifndef SHEAF_DLL_SPEC_H 25 #include "SheafSystem/sheaf_dll_spec.h" 29 #include "SheafSystem/factory_2.h" 33 #include "SheafSystem/arg_list.h" 36 #ifndef ASSERT_CONTRACT_H 37 #include "SheafSystem/assert_contract.h" 40 #ifndef NAMESPACE_POSET_H 41 #include "SheafSystem/namespace_poset.h" 45 #include "SheafSystem/rc_ptr.h" 57 template <
typename T,
typename R>
70 template <
typename T,
typename R>
80 typename prototypes_map_type::iterator itr = _prototypes_map.begin();
81 while(itr != _prototypes_map.end())
86 _prototypes_map.clear();
90 ensure(unexecutable(
"All prototypes have been deleted."));
120 template <
typename T,
typename R>
127 require(contains_prototype(xclient_class_name));
131 R result = _prototypes_map.find(xclient_class_name)->second->clone(xargs);
136 ensure(unexecutable(
"result is constructed with args, xargs"));
143 template <
typename T,
typename R>
150 require(xprototype != 0);
160 string lclass_name = xprototype->class_name();
162 #ifdef DIAGNOSTIC_OUTPUT 164 cout <<
"in factory_2<T, R>::insert_prototype lclass_name = " 169 typename prototypes_map_type::value_type lval(lclass_name, xprototype);
170 _prototypes_map.insert(lval);
174 ensure(contains_prototype(xprototype->class_name()));
181 template <
typename T,
typename R>
190 if(!xclass_name.empty())
192 typename prototypes_map_type::iterator itr = _prototypes_map.find(xclass_name);
193 if(itr != _prototypes_map.end())
195 T* lproto = itr->second;
196 _prototypes_map.erase(itr);
204 ensure(!contains_prototype(xclass_name));
211 template <
typename T,
typename R>
223 !xclass_name.empty() &&
224 (_prototypes_map.find(xclass_name) != _prototypes_map.end());
238 template <
typename T,
typename R>
246 template <
typename T,
typename R>
247 ostream& operator << (ostream& xos, const factory_2<T, R>& xf)
255 for(litr = xf._prototypes_map.begin(); litr != xf._prototypes_map.end(); ++litr)
257 xos <<
" class: " << litr->first << endl;
269 #endif // ifndef FACTORY_2_IMPL_H R new_instance(const string &xclient_class_name, const arg_list &xargs)
Creates an instance of type xclient_class_name with arguments xargs.
A whitespace separated list of arguments. Insertion operaters are used to insert arguments into the l...
factory_2()
Default constructor.
void insert_prototype(T *xprototype)
Sets xprototype as the prototype for its client class.
A factory for instanting descendants of an abstract type T, given the class name of the descendant...
bool contains_prototype(const string &xclass_name) const
True if the set of prototypes contains a prototype for handles of type xclass_name.
void delete_prototype(const string &xclass_name)
Removes the prototype for handles of type xclass_name.
Namespace for the sheaves component of the sheaf system.
virtual ~factory_2()
Destructor.