<commit_before>/* Begin CVS Header
   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/utilities/CCopasiParameterGroup.cpp,v $
   $Revision: 1.5 $
   $Name:  $
   $Author: shoops $ 
   $Date: 2003/12/30 15:43:07 $
   End CVS Header */

/**
 *  CCopasiParameterGroup class.
 *  This class is used to describe parameters. This class is intended
 *  to be used with integration or optimization methods or reactions.
 *  
 *  Created for Copasi by <NAME> 2002
 */

#include "copasi.h"

#include "CCopasiParameterGroup.h"

CCopasiParameterGroup::CCopasiParameterGroup():
    CCopasiParameter("NoName", GROUP)
{}

CCopasiParameterGroup::CCopasiParameterGroup(const CCopasiParameterGroup & src,
    const CCopasiContainer * pParent):
    CCopasiParameter(src, pParent)
{createGroup((parameterGroup *) src.CCopasiParameter::getValue());}

CCopasiParameterGroup::CCopasiParameterGroup(const std::string & name,
    const CCopasiContainer * pParent,
    const std::string & objectType):
    CCopasiParameter(name, CCopasiParameter::GROUP, NULL, pParent, objectType)
{createGroup();}

CCopasiParameterGroup::~CCopasiParameterGroup()
{deleteGroup();}

void CCopasiParameterGroup::createGroup(const parameterGroup * pGroup)
{
  deleteGroup();

  mpValue = new parameterGroup;
  mSize = sizeof(parameterGroup);

  if (!pGroup) return;

  index_iterator it = const_cast< parameterGroup * >(pGroup)->begin();
  index_iterator end = const_cast< parameterGroup * >(pGroup)->end();

  CCopasiParameter * pParameter;

  for (; it != end; ++it)
    {
      if ((*it)->getType() == GROUP)
        pParameter = new CCopasiParameterGroup(* (CCopasiParameterGroup *) * it);
      else
        pParameter = new CCopasiParameter(**it);

      addParameter(pParameter);
    }
}

void CCopasiParameterGroup::deleteGroup()
{
  if (!mpValue) return;

  index_iterator it = ((parameterGroup *) mpValue)->begin();
  index_iterator end = ((parameterGroup *) mpValue)->end();

  for (; it != end; ++it) pdelete(*it);

  if (mpValue)
    {
      delete (parameterGroup *) mpValue;
      mpValue = NULL;
    }
}

void CCopasiParameterGroup::addParameter(CCopasiParameter * pParameter)
{
  CCopasiContainer::add(pParameter, true);
  ((parameterGroup *) mpValue)->push_back(pParameter);
}

CCopasiParameterGroup::name_iterator CCopasiParameterGroup::beginName() const
  {return const_cast< CCopasiContainer::objectMap * >(&getObjects())->begin();}

CCopasiParameterGroup::name_iterator CCopasiParameterGroup::nameEnd() const
  {return const_cast< CCopasiContainer::objectMap * >(&getObjects())->end();}

CCopasiParameterGroup::index_iterator CCopasiParameterGroup::beginIndex() const
  {return ((parameterGroup *) mpValue)->begin();}

CCopasiParameterGroup::index_iterator CCopasiParameterGroup::endIndex() const
  {return ((parameterGroup *) mpValue)->end();}

bool CCopasiParameterGroup::addParameter(const std::string & name,
    const CCopasiParameter::Type type)
{
  CCopasiParameter * pParameter;

  if (type == GROUP)
    pParameter = new CCopasiParameterGroup(name);
  else
    pParameter = new CCopasiParameter(name, type);

  addParameter(pParameter);

  return true;
}

bool CCopasiParameterGroup::addGroup(const std::string & name)
{
  addParameter(new CCopasiParameterGroup(name));
  return true;
}

bool CCopasiParameterGroup::removeParameter(const std::string & name)
{
  unsigned C_INT32 index = getIndex(name);

  if (index != C_INVALID_INDEX)
    {
      index_iterator it =
        ((parameterGroup *) mpValue)->begin() + index;

      ((parameterGroup *) mpValue)->erase(it, it + 1);
      pdelete(*it);

      return true;
    }

  return false;
}

bool CCopasiParameterGroup::removeParameter(const unsigned C_INT32 & index)
{
  if (index < size())
    {
      index_iterator it =
        ((parameterGroup *) mpValue)->begin() + index;

      ((parameterGroup *) mpValue)->erase(it, it + 1);
      pdelete(*it);

      return true;
    }

  return false;
}

