Added a copy constructor and an assignment operator.

This commit is contained in:
Harry Moffat 2005-10-21 18:23:08 +00:00
parent 593c6b4aeb
commit 82fa55b04a
2 changed files with 101 additions and 42 deletions

View file

@ -60,7 +60,10 @@ namespace Cantera {
}
/**
* Destructor.
* Destructor for class Constituents.
*
* Some cleanup of of the Global_Elements_List array is
* effected by unsubscribing to m_Elements.
*/
Constituents::~Constituents()
{
@ -170,14 +173,14 @@ namespace Cantera {
m_Elements->freezeElements();
}
/**
/*
* -> Passthrough to the Element lvl.
*/
bool Constituents::elementsFrozen() {
return m_Elements->elementsFrozen();
}
/**
/*
* Index of element named \a name. The index is an integer
* assigned to each element in the order it was added,
* beginning with 0 for the first element. If \a name is not
@ -191,15 +194,13 @@ namespace Cantera {
return (m_Elements->elementIndex(name));
}
/*******************************************************************
*
* elementName():
*
* Name of the element with index \c m. @param m Element
* index. If m < 0 or m >= nElements() an exception is thrown.
*
*
* -> Passthrough to the Element lvl.
/*
* Name of the element with index m.
*
* This is a passthrough routine to the Element object.
* @param m @{ Element index. @}
* \exception If m < 0 or m >= nElements(), the
* exception, ElementRangeError, is thrown.
*/
string Constituents::elementName(int m) const {
return (m_Elements->elementName(m));
@ -445,4 +446,48 @@ namespace Cantera {
}
}
/**
* This copy constructor just calls the assignment operator
* for this class.
* The assignment operator does a deep copy.
*/
Constituents::Constituents(const Constituents& right) {
*this = right;
}
/**
* Assignment operator for the Constituents class.
* Right now we pretty much do a straight uncomplicated
* copy of all of the protected data.
*/
Constituents& Constituents::operator=(const Constituents& right) {
/*
* Check for self assignment.
*/
if (this == &right) return *this;
/*
* We do a straight assignment operator on all of the
* data. The vectors are copied.
*/
m_kk = right.m_kk;
m_weight = right.m_weight;
m_speciesFrozen = right.m_speciesFrozen;
if (m_Elements) {
m_Elements->unsubscribe();
}
m_Elements = right.m_Elements;
if (m_Elements) {
m_Elements->subscribe();
}
m_speciesNames = right.m_speciesNames;
m_speciesComp = right.m_speciesComp;
m_speciesCharge = right.m_speciesCharge;
m_speciesSize = right.m_speciesSize;
/*
* Return the reference to the current object
*/
return *this;
}
}

View file

@ -8,7 +8,10 @@
* $Revision$
*
* $Log$
* Revision 1.7 2005-06-18 17:01:08 dggoodwin
* Revision 1.8 2005-10-21 18:23:08 hkmoffa
* Added a copy constructor and an assignment operator.
*
* Revision 1.7 2005/06/18 17:01:08 dggoodwin
* Prerelease_1_6_0_branch merged into trunk
*
* Revision 1.6.2.1 2005/01/24 15:09:11 dggoodwin
@ -80,46 +83,60 @@ namespace Cantera {
public:
/// Constructor.
Constituents(Elements* ptr_Elements = 0);
/// Constructor.
Constituents(Elements* ptr_Elements = 0);
/// Destructor.
~Constituents();
/// Destructor.
~Constituents();
/// @name Element Information
//@{
/// This copy constructor just calls the assignment operator
/// for this class.
Constituents(const Constituents& right);
/// Assignment operator
Constituents& operator=(const Constituents& right);
/// @name Element Information
//@{
/// Name of the element with index m. @param m Element
/// index. If m < 0 or m >= nElements() an exception is thrown.
string elementName(int m) const;
/// Name of the element with index m.
/// This is a passthrough routine to the Element object.
/// @param m @{ Element index. @}
/// \exception If m < 0 or m >= nElements(), the
/// exception, ElementRangeError, is thrown.
string elementName(int m) const;
/// Index of element named 'name'. The index is an integer
/// assigned to each element in the order it was added,
/// beginning with 0 for the first element. If 'name' is not
/// the name of an element in the set, then the value -1 is
/// returned.
int elementIndex(string name) const;
/// Index of element named 'name'.
/// The index is an integer
/// assigned to each element in the order it was added,
/// beginning with 0 for the first element.
/// @param name @{ name of the element @}
///
/// If 'name' is not
/// the name of an element in the set, then the value -1 is
/// returned.
int elementIndex(string name) const;
/// Atomic weight of element m.
doublereal atomicWeight(int m) const;
/// Atomic weight of element m.
doublereal atomicWeight(int m) const;
/// Atomic number of element m.
int atomicNumber(int m) const;
/// Atomic number of element m.
int atomicNumber(int m) const;
/// Return a read-only reference to the vector of element names.
const vector<string>& elementNames() const;
/// Return a read-only reference to the vector of element names.
const vector<string>& elementNames() const;
/// Return a read-only reference to the vector of atomic weights.
const array_fp& atomicWeights() const;
/// Return a read-only reference to the vector of atomic weights.
const array_fp& atomicWeights() const;
/// Number of elements.
int nElements() const;
/// Number of elements.
int nElements() const;
//@}
//@}
@ -253,9 +270,6 @@ namespace Cantera {
*/
void getAtoms(int k, double *atomArray) const;
/// Copy constructor and assignment operator
Constituents::Constituents(const Constituents& right);
Constituents& operator=(const Constituents& right);
protected: