<commit_before>/**
 *  @file ThermoPhase.cpp
 * Definition file for class ThermoPhase, the base class for phases with
 * thermodynamic properties
 * (see class \link Cantera::ThermoPhase ThermoPhase\endlink).
 */

/*
 *  $Author$
 *  $Date$
 *  $Revision$
 *
 *  Copyright 2002 California Institute of Technology
 *
 */

// turn off warnings under Windows
#ifdef WIN32
#pragma warning(disable:4786)
#pragma warning(disable:4503)
#endif

#include "ThermoPhase.h"

//@{
#ifndef MAX
#define MAX(x,y)    (( (x) > (y) ) ? (x) : (y))
#endif
//@}

using namespace std;

namespace Cantera {

  //! Constructor. Note that ThermoPhase is meant to be used as
  //! a base class, so this constructor should not be called
  //! explicitly.
  ThermoPhase::ThermoPhase() :
    Phase(), 
    m_spthermo(0), m_speciesData(0),
    m_index(-1), 
    m_phi(0.0), 
    m_hasElementPotentials(false),
    m_chargeNeutralityNecessary(false),
    m_ssConvention(cSS_CONVENTION_TEMPERATURE)
  {
  }

  ThermoPhase::~ThermoPhase() 
  {
    for (int k = 0; k < m_kk; k++) {
      if (!m_speciesData[k]) {
        delete m_speciesData[k];
      }
    }
    delete m_spthermo;
  }

  /**
   * Copy Constructor for the ThermoPhase object. 
   *
   * Currently, this is implemented, but not tested. If called it will
   * throw an exception until fully tested.
   */
  ThermoPhase::ThermoPhase(const ThermoPhase &right)  :
    Phase(),
    m_spthermo(0), 
    m_speciesData(0),
    m_index(-1),
    m_phi(0.0), 
    m_hasElementPotentials(false),
    m_chargeNeutralityNecessary(false),
    m_ssConvention(cSS_CONVENTION_TEMPERATURE)
  {
    /*
     * Call the assignment operator
     */
    *this = operator=(right);
  }
  
  /*
   * operator=()
   *
   *  Note this stuff will not work until the underlying phase
   *  has a working assignment operator
   */
  ThermoPhase& ThermoPhase::
  operator=(const ThermoPhase &right) {
    /*
     * Check for self assignment.
     */
    if (this == &right) return *this;

    /*
     * We need to destruct first
     */
    for (int k = 0; k < m_kk; k++) {
      if (!m_speciesData[k]) {
        delete m_speciesData[k];
      }
    }
    if (m_spthermo) {<commit_msg>Fixed a memory leak error, due to faulty logic in  the destructor.<commit_after>/**
 *  @file ThermoPhase.cpp
 * Definition file for class ThermoPhase, the base class for phases with
 * thermodynamic properties
 * (see class \link Cantera::ThermoPhase ThermoPhase\endlink).
 */

/*
 *  $Author$
 *  $Date$
 *  $Revision$
 *
 *  Copyright 2002 California Institute of Technology
 *
 */

// turn off warnings under Windows
#ifdef WIN32
#pragma warning(disable:4786)
#pragma warning(disable:4503)
#endif

#include "ThermoPhase.h"

//@{
#ifndef MAX
#define MAX(x,y)    (( (x) > (y) ) ? (x) : (y))
#endif
//@}

using namespace std;

namespace Cantera {

  //! Constructor. Note that ThermoPhase is meant to be used as
  //! a base class, so this constructor should not be called
  //! explicitly.
  ThermoPhase::ThermoPhase() :
    Phase(), 
    m_spthermo(0), m_speciesData(0),
    m_index(-1), 
    m_phi(0.0), 
    m_hasElementPotentials(false),
    m_chargeNeutralityNecessary(false),
    m_ssConvention(cSS_CONVENTION_TEMPERATURE)
  {
  }

  ThermoPhase::~ThermoPhase() 
  {
    for (int k = 0; k < m_kk; k++) {
      if (m_speciesData[k]) {
        delete m_speciesData[k];
        m_speciesData[k] = 0;
      }
    }
    delete m_spthermo;
    m_spthermo = 0;
  }

  /**
   * Copy Constructor for the ThermoPhase object. 
   *
   * Currently, this is implemented, but not tested. If called it will
   * throw an exception until fully tested.
   */
  ThermoPhase::ThermoPhase(const ThermoPhase &right)  :
    Phase(),
    m_spthermo(0), 
    m_speciesData(0),
    m_index(-1),
    m_phi(0.0), 
    m_hasElementPotentials(false),
    m_chargeNeutralityNecessary(false),
    m_ssConvention(cSS_CONVENTION_TEMPERATURE)
  {
    /*
     * Call the assignment operator
     */
    *this = operator=(right);
  }
  
  /*
   * operator=()
   *
   *  Note this stuff will not work until the underlying phase
   *  has a working assignment operator
   */
  ThermoPhase& ThermoPhase::
  operator=(const ThermoPhase &right) {
    /*
     * Check for self assignment.
     */
    if (this == &right) return *this;

    /*
     * We need to destruct first
     */
    for (int k = 0; k < m_kk; k++) {
      if (m_speciesData[k]) {
        delete m_speciesData[k];
        m_speciesData[k] = 0;
      }
    }
    if (m_spthermo) {
{'fraction_non_alphanumeric': 0.12447210491220272, 'fraction_numerical': 0.012224938875305624, 'mean_word_length': 2.7468776019983348, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4871955', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1521, 'n_words': 397}