added FactoryBase.h
This commit is contained in:
parent
52af3dd76d
commit
9a13b924d8
1 changed files with 50 additions and 0 deletions
50
Cantera/src/base/FactoryBase.h
Normal file
50
Cantera/src/base/FactoryBase.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef CT_FACTORY_BASE
|
||||
#define CT_FACTORY_BASE
|
||||
|
||||
#include <vector>
|
||||
|
||||
#if defined(THREAD_SAFE_CANTERA)
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#endif
|
||||
|
||||
namespace Cantera {
|
||||
|
||||
/**
|
||||
* Base class for factories. This class maintains a registry of
|
||||
* all factories that derive from it, and deletes them all when
|
||||
* its static method deleteFactories is invoked.
|
||||
*/
|
||||
class FactoryBase
|
||||
{
|
||||
public:
|
||||
virtual ~FactoryBase()
|
||||
{
|
||||
}
|
||||
|
||||
static void deleteFactories()
|
||||
{
|
||||
std::vector< FactoryBase* >::iterator iter ;
|
||||
for ( iter = s_vFactoryRegistry.begin();
|
||||
iter != s_vFactoryRegistry.end();
|
||||
++iter)
|
||||
{
|
||||
(*iter)->deleteFactory() ;
|
||||
}
|
||||
s_vFactoryRegistry.clear() ;
|
||||
}
|
||||
|
||||
protected:
|
||||
FactoryBase()
|
||||
{
|
||||
s_vFactoryRegistry.push_back(this) ;
|
||||
}
|
||||
|
||||
virtual void deleteFactory() = 0 ;
|
||||
|
||||
private:
|
||||
static std::vector<FactoryBase*> s_vFactoryRegistry ;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Add table
Reference in a new issue