Fixed the assignment operator.

This commit is contained in:
Harry Moffat 2008-12-04 02:02:45 +00:00
parent 6216127e05
commit 60d5e939db
2 changed files with 115 additions and 139 deletions

View file

@ -216,30 +216,54 @@ namespace Cantera {
"elements cannot be added after species.") {}
};
/*
* Elements Class Constructor
* We initialize all internal variables to zero here.
*/
Elements::Elements() :
m_mm(0),
m_elementsFrozen(false),
numSubscribers(0)
{
}
/*
* Elements Class Constructor
* We initialize all internal variables to zero here.
*/
Elements::Elements() :
m_mm(0),
m_elementsFrozen(false),
numSubscribers(0)
{
}
/*
* Elements Class Destructor
* If the number of subscribers is not zero, through an error.
* A logic problem has occurred.
*
* @exception CanteraError
*/
Elements::~Elements()
{
if (numSubscribers != 0) {
throw CanteraError("~Elements", "numSubscribers not zero");
}
/*
* Elements Class Destructor
* If the number of subscribers is not zero, through an error.
* A logic problem has occurred.
*
* @exception CanteraError
*/
Elements::~Elements() {
if (numSubscribers != 0) {
throw CanteraError("~Elements", "numSubscribers not zero");
}
}
Elements::Elements(const Elements &right) :
m_mm(0),
m_elementsFrozen(false),
numSubscribers(0)
{
*this = operator=(right);
}
Elements& Elements::operator=(const Elements &right) {
if (&right == this) return *this;
m_mm = right.m_mm;
m_elementsFrozen = right.m_elementsFrozen;
m_atomicWeights = right.m_atomicWeights;
m_atomicNumbers = right.m_atomicNumbers;
m_elementNames = right.m_elementNames;
m_entropy298 = right.m_entropy298;
numSubscribers = 0;
return *this;
}
/*
* freezeElements():
@ -475,76 +499,26 @@ namespace Cantera {
}
}
/*
* clear()
*
* Remove all elements from the structure.
*/
void Elements::clear() {
m_mm = 0;
m_atomicWeights.resize(0);
m_elementNames.resize(0);
m_elementsFrozen = false;
}
/*
* clear()
*
* Remove all elements from the structure.
*/
void Elements::clear() {
m_mm = 0;
m_atomicWeights.resize(0);
m_elementNames.resize(0);
m_elementsFrozen = false;
}
/*
* ready():
*
* True if the elements have been frozen
*/
bool Elements::ready() const {
return (m_elementsFrozen);
}
/*
* Elements(const Elements&) - copy constructor:
*
* This copy constructor just calls the assignment operator for this
* class.
*/
Elements::Elements(const Elements& right)
{
*this = right;
/*
* Set the number of subscribers to zero during a copy constructor
*/
numSubscribers = 0;
}
/*
* Elements& Elements::operator=(const Elements& right):
*
* (assignment operator)
*
* This is the assignment operator for the Elements class.
* Right now we pretty much do a straight uncomplicated
* assignment. However, subscribers are not mucked with, as they
* have to do with the address of the object to be subscribed to
*/
Elements& Elements::operator=(const Elements& 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_mm = right.m_mm;
m_elementsFrozen = right.m_elementsFrozen;
m_atomicWeights = right.m_atomicWeights;
m_elementNames = right.m_elementNames;
/*
* We must not muck with the number of subscribers to this object
* during a straight assignment. This number was set in the
* constructor operation.
*/
/*
* Return the reference to the current object
*/
return *this;
}
/*
* ready():
*
* True if the elements have been frozen
*/
bool Elements::ready() const {
return (m_elementsFrozen);
}
void Elements::addElementsFromXML(const XML_Node& phase) {

View file

@ -55,6 +55,27 @@ namespace Cantera {
//! Default destructor for the elements class
~Elements();
//! copy constructor
/*!
* This copy constructor just calls the assignment operator for this
* class. It sets the number of subscribers to zer0.
*
* @param right Reference to the object to be copied.
*/
Elements(const Elements& right);
//! Assigntment operator
/*!
* This is the assignment operator for the Elements class.
* Right now we pretty much do a straight uncomplicated
* assignment. However, subscribers are not mucked with, as they
* have to do with the address of the object to be subscribed to
*
* @param right Reference to the object to be copied.
*/
Elements& operator=(const Elements& right);
//! Function to lookup the atomic weight of an element
/*!
* @param ename Element symbol name.
@ -189,26 +210,7 @@ namespace Cantera {
/// True if both elements and species have been frozen
bool ready() const;
//! copy constructor
/*!
* This copy constructor just calls the assignment operator for this
* class. It sets the number of subscribers to zer0.
*
* @param right Reference to the object to be copied.
*/
Elements(const Elements& right);
//! Assigntment operator
/*!
* This is the assignment operator for the Elements class.
* Right now we pretty much do a straight uncomplicated
* assignment. However, subscribers are not mucked with, as they
* have to do with the address of the object to be subscribed to
*
* @param right Reference to the object to be copied.
*/
Elements& operator=(const Elements& right);
//! subscribe to this object
/*!
* Increment by one the number of subscriptions to this object.
@ -233,38 +235,38 @@ namespace Cantera {
//! Number of elements.
int m_mm;
/* m_elementsFrozen: */
/** boolean indicating completion of object
*
* If this is true, then no elements may be added to the
* object.
*/
bool m_elementsFrozen;
/* m_elementsFrozen: */
/** boolean indicating completion of object
*
* If this is true, then no elements may be added to the
* object.
*/
bool m_elementsFrozen;
/**
* Vector of element atomic weights:
*
* units = kg / kmol
*/
vector_fp m_atomicWeights;
/**
* Vector of element atomic weights:
*
* units = kg / kmol
*/
vector_fp m_atomicWeights;
/**
* Vector of element atomic numbers:
*
*/
vector_int m_atomicNumbers;
/**
* Vector of element atomic numbers:
*
*/
vector_int m_atomicNumbers;
/** Vector of strings containing the names of the elements
*
* Note, a string search is the primary way to identify elements.
*/
std::vector<std::string> m_elementNames;
/** Vector of strings containing the names of the elements
*
* Note, a string search is the primary way to identify elements.
*/
std::vector<std::string> m_elementNames;
//! Entropy at 298.15 K and 1 bar of stable state
/*!
* units J kmol-1
*/
vector_fp m_entropy298;
//! Entropy at 298.15 K and 1 bar of stable state
/*!
* units J kmol-1
*/
vector_fp m_entropy298;
/**
* Number of Constituents Objects that use this object