Cantera  2.1.2
FactoryBase.h
Go to the documentation of this file.
1 /**
2  * @file FactoryBase.h
3  * File contains the FactoryBase class declarations.
4  */
5 #ifndef CT_FACTORY_BASE
6 #define CT_FACTORY_BASE
7 
8 #include <vector>
9 
10 namespace Cantera
11 {
12 
13 //! Base class for factories.
14 /*! This class maintains a registry of
15  * all factories that derive from it, and deletes them all when
16  * its static method deleteFactories is invoked.
17  */
19 {
20 public:
21 
22  //! destructor
23  virtual ~FactoryBase() {
24  }
25 
26  //! static function that deletes all factories
27  //! in the internal registry maintained in a static variable
28  static void deleteFactories() {
29  std::vector< FactoryBase* >::iterator iter ;
30  for (iter = s_vFactoryRegistry.begin();
31  iter != s_vFactoryRegistry.end();
32  ++iter) {
33  (*iter)->deleteFactory() ;
34  }
35  s_vFactoryRegistry.clear() ;
36  }
37 
38 protected:
39 
40  //! Constructor.
41  /*!
42  * Adds the current object to the current static list
43  */
45  s_vFactoryRegistry.push_back(this) ;
46  }
47 
48  //! Virtual abstract function that deletes the factory
49  /*!
50  * This must be properly defined in child objects.
51  */
52  virtual void deleteFactory() = 0 ;
53 
54 private:
55 
56  //! statically held list of Factories.
57  static std::vector<FactoryBase*> s_vFactoryRegistry ;
58 };
59 }
60 
61 #endif
62 
virtual ~FactoryBase()
destructor
Definition: FactoryBase.h:23
FactoryBase()
Constructor.
Definition: FactoryBase.h:44
Base class for factories.
Definition: FactoryBase.h:18
virtual void deleteFactory()=0
Virtual abstract function that deletes the factory.
static void deleteFactories()
static function that deletes all factories in the internal registry maintained in a static variable ...
Definition: FactoryBase.h:28
static std::vector< FactoryBase * > s_vFactoryRegistry
statically held list of Factories.
Definition: FactoryBase.h:57