Cantera  3.0.0
Loading...
Searching...
No Matches
FlowDeviceFactory.cpp
Go to the documentation of this file.
1//! @file FlowDeviceFactory.cpp
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
8
9namespace Cantera
10{
11
12FlowDeviceFactory* FlowDeviceFactory::s_factory = 0;
13std::mutex FlowDeviceFactory::flowDevice_mutex;
14
15FlowDeviceFactory::FlowDeviceFactory()
16{
17 reg("MassFlowController", []() { return new MassFlowController(); });
18 reg("PressureController", []() { return new PressureController(); });
19 reg("Valve", []() { return new Valve(); });
20}
21
22FlowDeviceFactory* FlowDeviceFactory::factory() {
23 std::unique_lock<std::mutex> lock(flowDevice_mutex);
24 if (!s_factory) {
25 s_factory = new FlowDeviceFactory;
26 }
27 return s_factory;
28}
29
31 std::unique_lock<std::mutex> lock(flowDevice_mutex);
32 delete s_factory;
33 s_factory = 0;
34}
35
36
37FlowDevice* FlowDeviceFactory::newFlowDevice(const string& flowDeviceType)
38{
39 warn_deprecated("FlowDeviceFactory::newFlowDevice",
40 "To be removed after Cantera 3.0; for new behavior, see 'newFlowDevice3'.");
41 return create(flowDeviceType);
42}
43
44FlowDevice* newFlowDevice(const string& model)
45{
46 warn_deprecated("newFlowDevice",
47 "To be changed after Cantera 3.0; for new behavior, see 'newFlowDevice3'.");
48 return FlowDeviceFactory::factory()->newFlowDevice(model);
49}
50
51shared_ptr<FlowDevice> newFlowDevice3(const string& model)
52{
53 shared_ptr<FlowDevice> fdptr(FlowDeviceFactory::factory()->create(model));
54 return fdptr;
55}
56
57}
FlowDevice * create(const string &name, Args... args)
Create an object using the object construction function corresponding to "name" and the provided cons...
Definition FactoryBase.h:75
void reg(const string &name, function< FlowDevice *(Args...)> f)
Register a new object construction function.
Definition FactoryBase.h:80
FlowDevice * newFlowDevice(const string &flowDeviceType)
Create a new flow device by type name.
void deleteFactory() override
Virtual abstract function that deletes the factory.
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition FlowDevice.h:24
Some flow devices derived from class FlowDevice.
FlowDevice * newFlowDevice(const string &model)
Create a FlowDevice object of the specified type.
shared_ptr< FlowDevice > newFlowDevice3(const string &model)
Create a FlowDevice object of the specified type.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1926