Cantera 2.6.0

FlowDeviceFactory.h
Go to the documentation of this file.
1//! @file FlowDeviceFactory.h
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
6#ifndef FLOWDEVICE_FACTORY_H
7#define FLOWDEVICE_FACTORY_H
8
9#include "cantera/base/FactoryBase.h"
10#include "cantera/zeroD/FlowDevice.h"
11
12 namespace Cantera
13{
14
15//! Factory class to create FlowDevice objects.
16//!
17//! This class is mainly used via the newFlowDevice() function, for example:
18//!
19//! ```cpp
20//! unique_ptr<FlowDevice> mfc(newFlowDevice("MassFlowController"));
21//! ```
22//!
23//! @ingroup ZeroD
24 class FlowDeviceFactory : public Factory<FlowDevice>
25{
26 public:
27 static FlowDeviceFactory* factory() {
28 std::unique_lock<std::mutex> lock(flowDevice_mutex);
29 if (!s_factory) {
30 s_factory = new FlowDeviceFactory;
31 }
32 return s_factory;
33 }
34
35 virtual void deleteFactory() {
36 std::unique_lock<std::mutex> lock(flowDevice_mutex);
37 delete s_factory;
38 s_factory = 0;
39 }
40
41 //! Create a new flow device by type name.
42 /*!
43 * @param flowDeviceType the type to be created.
44 */
45 virtual FlowDevice* newFlowDevice(const std::string& flowDeviceType);
46
47 private:
48 static FlowDeviceFactory* s_factory;
49 static std::mutex flowDevice_mutex;
50 FlowDeviceFactory();
51};
52
53//! Create a FlowDevice object of the specified type
54//! @ingroup ZeroD
55 inline FlowDevice* newFlowDevice(const std::string& model)
56{
57 return FlowDeviceFactory::factory()->newFlowDevice(model);
58}
59
60}
61
62#endif
FactoryBase.h
File contains the FactoryBase class declarations.
FlowDevice.h
Cantera::Factory
Factory class that supports registering functions to create objects.
Definition: FactoryBase.h:70
Cantera::FlowDeviceFactory
Factory class to create FlowDevice objects.
Definition: FlowDeviceFactory.h:25
Cantera::FlowDeviceFactory::newFlowDevice
virtual FlowDevice * newFlowDevice(const std::string &flowDeviceType)
Create a new flow device by type name.
Definition: FlowDeviceFactory.cpp:23
Cantera::FlowDeviceFactory::deleteFactory
virtual void deleteFactory()
Virtual abstract function that deletes the factory.
Definition: FlowDeviceFactory.h:35
Cantera::FlowDevice
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition: FlowDevice.h:24
Cantera::newFlowDevice
FlowDevice * newFlowDevice(const std::string &model)
Create a FlowDevice object of the specified type.
Definition: FlowDeviceFactory.h:55
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557