Cantera  3.1.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", [](const string& name) {
18 return new MassFlowController(name);
19 });
20 reg("PressureController", [](const string& name) {
21 return new PressureController(name);
22 });
23 reg("Valve", [](const string& name) {
24 return new Valve(name);
25 });
26}
27
28FlowDeviceFactory* FlowDeviceFactory::factory() {
29 std::unique_lock<std::mutex> lock(flowDevice_mutex);
30 if (!s_factory) {
31 s_factory = new FlowDeviceFactory;
32 }
33 return s_factory;
34}
35
37 std::unique_lock<std::mutex> lock(flowDevice_mutex);
38 delete s_factory;
39 s_factory = 0;
40}
41
42shared_ptr<FlowDevice> newFlowDevice(const string& model, const string& name)
43{
44 return shared_ptr<FlowDevice>(FlowDeviceFactory::factory()->create(model, name));
45}
46
47shared_ptr<FlowDevice> newFlowDevice3(const string& model)
48{
49 warn_deprecated("newFlowDevice3",
50 "Use newFlowDevice instead; to be removed after Cantera 3.1.");
51 return newFlowDevice(model);
52}
53
54}
void reg(const string &name, function< FlowDevice *(Args...)> f)
Register a new object construction function.
Definition FactoryBase.h:80
void deleteFactory() override
Virtual abstract function that deletes the factory.
Some flow devices derived from class FlowDevice.
shared_ptr< FlowDevice > newFlowDevice(const string &model, const string &name)
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:595
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997