Cantera  2.0
KineticsFactory.h
Go to the documentation of this file.
1 /**
2  * @file KineticsFactory.h
3  */
4 // Copyright 2001 California Institute of Technology
5 
6 
7 #ifndef KINETICS_FACTORY_H
8 #define KINETICS_FACTORY_H
9 
10 #include "Kinetics.h"
11 #include "cantera/base/xml.h"
13 #include "cantera/base/ct_thread.h"
14 
15 namespace Cantera
16 {
17 
18 
19 class UnknownKineticsModel : public CanteraError
20 {
21 public:
22  UnknownKineticsModel(std::string proc, std::string kineticsModel) :
23  CanteraError(proc, "Specified Kinetics model "
24  + kineticsModel +
25  " does not match any known type.") {}
26  virtual ~UnknownKineticsModel() throw() {}
27 };
28 
29 
30 /**
31  * Factory for kinetics managers.
32  */
34 {
35 
36 public:
37 
38  static KineticsFactory* factory() {
39  ScopedLock lock(kinetics_mutex);
40  if (!s_factory) {
41  s_factory = new KineticsFactory;
42  }
43  return s_factory;
44  }
45 
46  virtual ~KineticsFactory() {
47  //delete s_factory;
48  //s_factory = 0;
49  }
50 
51  virtual void deleteFactory() {
52  ScopedLock lock(kinetics_mutex);
53  if (s_factory) {
54  delete s_factory ;
55  s_factory = 0 ;
56  }
57  }
58 
59  /**
60  * Create a new kinetics manager.
61  */
62  virtual Kinetics* newKinetics(XML_Node& phase,
63  std::vector<ThermoPhase*> th);
64 
65  virtual Kinetics* newKinetics(std::string model);
66 
67 private:
68 
69  static KineticsFactory* s_factory;
70  KineticsFactory() {}
71  static mutex_t kinetics_mutex;
72 };
73 
74 
75 /**
76  * Create a new kinetics manager.
77  */
79  std::vector<ThermoPhase*> th, KineticsFactory* f=0)
80 {
81  if (f == 0) {
82  f = KineticsFactory::factory();
83  }
84  Kinetics* kin = f->newKinetics(phase, th);
85  return kin;
86 }
87 
88 /**
89  * Create a new kinetics manager.
90  */
91 inline Kinetics* newKineticsMgr(std::string model, KineticsFactory* f=0)
92 {
93  if (f == 0) {
94  f = KineticsFactory::factory();
95  }
96  Kinetics* kin = f->newKinetics(model);
97  return kin;
98 }
99 }
100 
101 #endif
102 
103 
104