/* * --- GSMP-COPYRIGHT-NOTE-BEGIN --- * * This copyright note is auto-generated by ./scripts/Create-CopyPatch. * Please add additional copyright information _after_ the line containing * the GSMP-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by * the ./scripts/Create-CopyPatch script. Do not edit this copyright text! * * GSMP: dam/include/Factory.hh_in * General Sound Manipulation Program is Copyright (C) 2000 - 2004 * Valentin Ziegler and René Rebe * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2. A copy of the GNU General * Public License can be found in the file LICENSE. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT- * ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * * --- GSMP-COPYRIGHT-NOTE-END --- */ #ifndef DAM__FACTORY_HH__ #define DAM__FACTORY_HH__ #include #include namespace DAM { /*Expand*/ __TypeList class BasicFactory__NO { public: typedef BASE Base; typedef INFO Info; Base* operator () (__ArgList) { return Create (__ArgRep); } virtual Base* Create (__ArgList) = 0; virtual const Info* Information () const { return m_info; } protected: BasicFactory__NO (Info* i_info) { m_info = i_info; } BasicFactory__NO () { m_info = 0; } virtual ~BasicFactory__NO () {} Info* m_info; }; /*!Expand*/ /*Expand*/ __TypeList class StdFactory__NO : public BasicFactory__NO __TypeRep { public: typedef BasicFactory__NO __TypeRep BasicFactory; typedef typename BasicFactory::Base Base; typedef typename BasicFactory::Info Info; typedef IMPL Impl; StdFactory__NO (Info* i_info) : BasicFactory__NO __TypeRep (i_info) {} virtual ~StdFactory__NO () { if (this->m_info) delete this->m_info; } // this-> needed for gcc-3.4 virtual Base* Create ( __ArgList ) { return new Impl ( __ArgRep ); } }; /*!Expand*/ struct nil; /*Expand*/ // Convenience __TypeList class StdFactory __SpTypeRep : public StdFactory__NO __TypeRep { public: typedef INFO Info; StdFactory (Info* i_info) : StdFactory__NO __TypeRep (i_info) {} }; /*!Expand*/ // TODO: Id Browser class BasicFactoryHolder { public: typedef std::string Id__; typedef const Id__& Id; }; template class FactoryHolder : public BasicFactoryHolder { public: typedef FACTORY Factory; // prototype container typedef std::map FactoryMap; typedef typename FactoryMap::iterator Iterator; Factory* operator () (Id id); Iterator Begin () { return factories.begin (); } Iterator End () { return factories.end (); } Iterator Find (Id id) { return factories.find (id); } bool Register (Id id, Factory* factory); bool UnRegister (Id id); private: FactoryMap factories; }; } // end namespace DAM /* include template implementation */ #define DAM__FACTORY_TMPL__ #include "template/Factory.tcc" #undef DAM__FACTORY_TMPL__ #endif // DAM__FACTORY_HH__