Added copy constructor and assignment operator

This commit is contained in:
Harry Moffat 2010-07-16 16:25:32 +00:00
parent 6c8835bb84
commit e759ea1a4b

View file

@ -15,77 +15,128 @@
#include "Cantera.h"
#include "thermo.h"
#include "kinetics.h"
// #include "kernel/SurfPhase.h"
// #include "kernel/InterfaceKinetics.h"
// #include "kernel/importKinetics.h"
/**
* This namespace is used for the Cantera C++ user interface.
*/
namespace Cantera_CXX {
/**
* An interface between multiple bulk phases. This class is
* defined mostly for convenience. It inherits both from
* Cantera::SurfPhase and Cantera::InterfaceKinetics. It therefore
* represents a surface phase, and also acts as the kinetics
* manager to manage reaction occurring on the surface, possibly
* involving species from other phases.
//! An interface between multiple bulk phases.
/*!
* This class isdefined mostly for convenience. It inherits both from
* Cantera::SurfPhase and Cantera::InterfaceKinetics. It therefore
* represents a surface phase, and also acts as the kinetics
* manager to manage reactions occurring on the surface, possibly
* involving species from other phases.
*/
class Interface :
public Cantera::SurfPhase,
public Cantera::InterfaceKinetics
{
public:
//! Constructor.
/*!
* Construct an Interface instance from a specification in an input file.
*
* @param infile. Cantera input file in CTI or CTML format.
* @param id Identification string to distinguish between
* multiple definitions within one input file.
* @param otherPhases Neighboring phases that may participate in the
* reactions on this interface. Don't include the
* surface phase
*
* @deprecated
* While it's convenient to have the surface phase and the interfacial reaction
* together, this class doesn't satisfy the primary issue, which is one
* of instantiation of all the ThermoPhase classes that accompany a
* surface reaction. This is accomplished by the PhaseList class along with
* the ReactingSurface class. These classes will be migrated into Cantera
* soon.
*/
class Interface :
public Cantera::SurfPhase,
public Cantera::InterfaceKinetics
Interface(std::string infile, std::string id,
std::vector<Cantera::ThermoPhase*> otherPhases) :
m_ok(false),
m_r(0)
{
public:
/**
* Constructor. Construct an Interface instance from
* a specification in an input file.
* @param infile. Cantera input file in CTI or CTML format.
* @param id Identification string to distinguish between
* multiple definitions within one input file.
* @param phases Neighboring phases that may participate in the
* reactions on this interface.
*/
Interface(std::string infile, std::string id,
std::vector<Cantera::ThermoPhase*> phases)
: m_ok(false), m_r(0) {
m_r = Cantera::get_XML_File(infile);
if (id == "-") id = "";
Cantera::XML_Node* x = Cantera::get_XML_Node("#"+id, m_r);
if (!x)
throw Cantera::CanteraError("Interface","error in get_XML_Node");
Cantera::importPhase(*x, this);
phases.push_back(this);
Cantera::importKinetics(*x, phases, this);
m_ok = true;
}
/// Destructor. Does nothing.
virtual ~Interface() {}
bool operator!() { return !m_ok;}
bool ready() const { return m_ok; }
protected:
bool m_ok;
Cantera::XML_Node* m_r;
private:
};
/**
* Import an instance of class Interface from a specification in an
* input file. This is the preferred method to create an Interface
* instance.
*/
inline Interface* importInterface(std::string infile, std::string id,
std::vector<Cantera::ThermoPhase*> phases) {
return new Interface(infile, id, phases);
m_r = Cantera::get_XML_File(infile);
if (id == "-") id = "";
Cantera::XML_Node* x = Cantera::get_XML_Node("#"+id, m_r);
if (!x) {
throw Cantera::CanteraError("Interface","error in get_XML_Node");
}
Cantera::importPhase(*x, this);
otherPhases.push_back(this);
Cantera::importKinetics(*x, otherPhases, this);
m_ok = true;
}
//! Copy Constructor
/*!
* @param ii Interface object to be copied.
*/
Interface(const Interface& ii) :
Cantera::SurfPhase(ii),
Cantera::InterfaceKinetics(ii),
m_ok(ii.m_ok),
m_r(ii.m_r)
{
}
//! Assignment operator
/*!
* @param right Interface object to be copied.
*/
Interface & operator=(const Interface &right) {
if (this == &right) return *this;
Cantera::SurfPhase::operator=(right);
Cantera::InterfaceKinetics::operator=(right);
m_ok = right.m_ok;
m_r = right.m_r;
return *this;
}
//! Destructor. Does nothing.
virtual ~Interface() {
}
//! Not operator
bool operator!() {
return !m_ok;
}
//! return whether the object has been instantiated
/*!
* @return Returns a bool.
*/
bool ready() const {
return m_ok;
}
protected:
//! Flag indicating that the object has been instantiated
bool m_ok;
//! XML_Node pointer to the XML File object that contains the Surface and the Interfacial Reaction object
//! description
Cantera::XML_Node* m_r;
};
//! Import an instance of class Interface from a specification in an input file.
/*!
* This is the preferred method to create an Interface instance.
*/
Interface* importInterface(std::string infile, std::string id, std::vector<Cantera::ThermoPhase*> phases) {
return new Interface(infile, id, phases);
}
}