CCopasiParameter * CCopasiParameterGroup::getParameter(const std::string & name)
{
  std::pair < CCopasiContainer::objectMap::const_iterator,
  CCopasiContainer::objectMap::const_iterator > range =<commit_msg>Reversed order of pdelete and erase in both removeParameter methods. The old code was faulty since erase updates the iterator.<commit_after>/* Begin CVS Header
   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/utilities/CCopasiParameterGroup.cpp,v $
   $Revision: 1.6 $
   $Name:  $
   $Author: shoops $ 
   $Date: 2003/12/30 17:19:47 $
   End CVS Header */

/**
 *  CCopasiParameterGroup class.
 *  This class is used to describe parameters. This class is intended
 *  to be used with integration or optimization methods or reactions.
 *  
 *  Created for Copasi by <NAME> 2002
 */

#include "copasi.h"

#include "CCopasiParameterGroup.h"

CCopasiParameterGroup::CCopasiParameterGroup():
    CCopasiParameter("NoName", GROUP)
{}

CCopasiParameterGroup::CCopasiParameterGroup(const CCopasiParameterGroup & src,
    const CCopasiContainer * pParent):
    CCopasiParameter(src, pParent)
{createGroup((parameterGroup *) src.CCopasiParameter::getValue());}

CCopasiParameterGroup::CCopasiParameterGroup(const std::string & name,
    const CCopasiContainer * pParent,
    const std::string & objectType):
    CCopasiParameter(name, CCopasiParameter::GROUP, NULL, pParent, objectType)
{createGroup();}

CCopasiParameterGroup::~CCopasiParameterGroup()
{deleteGroup();}

void CCopasiParameterGroup::createGroup(const parameterGroup * pGroup)
{
  deleteGroup();

  mpValue = new parameterGroup;
  mSize = sizeof(parameterGroup);

  if (!pGroup) return;

  index_iterator it = const_cast< parameterGroup * >(pGroup)->begin();
  index_iterator end = const_cast< parameterGroup * >(pGroup)->end();

  CCopasiParameter * pParameter;

  for (; it != end; ++it)
    {
      if ((*it)->getType() == GROUP)
        pParameter = new CCopasiParameterGroup(* (CCopasiParameterGroup *) * it);
      else
        pParameter = new CCopasiParameter(**it);

      addParameter(pParameter);
    }
}

void CCopasiParameterGroup::deleteGroup()
{
  if (!mpValue) return;

  index_iterator it = ((parameterGroup *) mpValue)->begin();
  index_iterator end = ((parameterGroup *) mpValue)->end();

  for (; it != end; ++it) pdelete(*it);

  if (mpValue)
    {
      delete (parameterGroup *) mpValue;
      mpValue = NULL;
    }
}

void CCopasiParameterGroup::addParameter(CCopasiParameter * pParameter)
{
  CCopasiContainer::add(pParameter, true);
  ((parameterGroup *) mpValue)->push_back(pParameter);
}

CCopasiParameterGroup::name_iterator CCopasiParameterGroup::beginName() const
  {return const_cast< CCopasiContainer::objectMap * >(&getObjects())->begin();}

CCopasiParameterGroup::name_iterator CCopasiParameterGroup::nameEnd() const
  {return const_cast< CCopasiContainer::objectMap * >(&getObjects())->end();}

CCopasiParameterGroup::index_iterator CCopasiParameterGroup::beginIndex() const
  {return ((parameterGroup *) mpValue)->begin();}

CCopasiParameterGroup::index_iterator CCopasiParameterGroup::endIndex() const
  {return ((parameterGroup *) mpValue)->end();}

bool CCopasiParameterGroup::addParameter(const std::string & name,
    const CCopasiParameter::Type type)
{
  CCopasiParameter * pParameter;

  if (type == GROUP)
    pParameter = new CCopasiParameterGroup(name);
  else
    pParameter = new CCopasiParameter(name, type);

  addParameter(pParameter);

  return true;
}

bool CCopasiParameterGroup::addGroup(const std::string & name)
{
  addParameter(new CCopasiParameterGroup(name));
  return true;
}

bool CCopasiParameterGroup::removeParameter(const std::string & name)
{
  unsigned C_INT32 index = getIndex(name);

  if (index != C_INVALID_INDEX)
    {
      index_iterator it =
        ((parameterGroup *) mpValue)->begin() + index;

      pdelete(*it);
      ((parameterGroup *) mpValue)->erase(it, it + 1);

      return true;
    }

  return false;
}

bool CCopasiParameterGroup::removeParameter(const unsigned C_INT32 & index)
{
  if (index < size())
    {
      index_iterator it =
        ((parameterGroup *) mpValue)->begin() + index;

      pdelete(*it);
      ((parameterGroup *) mpValue)->erase(it, it + 1);

      return true;
    }

  return false;
}

CCopasiParameter * CCopasiParameterGroup::getParameter(const std::string & name)
{
  std::pair < CCopasiContainer::objectMap::const_iterator,
  CCopasiContainer::objectMap::const_iterator > range =
{'fraction_non_alphanumeric': 0.12789180211175702, 'fraction_numerical': 0.006169177838414996, 'mean_word_length': 4.813793103448276, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 43, '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': '2967435', 'n_tokens_mistral': 2670, 'n_tokens_neox': 2573, 'n_words': 551}