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() Constituents::~Constituents()
{ {
@ -170,14 +173,14 @@ namespace Cantera {
m_Elements->freezeElements(); m_Elements->freezeElements();
} }
/** /*
* -> Passthrough to the Element lvl. * -> Passthrough to the Element lvl.
*/ */
bool Constituents::elementsFrozen() { bool Constituents::elementsFrozen() {
return m_Elements->elementsFrozen(); return m_Elements->elementsFrozen();
} }
/** /*
* Index of element named \a name. The index is an integer * Index of element named \a name. The index is an integer
* assigned to each element in the order it was added, * assigned to each element in the order it was added,
* beginning with 0 for the first element. If \a name is not * beginning with 0 for the first element. If \a name is not
@ -191,15 +194,13 @@ namespace Cantera {
return (m_Elements->elementIndex(name)); return (m_Elements->elementIndex(name));
} }
/******************************************************************* /*
* * Name of the element with index m.
* elementName(): *
* * This is a passthrough routine to the Element object.
* Name of the element with index \c m. @param m Element * @param m @{ Element index. @}
* index. If m < 0 or m >= nElements() an exception is thrown. * \exception If m < 0 or m >= nElements(), the
* * exception, ElementRangeError, is thrown.
*
* -> Passthrough to the Element lvl.
*/ */
string Constituents::elementName(int m) const { string Constituents::elementName(int m) const {
return (m_Elements->elementName(m)); 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$ * $Revision$
* *
* $Log$ * $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 * Prerelease_1_6_0_branch merged into trunk
* *
* Revision 1.6.2.1 2005/01/24 15:09:11 dggoodwin * Revision 1.6.2.1 2005/01/24 15:09:11 dggoodwin
@ -80,46 +83,60 @@ namespace Cantera {
public: public:
/// Constructor. /// Constructor.
Constituents(Elements* ptr_Elements = 0); Constituents(Elements* ptr_Elements = 0);
/// Destructor. /// Destructor.
~Constituents(); ~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 /// Name of the element with index m.
/// index. If m < 0 or m >= nElements() an exception is thrown. /// This is a passthrough routine to the Element object.
string elementName(int m) const; /// @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 /// Index of element named 'name'.
/// assigned to each element in the order it was added, /// The index is an integer
/// beginning with 0 for the first element. If 'name' is not /// assigned to each element in the order it was added,
/// the name of an element in the set, then the value -1 is /// beginning with 0 for the first element.
/// returned. /// @param name @{ name of the element @}
int elementIndex(string name) const; ///
/// 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. /// Atomic weight of element m.
doublereal atomicWeight(int m) const; doublereal atomicWeight(int m) const;
/// Atomic number of element m. /// Atomic number of element m.
int atomicNumber(int m) const; int atomicNumber(int m) const;
/// Return a read-only reference to the vector of element names. /// Return a read-only reference to the vector of element names.
const vector<string>& elementNames() const; const vector<string>& elementNames() const;
/// Return a read-only reference to the vector of atomic weights. /// Return a read-only reference to the vector of atomic weights.
const array_fp& atomicWeights() const; const array_fp& atomicWeights() const;
/// Number of elements. /// Number of elements.
int nElements() const; int nElements() const;
//@} //@}
@ -253,9 +270,6 @@ namespace Cantera {
*/ */
void getAtoms(int k, double *atomArray) const; void getAtoms(int k, double *atomArray) const;
/// Copy constructor and assignment operator
Constituents::Constituents(const Constituents& right);
Constituents& operator=(const Constituents& right);
protected: protected: