Cantera  2.0
ReactorFactory.h
Go to the documentation of this file.
1 /**
2  * @file ReactorFactory.h
3  */
4 // Copyright 2001 California Institute of Technology
5 
6 
7 #ifndef REACTOR_FACTORY_H
8 #define REACTOR_FACTORY_H
9 
10 #include "ReactorBase.h"
12 #include "cantera/base/ct_thread.h"
13 
14 namespace Cantera
15 {
16 
17 class ReactorFactory : Cantera::FactoryBase
18 {
19 
20 public:
21 
22  static ReactorFactory* factory() {
23  ScopedLock lock(reactor_mutex);
24  if (!s_factory) {
25  s_factory = new ReactorFactory;
26  }
27  return s_factory;
28  }
29 
30  virtual void deleteFactory() {
31  ScopedLock lock(reactor_mutex);
32  if (s_factory) {
33  delete s_factory;
34  s_factory = 0;
35  }
36  }
37 
38  /**
39  * Destructor doesn't do anything.
40  */
41  virtual ~ReactorFactory() {}
42 
43  /**
44  * Create a new reactor.
45  * @param n the type to be created.
46  */
47  virtual ReactorBase* newReactor(int n);
48  virtual ReactorBase* newReactor(std::string reactorType);
49 
50 private:
51  static ReactorFactory* s_factory;
52  static mutex_t reactor_mutex;
53  ReactorFactory() {}
54 };
55 
56 inline ReactorBase* newReactor(std::string model,
57  ReactorFactory* f=0)
58 {
59  if (f == 0) {
60  f = ReactorFactory::factory();
61  }
62  return f->newReactor(model);
63 }
64 
65 }
66 
67 #endif
68 
69 
70