COPASI API  4.16.103
Classes | Functions
CCopasiParameterGroup.h File Reference
#include <string>
#include <vector>
#include "copasi/utilities/CCopasiParameter.h"
#include "copasi/utilities/CCopasiMessage.h"
Include dependency graph for CCopasiParameterGroup.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CCopasiParameterGroup
 

Functions

template<typename ElevateTo , typename ElevateFrom >
ElevateTo * elevate (CCopasiParameter *pParm)
 

Function Documentation

template<typename ElevateTo , typename ElevateFrom >
ElevateTo* elevate ( CCopasiParameter pParm)

Elevate a CCopasiParameter pointer to ElevateTo. If pParm is NULL, not of type ElevateFrom, or the elevation fails a NULL pointer is returned. If the elevation is success full the parameter *pParm is replaced with the elevated object.

Parameters
CCopasiParameter* pParm
Returns
ElevateTo * pTo

Definition at line 480 of file CCopasiParameterGroup.h.

References CCopasiMessage::ERROR, CCopasiObject::getObjectParent(), and MCParameter.

481 {
482  if (!pParm)
483  {
485  return NULL;
486  }
487 
488  ElevateFrom * pFrom = dynamic_cast<ElevateFrom *>(pParm);
489 
490  if (!pFrom)
491  {
493  return NULL;
494  }
495 
496  // Even if the pParm is already of the desired type we still
497  // recreate it to assure that we have proper construction.
498  ElevateTo * pTo = NULL;
499 
500  CCopasiParameterGroup * pGrp =
501  dynamic_cast<CCopasiParameterGroup *>(pParm->getObjectParent());
502 
503  if (pGrp)
504  {
505  std::vector< CCopasiParameter * >::iterator it =
506  pGrp->CCopasiParameter::getValue().pGROUP->begin();
507  std::vector< CCopasiParameter * >::iterator end =
508  pGrp->CCopasiParameter::getValue().pGROUP->end();
509 
510  while (it != end && *it != pParm) ++it;
511 
512  if (it == end)
513  {
515  return NULL;
516  }
517 
518  pTo = new ElevateTo(*pFrom);
519  delete pParm;
520 
521  pGrp->CCopasiContainer::add(pTo, true);
522  *it = pTo;
523  }
524  else
525  pTo = new ElevateTo(*pFrom);
526 
527  return pTo;
528 }
#define MCParameter
CCopasiContainer * getObjectParent() const