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

#include "copasi.h"

#include "CMathDependencyNode.h"
#include "CMathObject.h"
#include "CMathDependencyNodeIterator.h"
#include "CMathContainer.h"

#include "model/CMetab.h"

CMathDependencyNode::CMathDependencyNode():
  mpObject(NULL),
  mPrerequisites(),
  mDependents(),
  mChanged(false),
  mRequested(false)
{}

CMathDependencyNode::CMathDependencyNode(const CObjectInterface * pObject):
  mpObject(pObject),
  mPrerequisites(),
  mDependents(),
  mChanged(false),
  mRequested(false)
{}

CMathDependencyNode::CMathDependencyNode(const CMathDependencyNode & src):
  mpObject(src.mpObject),
  mPrerequisites(src.mPrerequisites),
  mDependents(src.mDependents),
  mChanged(src.mChanged),
  mRequested(src.mRequested)
{}

CMathDependencyNode::~CMathDependencyNode()
{}

const CObjectInterface * CMathDependencyNode::getObject() const
{
  return mpObject;
}

void CMathDependencyNode::addPrerequisite(CMathDependencyNode * pObject)
{
  mPrerequisites.push_back(pObject);
}

void CMathDependencyNode::removePrerequisite(CMathDependencyNode * pNode)
{
  std::vector< CMathDependencyNode * >::iterator it = mPrerequisites.begin();
  std::vector< CMathDependencyNode * >::iterator end = mPrerequisites.end();

  for (; it != end;)
    {
      if (*it == pNode)
        {
          it = mPrerequisites.erase(it);
          end = mPrerequisites.end();
        }
      else
        {
          ++it;
        }
    }
}

std::vector< CMathDependencyNode * > & CMathDependencyNode::getPrerequisites()
{
  return mPrerequisites;
}

void CMathDependencyNode::addDependent(CMathDependencyNode * pNode)
{
  mDependents.push_back(pNode);
}

void CMathDependencyNode::removeDependent(CMathDependencyNode * pNode)
{
  std::vector< CMathDependencyNode * >::iterator it = mDependents.begin();
  std::vector< CMathDependencyNode * >::iterator end = mDependents.end();

  for (; it != end;)
    {

      if (*it == pNode)
        {
          it = mDependents.erase(it);
          end = mDependents.end();
        }
      else
        {
          ++it;
        }
    }
}

std::vector< CMathDependencyNode * > & CMathDependencyNode::getDependents()
{
  return mDependents;
}

bool CMathDependencyNode::updateDependentState(const CMath::SimulationContextFlag & context,
    const CObjectInterface::ObjectSet & changedObjects)
{
  CMathDependencyNodeIterator itNode(this, CMathDependencyNodeIterator::Dependents);
  itNode.setProcessingModes(CMathDependencyNodeIterator::Before);

  while (itNode.next())
    {
      // If we have a recursive dependency we need make sure that this is due to
      // an intensive/extensive value pair
      if (itNode.state() == CMathDependencyNodeIterator::Recursive)
        {
          if (itNode->getObject()->isPrerequisiteForContext(itNode.parent()->getObject(), context, changedObjects))
            {
              return false;
            }

          continue;
        }
<commit_msg>Simpler and more understandable fix of the iterator issue.<commit_after>// Copyright (C) 2011 - 2016 by <NAME>, Virginia Tech Intellectual
// Properties, Inc., University of Heidelberg, and The University
// of Manchester.
// All rights reserved.

#include "copasi.h"

#include "CMathDependencyNode.h"
#include "CMathObject.h"
#include "CMathDependencyNodeIterator.h"
#include "CMathContainer.h"

#include "model/CMetab.h"

CMathDependencyNode::CMathDependencyNode():
  mpObject(NULL),
  mPrerequisites(),
  mDependents(),
  mChanged(false),
  mRequested(false)
{}

CMathDependencyNode::CMathDependencyNode(const CObjectInterface * pObject):
  mpObject(pObject),
  mPrerequisites(),
  mDependents(),
  mChanged(false),
  mRequested(false)
{}

CMathDependencyNode::CMathDependencyNode(const CMathDependencyNode & src):
  mpObject(src.mpObject),
  mPrerequisites(src.mPrerequisites),
  mDependents(src.mDependents),
  mChanged(src.mChanged),
  mRequested(src.mRequested)
{}

CMathDependencyNode::~CMathDependencyNode()
{}

const CObjectInterface * CMathDependencyNode::getObject() const
{
  return mpObject;
}

void CMathDependencyNode::addPrerequisite(CMathDependencyNode * pObject)
{
  mPrerequisites.push_back(pObject);
}

void CMathDependencyNode::removePrerequisite(CMathDependencyNode * pNode)
{
  std::vector< CMathDependencyNode * >::iterator it = mPrerequisites.begin();
  std::vector< CMathDependencyNode * >::iterator end = mPrerequisites.end();

  for (; it != end; ++it)
    if (*it == pNode)
      {
        mPrerequisites.erase(it);
        break;
      }
}

std::vector< CMathDependencyNode * > & CMathDependencyNode::getPrerequisites()
{
  return mPrerequisites;
}

void CMathDependencyNode::addDependent(CMathDependencyNode * pNode)
{
  mDependents.push_back(pNode);
}

void CMathDependencyNode::removeDependent(CMathDependencyNode * pNode)
{
  std::vector< CMathDependencyNode * >::iterator it = mDependents.begin();
  std::vector< CMathDependencyNode * >::iterator end = mDependents.end();

  for (; it != end; ++it)
    if (*it == pNode)
      {
        mDependents.erase(it);
        break;
      }
}

std::vector< CMathDependencyNode * > & CMathDependencyNode::getDependents()
{
  return mDependents;
}

bool CMathDependencyNode::updateDependentState(const CMath::SimulationContextFlag & context,
    const CObjectInterface::ObjectSet & changedObjects)
{
  CMathDependencyNodeIterator itNode(this, CMathDependencyNodeIterator::Dependents);
  itNode.setProcessingModes(CMathDependencyNodeIterator::Before);

  while (itNode.next())
    {
      // If we have a recursive dependency we need make sure that this is due to
      // an intensive/extensive value pair
      if (itNode.state() == CMathDependencyNodeIterator::Recursive)
        {
          if (itNode->getObject()->isPrerequisiteForContext(itNode.parent()->getObject(), context, changedObjects))
            {
              return false;
            }

          continue;
        }

{'fraction_non_alphanumeric': 0.1196567090278924, 'fraction_numerical': 0.0026406997854431426, 'mean_word_length': 4.201716738197425, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '4607556', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1854, 'n_words': 350}