<commit_before>// Copyright (C) 2017 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and University of
// of Connecticut School of Medicine.
// All rights reserved.

// Copyright (C) 2011 - 2016 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and The University
// of Manchester.
// All rights reserved.

#include <limits>

#include "copasi.h"

#include "CModelParameter.h"
#include "CModelParameterGroup.h"
#include "CModelParameterSet.h"
#include "CMetabNameInterface.h"
#include "CReaction.h"
#include "CopasiDataModel/CDataModel.h"
#include "function/CExpression.h"
#include "model/CModel.h"
#include "copasi/core/CRootContainer.h"
#include "report/CKeyFactory.h"
#include "copasi/core/CDataObject.h"
#include "utilities/CUnitValidator.h"
#include "utilities/CUnit.h"
#include "math/CMathExpression.h"

// static
const char * CModelParameter::TypeNames[] =
{
  "Model",
  "Compartment",
  "Species",
  "ModelValue",
  "ReactionParameter",
  "Reaction",
  "Group",
  "Set",
  "unknown",
  NULL
};

// static
std::string CModelParameter::nameFromCN(const CCommonName & cn)
{
  CCommonName Primary = cn.getPrimary();
  CCommonName Remainder = cn.getRemainder();

  while (Remainder != "")
    {
      Primary = Remainder.getPrimary();
      Remainder = Remainder.getRemainder();
    }

  std::string Name = Primary.getElementName(0);

  if (Name != "")
    {
      return Name;
    }

  return Primary.getObjectName();
}

CModelParameter::CModelParameter(CModelParameterGroup * pParent, const CModelParameter::Type & type):
  mpParent(static_cast< CModelParameterGroup * >(pParent)),
  mType(type),
  mCN(),
  mSimulationType(type == CModelParameter::Model ? CModelEntity::Status::TIME : CModelEntity::Status::FIXED),
  mValue(std::numeric_limits< C_FLOAT64 >::quiet_NaN()),
  mpInitialExpression(NULL),
  mCompareResult(CModelParameter::Identical),
  mpObject(NULL),
  mIsInitialExpressionValid(true)
{
  assert(mType == Set || mpParent != NULL);
}

CModelParameter::CModelParameter(const CModelParameter & src, CModelParameterGroup * pParent):
  mpParent(pParent),
  mType(src.mType),
  mCN(src.mCN),
  mSimulationType(src.mSimulationType),
  mValue(src.mValue),
  mpInitialExpression(NULL),
  mCompareResult(src.mCompareResult),
  mpObject(src.mpObject),
  mIsInitialExpressionValid(src.mIsInitialExpressionValid)
{
  assert(mType == Set || mpParent != NULL);

  setInitialExpression(src.getInitialExpression());
}

// virtual
CModelParameter::~CModelParameter()
{
  if (mpParent != NULL)
    {
      mpParent->remove(this);
    }
}

void CModelParameter::setParent(CModelParameterGroup * pParent)
{<commit_msg>Bug 2486: The initial expression is deleted in the destructor.<commit_after>// Copyright (C) 2017 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and University of
// of Connecticut School of Medicine.
// All rights reserved.

// Copyright (C) 2011 - 2016 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and The University
// of Manchester.
// All rights reserved.

#include <limits>

#include "copasi.h"

#include "CModelParameter.h"
#include "CModelParameterGroup.h"
#include "CModelParameterSet.h"
#include "CMetabNameInterface.h"
#include "CReaction.h"
#include "CopasiDataModel/CDataModel.h"
#include "function/CExpression.h"
#include "model/CModel.h"
#include "copasi/core/CRootContainer.h"
#include "report/CKeyFactory.h"
#include "copasi/core/CDataObject.h"
#include "utilities/CUnitValidator.h"
#include "utilities/CUnit.h"
#include "math/CMathExpression.h"

// static
const char * CModelParameter::TypeNames[] =
{
  "Model",
  "Compartment",
  "Species",
  "ModelValue",
  "ReactionParameter",
  "Reaction",
  "Group",
  "Set",
  "unknown",
  NULL
};

// static
std::string CModelParameter::nameFromCN(const CCommonName & cn)
{
  CCommonName Primary = cn.getPrimary();
  CCommonName Remainder = cn.getRemainder();

  while (Remainder != "")
    {
      Primary = Remainder.getPrimary();
      Remainder = Remainder.getRemainder();
    }

  std::string Name = Primary.getElementName(0);

  if (Name != "")
    {
      return Name;
    }

  return Primary.getObjectName();
}

CModelParameter::CModelParameter(CModelParameterGroup * pParent, const CModelParameter::Type & type):
  mpParent(static_cast< CModelParameterGroup * >(pParent)),
  mType(type),
  mCN(),
  mSimulationType(type == CModelParameter::Model ? CModelEntity::Status::TIME : CModelEntity::Status::FIXED),
  mValue(std::numeric_limits< C_FLOAT64 >::quiet_NaN()),
  mpInitialExpression(NULL),
  mCompareResult(CModelParameter::Identical),
  mpObject(NULL),
  mIsInitialExpressionValid(true)
{
  assert(mType == Set || mpParent != NULL);
}

CModelParameter::CModelParameter(const CModelParameter & src, CModelParameterGroup * pParent):
  mpParent(pParent),
  mType(src.mType),
  mCN(src.mCN),
  mSimulationType(src.mSimulationType),
  mValue(src.mValue),
  mpInitialExpression(NULL),
  mCompareResult(src.mCompareResult),
  mpObject(src.mpObject),
  mIsInitialExpressionValid(src.mIsInitialExpressionValid)
{
  assert(mType == Set || mpParent != NULL);

  setInitialExpression(src.getInitialExpression());
}

// virtual
CModelParameter::~CModelParameter()
{
  if (mpParent != NULL)
    {
      mpParent->remove(this);
    }

  pdelete(mpInitialExpression);
}

void CModelParameter::setParent(CModelParameterGroup * pParent)
{
{'fraction_non_alphanumeric': 0.13754578754578756, 'fraction_numerical': 0.0062271062271062275, 'mean_word_length': 5.156708004509583, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '1762381', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1775, 'n_words': 354}