Addec copy constructor and assignment operator.
This commit is contained in:
parent
318b639211
commit
747717bf86
2 changed files with 71 additions and 0 deletions
|
|
@ -16,6 +16,67 @@
|
|||
|
||||
namespace Cantera {
|
||||
|
||||
|
||||
/*
|
||||
* Copy Constructor
|
||||
*
|
||||
* This function just does the default initialization, and
|
||||
* then calls the assignment operator.
|
||||
*/
|
||||
Phase::Phase(const Phase &right) :
|
||||
m_kk(-1),
|
||||
m_ndim(3),
|
||||
m_index(-1),
|
||||
m_xml(new XML_Node("phase")),
|
||||
m_id("<phase>"),
|
||||
m_name("")
|
||||
{
|
||||
/*
|
||||
* Call the assignment operator.
|
||||
*/
|
||||
*this = operator=(right);
|
||||
}
|
||||
|
||||
/*
|
||||
* Assignment operator
|
||||
*
|
||||
* This operation is sort of complicated. We have to
|
||||
* call the assignment operator for the Constituents and
|
||||
* State operators that Phase inherits from. Then,
|
||||
* we have to copy our own data, making sure to do a
|
||||
* deep copy on the XML_Node data owned by this object.
|
||||
*/
|
||||
const Phase &Phase::operator=(const Phase &right) {
|
||||
/*
|
||||
* Check for self assignment.
|
||||
*/
|
||||
if (this == &right) return *this;
|
||||
/*
|
||||
* Now call the inherited-classes assignment operators.
|
||||
*/
|
||||
(void) Constituents::operator=(right);
|
||||
(void) State::operator=(right);
|
||||
/*
|
||||
* Handle its own data
|
||||
*/
|
||||
m_kk = right.m_kk;
|
||||
m_ndim = right.m_ndim;
|
||||
m_index = right.m_index;
|
||||
m_data = right.m_data;
|
||||
/*
|
||||
* This is a little complicated. -> Because we delete m_xml
|
||||
* in the destructor, we own m_xml completely, and we need
|
||||
* to have our own individual copies of the XML data tree
|
||||
* in each object
|
||||
*/
|
||||
m_xml = new XML_Node(*(right.m_xml));
|
||||
m_id = right.m_id;
|
||||
m_name = right.m_name;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void Phase::saveState(vector_fp& state) const {
|
||||
state.resize(nSpecies() + 2);
|
||||
saveState(state.size(),state.begin());
|
||||
|
|
|
|||
|
|
@ -51,6 +51,16 @@ namespace Cantera {
|
|||
delete m_xml;
|
||||
m_xml = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy Constructor
|
||||
*/
|
||||
Phase(const Phase &c);
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
*/
|
||||
const Phase &operator=(const Phase &c);
|
||||
|
||||
XML_Node& xml() { return *m_xml; }
|
||||
string id() const { return m_id; }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue