diff --git a/Cantera/src/thermo/Elements.cpp b/Cantera/src/thermo/Elements.cpp index f4da84902..0022241ef 100644 --- a/Cantera/src/thermo/Elements.cpp +++ b/Cantera/src/thermo/Elements.cpp @@ -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) { diff --git a/Cantera/src/thermo/Elements.h b/Cantera/src/thermo/Elements.h index 27c40f636..2423aa059 100644 --- a/Cantera/src/thermo/Elements.h +++ b/Cantera/src/thermo/Elements.h @@ -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 m_elementNames; + /** Vector of strings containing the names of the elements + * + * Note, a string search is the primary way to identify elements. + */ + std::vector 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