Cantera  3.1.0a2
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
36shared_ptr<FlowDevice> newFlowDevice(const string& model)
37{
38 return shared_ptr<FlowDevice>(FlowDeviceFactory::factory()->create(model));
39}
40
41shared_ptr<FlowDevice> newFlowDevice3(const string& model)
42{
43 return newFlowDevice(model);
44}
45
46}
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)
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