Cantera 2.6.0
ReactionFactory.h
Go to the documentation of this file.
1/**
2 * @file ReactionFactory.h
3 * Factory class for reaction functions. Used by classes
4 * that implement kinetics
5 * (see \ref reactionGroup and class \link Cantera::Reaction Reaction\endlink).
6 */
7
8// This file is part of Cantera. See License.txt in the top-level directory or
9// at https://cantera.org/license.txt for license and copyright information.
10
11#ifndef CT_NEWREACTION_H
12#define CT_NEWREACTION_H
13
16
17namespace Cantera
18{
19
20/**
21 * Factory class to construct reaction function calculators.
22 * The reaction factory is accessed through static method factory:
23 *
24 * @code
25 * Reaction* f = ReactionFactory::factory()->newReaction(type, c)
26 * @endcode
27 *
28 * @ingroup reactionGroup
29 */
30class ReactionFactory : public Factory<Reaction, const AnyMap&, const Kinetics&>
31{
32public:
33 /**
34 * Return a pointer to the factory. On the first call, a new instance is
35 * created. Since there is no need to instantiate more than one factory,
36 * on all subsequent calls, a pointer to the existing factory is returned.
37 */
39 std::unique_lock<std::mutex> lock(reaction_mutex);
40 if (!s_factory) {
42 }
43 return s_factory;
44 }
45
46 virtual void deleteFactory() {
47 std::unique_lock<std::mutex> lock(reaction_mutex);
48 delete s_factory;
49 s_factory = 0;
50 }
51
52private:
53 //! Pointer to the single instance of the factory
55
56 //! default constructor, which is defined as private
58
59 //! Mutex for use when calling the factory
60 static std::mutex reaction_mutex;
61};
62
63class ReactionFactoryXML : public Factory<Reaction, const XML_Node&>
64{
65public:
66 /**
67 * Return a pointer to the factory. On the first call, a new instance is
68 * created. Since there is no need to instantiate more than one factory,
69 * on all subsequent calls, a pointer to the existing factory is returned.
70 */
71 static ReactionFactoryXML* factory() {
72 std::unique_lock<std::mutex> lock(reaction_mutex);
73 if (!s_factory) {
74 s_factory = new ReactionFactoryXML;
75 }
76 return s_factory;
77 }
78
79 virtual void deleteFactory() {
80 std::unique_lock<std::mutex> lock(reaction_mutex);
81 delete s_factory;
82 s_factory = 0;
83 }
84
85private:
86 //! Pointer to the single instance of the factory
87 static ReactionFactoryXML* s_factory;
88
89 //! default constructor, which is defined as private
90 ReactionFactoryXML();
91
92 //! Mutex for use when calling the factory
93 static std::mutex reaction_mutex;
94};
95
96}
97#endif
File contains the FactoryBase class declarations.
Factory class that supports registering functions to create objects.
Definition: FactoryBase.h:70
Factory class to construct reaction function calculators.
ReactionFactory()
default constructor, which is defined as private
static std::mutex reaction_mutex
Mutex for use when calling the factory.
static ReactionFactory * s_factory
Pointer to the single instance of the factory.
static ReactionFactory * factory()
Return a pointer to the factory.
virtual void deleteFactory()
Virtual abstract function that deletes the factory.
Namespace for the Cantera kernel.
Definition: AnyMap.h:29