From 63b3b5ebc86a2cda9c47f9df0417357621e1b36a Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Wed, 17 May 2006 15:16:00 +0000 Subject: [PATCH] initial import --- Cantera/src/zeroD/ReactorFactory.cpp | 68 ++++++++++++++++++++++++++++ Cantera/src/zeroD/ReactorFactory.h | 68 ++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 Cantera/src/zeroD/ReactorFactory.cpp create mode 100644 Cantera/src/zeroD/ReactorFactory.h diff --git a/Cantera/src/zeroD/ReactorFactory.cpp b/Cantera/src/zeroD/ReactorFactory.cpp new file mode 100644 index 000000000..ed0e640e9 --- /dev/null +++ b/Cantera/src/zeroD/ReactorFactory.cpp @@ -0,0 +1,68 @@ +/** + * @file ReactorFactory.cpp + */ + +/* + * $Author$ + * $Revision$ + * $Date$ + */ + +// Copyright 2006 California Institute of Technology + + +#ifdef WIN32 +#pragma warning(disable:4786) +#endif + +#include "ReactorFactory.h" + +#include "Reservoir.h" +#include "Reactor.h" +#include "FlowReactor.h" +#include "ConstPressureReactor.h" + +namespace CanteraZeroD { + + ReactorFactory* ReactorFactory::s_factory = 0; + + static int ntypes = 4; + static string _types[] = {"Reservoir", "Reactor", "ConstPressureReactor", + "FlowReactor"}; + + // these constants are defined in ReactorBase.h + static int _itypes[] = {ReservoirType, ReactorType, FlowReactorType, + ConstPressureReactorType}; + + /** + * This method returns a new instance of a subclass of ThermoPhase + */ + ReactorBase* ReactorFactory::newReactor(string reactorType) { + + int ir=-1; + + for (int n = 0; n < ntypes; n++) { + if (reactorType == _types[n]) ir = _itypes[n]; + } + + return newReactor(ir); + } + + + ReactorBase* ReactorFactory::newReactor(int ir) { + switch (ir) { + case ReservoirType: + return new Reservoir(); + case ReactorType: + return new Reactor(); + case FlowReactorType: + return new FlowReactor(); + case ConstPressureReactorType: + return new ConstPressureReactor(); + default: + throw CanteraError("ReactorFactory::newReactor", + "unknown reactor type!"); + } + } + +} diff --git a/Cantera/src/zeroD/ReactorFactory.h b/Cantera/src/zeroD/ReactorFactory.h new file mode 100644 index 000000000..8a28cb7a0 --- /dev/null +++ b/Cantera/src/zeroD/ReactorFactory.h @@ -0,0 +1,68 @@ +/** + * @file ReactorFactory.h + */ + +/* + * $Author$ + * $Revision$ + * $Date$ + */ + +// Copyright 2001 California Institute of Technology + + +#ifndef REACTOR_FACTORY_H +#define REACTOR_FACTORY_H + +#include "ReactorBase.h" + +namespace CanteraZeroD { + + + class ReactorFactory { + + public: + + static ReactorFactory* factory() { + if (!s_factory) s_factory = new ReactorFactory; + return s_factory; + } + + static void deleteFactory() { + if (s_factory) { + delete s_factory; + s_factory = 0; + } + } + + /** + * Destructor doesn't do anything. + */ + virtual ~ReactorFactory() {} + + /** + * Create a new reactor. + * @param n the type to be created. + */ + virtual ReactorBase* newReactor(int n); + virtual ReactorBase* newReactor(string reactorType); + + private: + + static ReactorFactory* s_factory; + ReactorFactory(){} + }; + + inline ReactorBase* newReactor(string model, + ReactorFactory* f=0) { + if (f == 0) { + f = ReactorFactory::factory(); + } + return f->newReactor(model); + } + +} + +#endif + +