FactoryBase.h

Go to the documentation of this file.
00001 /**
00002  *  @file FactoryBase.h
00003  *  File contains the FactoryBase class declarations.
00004  */
00005 #ifndef CT_FACTORY_BASE
00006 #define CT_FACTORY_BASE
00007 
00008 #include <vector>
00009 
00010 #if defined(THREAD_SAFE_CANTERA)
00011 #include <boost/thread/mutex.hpp>
00012 #endif
00013 
00014 namespace Cantera {
00015 
00016   
00017   //! Base class for factories. 
00018   /*!   This class maintains a registry of
00019    *    all factories that derive from it, and deletes them all when
00020    *    its static method deleteFactories is invoked.
00021    */
00022   class FactoryBase
00023   {
00024   public:
00025 
00026     //! destructor
00027     virtual ~FactoryBase()
00028     {
00029     }
00030     
00031     //! static function that deletes all factories
00032     //! in the internal registry maintained in a static variable
00033     static void deleteFactories()
00034     {
00035       std::vector< FactoryBase* >::iterator iter ;
00036       for ( iter = s_vFactoryRegistry.begin(); 
00037             iter != s_vFactoryRegistry.end(); 
00038             ++iter)
00039         {
00040           (*iter)->deleteFactory() ;
00041         }
00042       s_vFactoryRegistry.clear() ;
00043     }
00044     
00045   protected:
00046 
00047     //! Constructor.
00048     /*!
00049      * Adds the current object to the current static list
00050      */
00051     FactoryBase()
00052     {
00053       s_vFactoryRegistry.push_back(this) ;
00054     }
00055 
00056     //! Virtual abstract function that deletes the factory
00057     /*!
00058      *  This must be properly defined in child objects.
00059      */
00060     virtual void deleteFactory() = 0 ;
00061         
00062   private:
00063 
00064     //! statically held list of Factories.
00065     static std::vector<FactoryBase*> s_vFactoryRegistry ;
00066   };
00067 }
00068 
00069 #endif
00070 
Generated by  doxygen 1.6.3