28 #ifndef yaSSL_FACTORY_HPP 
   29 #define yaSSL_FACTORY_HPP 
   31 #include STL_VECTOR_FILE 
   32 #include STL_PAIR_FILE 
   35 namespace STL = STL_NAMESPACE;
 
   46 template<
class    AbstractProduct, 
 
   47          typename IdentifierType = int, 
 
   48          typename ProductCreator = AbstractProduct* (*)()
 
   51     typedef STL::pair<IdentifierType, ProductCreator> CallBack;
 
   52     typedef STL::vector<CallBack> CallBackVector;
 
   54     CallBackVector callbacks_;
 
   57     explicit Factory(
void (*init)(
Factory<AbstractProduct, IdentifierType,
 
   64     void Reserve(
size_t sz)
 
   66         callbacks_.reserve(sz);
 
   70     void Register(
const IdentifierType& 
id, ProductCreator pc)
 
   72         callbacks_.push_back(STL::make_pair(
id, pc));
 
   76     AbstractProduct* CreateObject(
const IdentifierType& 
id)
 const 
   78         typedef typename STL::vector<CallBack>::const_iterator cIter;
 
   80         cIter first = callbacks_.begin();
 
   81         cIter last  = callbacks_.end();
 
   83         while (first != last) {
 
   84             if (first->first == 
id)
 
   89         if (first == callbacks_.end())
 
   91         return (first->second)();
 
  101 #endif // yaSSL_FACTORY_HPP