1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| class Manager;
class Factory
{
typedef std::map<TypeId, BaseType*> map;
typedef typename map::const_iterator const_iterator;
public:
static BaseType* create(TypeId id)
{
/* éventuellement
assert(manager_!=0);
*/
const_iterator it=items_.find(id);
if(it !=items_.end())
{
BaseType* temp= (*it).second->clone();
manager_->registerItem(temp);
return temp;
}
return NULL;
}
/* ne sera utile que si tu envisage d'avoir plusieurs managers
* différents et lors de l'initialisation de ton application
*/
static void changeManager(Manager * man)
{
assert(man!=0);
manager_=man;
}
private:
static map items_;
static Manager * manager_;
}; |