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
14#include "cantera/base/FactoryBase.h"
15#include "cantera/kinetics/Reaction.h"
16
17 namespace 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 */
30 class ReactionFactory : public Factory<Reaction, const AnyMap&, const Kinetics&>
31{
32 public:
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 */
38 static ReactionFactory* factory() {
39 std::unique_lock<std::mutex> lock(reaction_mutex);
40 if (!s_factory) {
41 s_factory = new ReactionFactory;
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
52 private:
53 //! Pointer to the single instance of the factory
54 static ReactionFactory* s_factory;
55
56 //! default constructor, which is defined as private
57 ReactionFactory();
58
59 //! Mutex for use when calling the factory
60 static std::mutex reaction_mutex;
61};
62
63 class ReactionFactoryXML : public Factory<Reaction, const XML_Node&>
64{
65 public:
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
85 private:
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
FactoryBase.h
File contains the FactoryBase class declarations.
Reaction.h
Cantera::Factory
Factory class that supports registering functions to create objects.
Definition: FactoryBase.h:70
Cantera::ReactionFactory
Factory class to construct reaction function calculators.
Definition: ReactionFactory.h:31
Cantera::ReactionFactory::ReactionFactory
ReactionFactory()
default constructor, which is defined as private
Definition: ReactionFactory.cpp:23
Cantera::ReactionFactory::reaction_mutex
static std::mutex reaction_mutex
Mutex for use when calling the factory.
Definition: ReactionFactory.h:60
Cantera::ReactionFactory::s_factory
static ReactionFactory * s_factory
Pointer to the single instance of the factory.
Definition: ReactionFactory.h:54
Cantera::ReactionFactory::factory
static ReactionFactory * factory()
Return a pointer to the factory.
Definition: ReactionFactory.h:38
Cantera::ReactionFactory::deleteFactory
virtual void deleteFactory()
Virtual abstract function that deletes the factory.
Definition: ReactionFactory.h:46
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557