COPASI API  4.16.103
Public Member Functions | Private Attributes | List of all members
CFunctionDB Class Reference

#include <CFunctionDB.h>

Inheritance diagram for CFunctionDB:
Inheritance graph
[legend]
Collaboration diagram for CFunctionDB:
Collaboration graph
[legend]

Public Member Functions

bool add (CFunction *pFunction, const bool &adopt)
 
CFunctionaddAndAdaptName (CFunction *pFunction)
 
bool appendDependentFunctions (std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependentFunctions) const
 
 CFunctionDB (const std::string &name, const CCopasiContainer *pParent)
 
void cleanup ()
 
CFunctionfindFunction (const std::string &functionName)
 
CFunctionfindLoadFunction (const std::string &functionName)
 
std::string getFilename () const
 
std::vector< CFunction * > getUsedFunctions (const CModel *pModel) const
 
void initObjects ()
 
std::set< std::string > listDependentTrees (const std::string &name) const
 
bool load ()
 
bool load (const std::string &fileName)
 
C_INT32 load (CReadConfig &configbuffer)
 
CCopasiVectorN< CFunction > & loadedFunctions ()
 
bool removeFunction (size_t index)
 
bool removeFunction (const std::string &key)
 
bool save (const std::string &fileName)
 
void setFilename (const std::string &filename)
 
std::vector< CFunction * > suitableFunctions (const size_t noSubstrates, const size_t noProducts, const TriLogic reversibility)
 
virtual ~CFunctionDB ()
 
- Public Member Functions inherited from CCopasiContainer
virtual bool add (CCopasiObject *pObject, const bool &adopt=true)
 
 CCopasiContainer (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=CCopasiObject::Container)
 
 CCopasiContainer (const CCopasiContainer &src, const CCopasiContainer *pParent=NULL)
 
virtual std::string getChildObjectUnits (const CCopasiObject *pObject) const
 
virtual const CObjectInterfacegetObject (const CCopasiObjectName &cn) const
 
virtual const objectMapgetObjects () const
 
virtual std::string getUnits () const
 
virtual const CCopasiObjectgetValueObject () const
 
virtual bool remove (CCopasiObject *pObject)
 
virtual ~CCopasiContainer ()
 
- Public Member Functions inherited from CCopasiObject
void addDirectDependency (const CCopasiObject *pObject)
 
 CCopasiObject (const CCopasiObject &src, const CCopasiContainer *pParent=NULL)
 
void clearDirectDependencies ()
 
void clearRefresh ()
 
bool dependsOn (DataObjectSet candidates, const DataObjectSet &context=DataObjectSet()) const
 
void getAllDependencies (DataObjectSet &dependencies, const DataObjectSet &context) const
 
virtual CCopasiObjectName getCN () const
 
virtual const DataObjectSetgetDirectDependencies (const DataObjectSet &context=DataObjectSet()) const
 
virtual const std::string & getKey () const
 
CCopasiContainergetObjectAncestor (const std::string &type) const
 
CCopasiDataModelgetObjectDataModel ()
 
const CCopasiDataModelgetObjectDataModel () const
 
virtual std::string getObjectDisplayName (bool regular=true, bool richtext=false) const
 
const std::string & getObjectName () const
 
CCopasiContainergetObjectParent () const
 
const std::string & getObjectType () const
 
virtual const
CObjectInterface::ObjectSet
getPrerequisites () const
 
virtual RefreshgetRefresh () const
 
UpdateMethodgetUpdateMethod () const
 
virtual voidgetValuePointer () const
 
bool hasCircularDependencies (DataObjectSet &candidates, DataObjectSet &verified, const DataObjectSet &context) const
 
bool hasUpdateMethod () const
 
bool isArray () const
 
bool isContainer () const
 
bool isDataModel () const
 
bool isMatrix () const
 
bool isNameVector () const
 
bool isNonUniqueName () const
 
virtual bool isPrerequisiteForContext (const CObjectInterface *pObject, const CMath::SimulationContextFlag &context, const CObjectInterface::ObjectSet &changedObjects) const
 
bool isReference () const
 
bool isRoot () const
 
bool isSeparator () const
 
bool isStaticString () const
 
bool isValueBool () const
 
bool isValueDbl () const
 
bool isValueInt () const
 
bool isValueInt64 () const
 
bool isValueString () const
 
bool isVector () const
 
virtual bool mustBeDeleted (const DataObjectSet &deletedObjects) const
 
virtual void print (std::ostream *ostream) const
 
void removeDirectDependency (const CCopasiObject *pObject)
 
void setDirectDependencies (const DataObjectSet &directDependencies)
 
bool setObjectName (const std::string &name)
 
virtual bool setObjectParent (const CCopasiContainer *pParent)
 
void setObjectValue (const C_FLOAT64 &value)
 
void setObjectValue (const C_INT32 &value)
 
void setObjectValue (const bool &value)
 
template<class CType >
void setRefresh (CType *pType, void(CType::*method)(void))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_FLOAT64 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_INT32 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const bool &))
 
virtual ~CCopasiObject ()
 
- Public Member Functions inherited from CObjectInterface
 CObjectInterface ()
 
virtual ~CObjectInterface ()
 

Private Attributes

std::string mFilename
 
CCopasiVectorN< CFunctionmLoadedFunctions
 

Additional Inherited Members

- Public Types inherited from CCopasiContainer
typedef std::multimap
< std::string, CCopasiObject * > 
objectMap
 
- Public Types inherited from CCopasiObject
typedef std::set< const
CCopasiObject * > 
DataObjectSet
 
typedef std::vector< Refresh * > DataUpdateSequence
 
- Public Types inherited from CObjectInterface
typedef std::set< const
CObjectInterface * > 
ObjectSet
 
typedef std::vector
< CObjectInterface * > 
UpdateSequence
 
- Static Public Member Functions inherited from CCopasiObject
static std::vector< Refresh * > buildUpdateSequence (const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
 
static void setRenameHandler (CRenameHandler *rh)
 
- Static Public Attributes inherited from CCopasiContainer
static const std::vector
< CCopasiContainer * > 
EmptyList
 
- Protected Types inherited from CCopasiObject
enum  Flag {
  Container = 0x1, Vector = 0x2, Matrix = 0x4, NameVector = 0x8,
  Reference = 0x10, ValueBool = 0x20, ValueInt = 0x40, ValueInt64 = 0x80,
  ValueDbl = 0x100, NonUniqueName = 0x200, StaticString = 0x400, ValueString = 0x800,
  Separator = 0x1000, ModelEntity = 0x2000, Array = 0x4000, DataModel = 0x8000,
  Root = 0x10000, Gui = 0x20000
}
 
- Protected Member Functions inherited from CCopasiContainer
template<class CType >
CCopasiObjectaddMatrixReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddObjectReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddVectorReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
void initObjects ()
 
- Protected Member Functions inherited from CCopasiObject
 CCopasiObject ()
 
 CCopasiObject (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=0)
 
- Protected Attributes inherited from CCopasiContainer
objectMap mObjects
 
- Static Protected Attributes inherited from CCopasiObject
static CRenameHandlersmpRenameHandler = NULL
 

Detailed Description

Definition at line 35 of file CFunctionDB.h.

Constructor & Destructor Documentation

CFunctionDB::CFunctionDB ( const std::string &  name,
const CCopasiContainer pParent 
)

Default constructor

Parameters
conststd::string & name (default: "NoName")
constCCopasiContainer * pParent (default: NULL)

CFunctionDB

Created for Copasi by Stefan Hoops (C) Stefan Hoops 2001

Definition at line 36 of file CFunctionDB.cpp.

References CONSTRUCTOR_TRACE, and initObjects().

37  :
38  CCopasiContainer(name, pParent, "FunctionDB"),
39  mFilename(),
40  mLoadedFunctions("Functions", this)
41 {
42  initObjects();
44 }
std::string mFilename
Definition: CFunctionDB.h:42
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
void initObjects()
Definition: CFunctionDB.cpp:54
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202
CFunctionDB::~CFunctionDB ( )
virtual

Destructor

Definition at line 46 of file CFunctionDB.cpp.

References cleanup(), and DESTRUCTOR_TRACE.

47 {
48  cleanup();
50 }
void cleanup()
Definition: CFunctionDB.cpp:52
#define DESTRUCTOR_TRACE
Definition: copasi.h:206

Member Function Documentation

bool CFunctionDB::add ( CFunction pFunction,
const bool &  adopt 
)

Add the function to the database

Parameters
CFunction* pFunction
constbool & adopt (default = false)
Returns
bool success

Definition at line 254 of file CFunctionDB.cpp.

References CCopasiVectorN< CType >::add(), and mLoadedFunctions.

Referenced by addAndAdaptName(), SBMLImporter::createCFunctionFromFunctionDefinition(), SBMLImporter::createCReactionFromReaction(), CQFunctionDM::insertRows(), CReaction::setFunctionFromExpressionTree(), FunctionWidget1::slotBtnNew(), and ReactionsWidget1::slotNewFunction().

256 {return mLoadedFunctions.add(pFunction, adopt);}
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
virtual bool add(const CType &src)
CFunction * CFunctionDB::addAndAdaptName ( CFunction pFunction)

Add the function to the database, if necessary adapt the name so it is unique.

Definition at line 258 of file CFunctionDB.cpp.

References add(), C_INVALID_INDEX, CCopasiVectorN< CType >::getIndex(), CCopasiObject::getObjectName(), mLoadedFunctions, pdelete, and CCopasiObject::setObjectName().

Referenced by CModel::convert2NonReversible(), test000058::test_bug1025_10(), test000058::test_bug1025_5(), test000059::test_unique_id_17(), test000059::test_unique_id_18(), test000059::test_unique_id_19(), test000059::test_unique_id_20(), test000059::test_unique_id_21(), and test000059::test_unique_id_21_2().

259 {
260  if (!pFunction) return NULL;
261 
262  std::string basename = pFunction->getObjectName();
263  std::string name = basename;
264  //CFunction* pFunc;
265  //CCopasiVectorN<CEvaluationTree>& FunctionList
266  //= this->loadedFunctions();
267  int i = 0;
268 
269  size_t Index = C_INVALID_INDEX;
270 
271  while ((Index = mLoadedFunctions.getIndex(name)) != C_INVALID_INDEX)
272  {
273  // Check whether the new functions and the old are the same.
274  if (*mLoadedFunctions[Index] == *pFunction)
275  {
276  pdelete(pFunction);
277  return mLoadedFunctions[Index];
278  }
279 
280  i++;
281  std::ostringstream ss; ss << "[" << i << "]";
282  name = basename + ss.str();
283  }
284 
285  pFunction->setObjectName(name);
286  this->add(pFunction, true);
287 
288  return pFunction;
289 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
#define pdelete(p)
Definition: copasi.h:215
const std::string & getObjectName() const
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
bool setObjectName(const std::string &name)
bool add(CFunction *pFunction, const bool &adopt)
bool CFunctionDB::appendDependentFunctions ( std::set< const CCopasiObject * >  candidates,
std::set< const CCopasiObject * > &  dependentFunctions 
) const

Appends pointers to function, which are dependent on any of the candidates to the list dependentFunctions.

Parameters
std::set<const CCopasiObject * > candidates
std::set<const CCopasiObject * > & dependentFunctions
Returns
bool functionsAppended

Definition at line 396 of file CFunctionDB.cpp.

References CCopasiVector< T >::begin(), CCopasiVector< T >::end(), and mLoadedFunctions.

Referenced by CQMessageBox::confirmDelete(), and FunctionWidget1::leave().

398 {
399  size_t Size = dependentFunctions.size();
400  CCallParameters< C_FLOAT64 > CallParmeters;
401 
404 
405  for (; it != end; ++it)
406  if (candidates.find(*it) == candidates.end() &&
407  (*it)->CEvaluationTree::dependsOn(candidates))
408  dependentFunctions.insert((*it));
409 
410  return Size < dependentFunctions.size();
411 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
iterator begin()
iterator end()
void CFunctionDB::cleanup ( )

Definition at line 52 of file CFunctionDB.cpp.

References CCopasiVector< T >::cleanup(), and mLoadedFunctions.

Referenced by ~CFunctionDB().

CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
virtual void cleanup()
CFunction * CFunctionDB::findFunction ( const std::string &  functionName)

Delete the function functionName from the database

Parameters
const string&functionName
Returns
C_INT32 Fail Search for a function among the loaded functions. If no function is found NULL is returned
Parameters
const string&functionName
Returns
CFunction *

Definition at line 325 of file CFunctionDB.cpp.

References C_INVALID_INDEX, CCopasiVectorN< CType >::getIndex(), and mLoadedFunctions.

Referenced by CEvaluationNodeCall::calls(), CEvaluationNodeCall::compile(), SBMLImporter::createCFunctionFromFunctionDefinition(), SBMLImporter::createCReactionFromReaction(), CSBMLExporter::createFunctionSetFromFunctionNames(), expand_function_call(), CODEExporterC::exportSingleFunction(), CODEExporter::exportSingleFunction(), SBMLImporter::findCorrespondingFunction(), SBMLImporter::findFunctionCalls(), CODEExporter::findFunctionsCalls(), CEvaluationNodeCall::getCalledTree(), SBMLImporter::isConstantFlux(), CODEExporter::modifyTreeForMassAction(), SBMLImporter::restoreFunctionDB(), CODEExporterC::setExportNameOfFunction(), CReaction::setFunctionFromExpressionTree(), CSBMLExporter::setFunctionSBMLIds(), suitableFunctions(), test000067::test_bug1060(), test_compare_utilities::test_copasi_function_expansion(), and CEvaluationNodeCall::toAST().

326 {
327  size_t index = mLoadedFunctions.getIndex(functionName);
328 
329  if (index != C_INVALID_INDEX)
330  return mLoadedFunctions[index];
331  else
332  return NULL;
333 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
CFunction * CFunctionDB::findLoadFunction ( const std::string &  functionName)

Search for a function among the loaded functions. If no function is found the database is searched and the apropriate function is loaded.

Parameters
const string&functionName
Returns
CFunction * function (NULL if function is not found)

Definition at line 335 of file CFunctionDB.cpp.

References CCopasiObject::getObjectName(), mLoadedFunctions, and CCopasiVector< T >::size().

Referenced by CReaction::setFunction(), CReactionInterface::setFunctionAndDoMapping(), and CReactionInterface::setFunctionWithEmptyMapping().

336 {
337  size_t i;
338 
339  for (i = 0; i < mLoadedFunctions.size(); i++)
340  if (functionName == mLoadedFunctions[i]->getObjectName())
341  return mLoadedFunctions[i];
342 
343  return NULL;
344 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
const std::string & getObjectName() const
virtual size_t size() const
std::string CFunctionDB::getFilename ( ) const

Definition at line 156 of file CFunctionDB.cpp.

References mFilename.

157 {return mFilename;}
std::string mFilename
Definition: CFunctionDB.h:42
std::vector< CFunction * > CFunctionDB::getUsedFunctions ( const CModel pModel) const

Retrieves a list of all functions used in the model

Returns
std::vector< CEvaluationTree * > usedFunctions

Definition at line 428 of file CFunctionDB.cpp.

References CModel::appendDependentModelObjects(), CCopasiVector< T >::begin(), CFunction::completeFunctionList(), CCopasiVector< T >::end(), and mLoadedFunctions.

Referenced by CCopasiXML::buildFunctionList().

429 {
430  std::vector< CFunction * > UsedFunctions;
433 
434  for (; it != end; ++it)
435  {
436  std::set< const CCopasiObject * > Function;
437  Function.insert(*it);
438 
439  std::set< const CCopasiObject * > Reactions;
440  std::set< const CCopasiObject * > Metabolites;
441  std::set< const CCopasiObject * > Values;
442  std::set< const CCopasiObject * > Compartments;
443  std::set< const CCopasiObject * > Events;
444 
445  pModel->appendDependentModelObjects(Function,
446  Reactions, Metabolites, Compartments, Values, Events);
447 
448  if (Reactions.size() != 0)
449  {
450  UsedFunctions.push_back(*it);
451  continue;
452  }
453 
454  if (Metabolites.size() != 0)
455  {
456  UsedFunctions.push_back(*it);
457  continue;
458  }
459 
460  if (Values.size() != 0)
461  {
462  UsedFunctions.push_back(*it);
463  continue;
464  }
465 
466  if (Compartments.size() != 0)
467  {
468  UsedFunctions.push_back(*it);
469  continue;
470  }
471 
472  if (Events.size() != 0)
473  {
474  UsedFunctions.push_back(*it);
475  continue;
476  }
477  }
478 
479  CFunction::completeFunctionList(UsedFunctions);
480 
481  return UsedFunctions;
482 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
static bool completeFunctionList(std::vector< CFunction * > &list, const size_t &added=0)
Definition: CFunction.cpp:303
iterator begin()
iterator end()
bool appendDependentModelObjects(const std::set< const CCopasiObject * > &candidates, std::set< const CCopasiObject * > &dependentReactions, std::set< const CCopasiObject * > &dependentMetabolites, std::set< const CCopasiObject * > &dependentCompartments, std::set< const CCopasiObject * > &dependentModelValues, std::set< const CCopasiObject * > &dependentEvents) const
Definition: CModel.cpp:2364
void CFunctionDB::initObjects ( )

Definition at line 54 of file CFunctionDB.cpp.

References CCopasiContainer::addObjectReference(), and mFilename.

Referenced by CFunctionDB().

55 {
57 }
std::string mFilename
Definition: CFunctionDB.h:42
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
std::set< std::string > CFunctionDB::listDependentTrees ( const std::string &  name) const

Retrieve a list of evaluation trees depending on the tree with the given name.

Parameters
conststd::string & name
Returns
std::set<std::string> list

Definition at line 414 of file CFunctionDB.cpp.

References CCopasiVector< T >::begin(), CCopasiVector< T >::end(), and mLoadedFunctions.

415 {
416  std::set<std::string> List;
417 
420 
421  for (; it != end; ++it)
422  if ((*it)->dependsOnTree(name))
423  List.insert((*it)->getObjectName());
424 
425  return List;
426 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
iterator begin()
iterator end()
bool CFunctionDB::load ( )

Definition at line 59 of file CFunctionDB.cpp.

References FunctionDBxml, CCopasiXML::load(), mLoadedFunctions, and CCopasiXML::setFunctionList().

Referenced by CCopasiRootContainer::initializeChildren(), and DataModelGUI::loadFunctionDB().

60 {
61  CCopasiXML XML;
63 
64  std::stringstream DB;
65  DB.str(FunctionDBxml);
66 
67  if (DB.fail())
68  return false;
69 
70  if (!XML.load(DB, ""))
71  return false;
72 
73  return true;
74 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
bool setFunctionList(CCopasiVectorN< CFunction > *pFunctionList)
Definition: CCopasiXML.cpp:270
virtual bool load(std::istream &is, const std::string &pwd)
Definition: CCopasiXML.cpp:169
static char FunctionDBxml[]
bool CFunctionDB::load ( const std::string &  fileName)

Definition at line 76 of file CFunctionDB.cpp.

References CCopasiXML::load(), mLoadedFunctions, and CCopasiXML::setFunctionList().

77 {
78  CCopasiXML XML;
80  std::fstream str(fileName.c_str());
81 
82  if (str.fail())
83  return false;
84 
85  if (!XML.load(str, ""))
86  return false;
87 
88  return true;
89 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
bool setFunctionList(CCopasiVectorN< CFunction > *pFunctionList)
Definition: CCopasiXML.cpp:270
virtual bool load(std::istream &is, const std::string &pwd)
Definition: CCopasiXML.cpp:169
C_INT32 CFunctionDB::load ( CReadConfig configbuffer)

Loads an object with data coming from a CReadConfig object. (CReadConfig object reads an input stream)

Parameters
pconfigbufferreference to a CReadConfig object.
Returns
mFail

Definition at line 98 of file CFunctionDB.cpp.

References CCopasiVectorN< CType >::add(), C_INT32, CEvaluationTree::compile(), fatalError, CEvaluationTree::Function, CCopasiMessage::getLastMessage(), CEvaluationTree::getType(), CReadConfig::getVariable(), CFunction::load(), CReadConfig::LOOP, CEvaluationTree::MassAction, MCCopasiVector, mLoadedFunctions, pdelete, CCopasiMessage::peekLastMessage(), CEvaluationTree::PreDefined, and CEvaluationTree::UserDefined.

99 {
100  CFunction Function;
101  CFunction * pFunction = NULL;
102 
103  C_INT32 Size = 0;
104  C_INT32 Fail = 0;
105 
106  configbuffer.getVariable("TotalUDKinetics", "C_INT32", &Size,
108 
109  for (C_INT32 i = 0; i < Size; i++)
110  {
111  Function.load(configbuffer);
112 
113  switch (Function.getType())
114  {
116  pFunction = new CFunction(Function);
117  break;
118 
120  pFunction = new CMassAction(Function);
121  break;
122 
125  pFunction = new CKinFunction(Function,
126  &configbuffer);
127  break;
128 
129  default:
130  fatalError();
131  break;
132  }
133 
134  pFunction->compile();
135 
136  if (!mLoadedFunctions.add(pFunction, true))
137  {
138  pdelete(pFunction);
139 
140  // We ignore:
141  // CCopasiVector (2): Object '%s' allready exists.
142  if ((MCCopasiVector + 2) != CCopasiMessage::peekLastMessage().getNumber())
143  return Fail = 1;
144 
145  // Remove the ignored meesage.
147  }
148  }
149 
150  return Fail;
151 }
static const CCopasiMessage & peekLastMessage()
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
#define pdelete(p)
Definition: copasi.h:215
#define fatalError()
const CEvaluationTree::Type & getType() const
#define C_INT32
Definition: copasi.h:90
virtual bool add(const CType &src)
virtual void load(CReadConfig &configBuffer, CReadConfig::Mode mode=CReadConfig::SEARCH)
Definition: CFunction.cpp:182
static CCopasiMessage getLastMessage()
virtual bool compile()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
C_INT32 getVariable(const std::string &name, const std::string &type, void *pout, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CReadConfig.cpp:81
#define MCCopasiVector
CCopasiVectorN< CFunction > & CFunctionDB::loadedFunctions ( )
bool CFunctionDB::removeFunction ( size_t  index)

Definition at line 291 of file CFunctionDB.cpp.

References CCopasiVector< T >::begin(), C_INVALID_INDEX, CCopasiVector< T >::end(), CCopasiRootContainer::getDatamodelList(), and mLoadedFunctions.

Referenced by removeFunction(), CQFunctionDM::removeRows(), SBMLImporter::restoreFunctionDB(), and FunctionWidget1::slotBtnDelete().

292 {
293  if (index == C_INVALID_INDEX) return false;
294 
295  // We need to delete all dependent objects in all data models.
298 
299  std::set< const CCopasiObject * > DeletedObjects = mLoadedFunctions[index]->getDeletedObjects();
300 
301  for (; it != end; ++it)
302  {
303  (*it)->getModel()->removeDependentModelObjects(DeletedObjects);
304  }
305 
306  mLoadedFunctions.CCopasiVector<CFunction>::remove(index);
307 
308  return true;
309 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
iterator begin()
#define C_INVALID_INDEX
Definition: copasi.h:222
iterator end()
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
bool CFunctionDB::removeFunction ( const std::string &  key)

Definition at line 311 of file CFunctionDB.cpp.

References C_INVALID_INDEX, CKeyFactory::get(), CCopasiRootContainer::getKeyFactory(), mLoadedFunctions, and removeFunction().

312 {
313  CEvaluationTree* func = dynamic_cast< CEvaluationTree * >(CCopasiRootContainer::getKeyFactory()->get(key));
314 
315  if (!func) return false;
316 
317  size_t index =
318  mLoadedFunctions.CCopasiVector<CFunction>::getIndex(func);
319 
320  if (index == C_INVALID_INDEX) return false;
321 
322  return removeFunction(index);
323 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
CCopasiObject * get(const std::string &key)
#define C_INVALID_INDEX
Definition: copasi.h:222
static CKeyFactory * getKeyFactory()
bool removeFunction(size_t index)
bool CFunctionDB::save ( const std::string &  fileName)

Definition at line 91 of file CFunctionDB.cpp.

References mLoadedFunctions, and CCopasiXML::setFunctionList().

Referenced by DataModelGUI::saveFunctionDB().

92 {
93  CCopasiXML XML;
95  return XML.CCopasiXMLInterface::save(fileName, fileName);
96 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
bool setFunctionList(CCopasiVectorN< CFunction > *pFunctionList)
Definition: CCopasiXML.cpp:270
void CFunctionDB::setFilename ( const std::string &  filename)

Definition at line 153 of file CFunctionDB.cpp.

References mFilename.

154 {mFilename = filename;}
std::string mFilename
Definition: CFunctionDB.h:42
std::vector< CFunction * > CFunctionDB::suitableFunctions ( const size_t  noSubstrates,
const size_t  noProducts,
const TriLogic  reversibility 
)

Retrieves the vector of functions that are suitable for a number of substrates, products and reversibility status. Note: The returns CCopasiVector has to be deleted after use!

Parameters
const size_tnoSubstrates the number of substrates
const size_tnoProducts the number of products
const TriLogicreversible the reversibility status
Returns
"std::vector<CFunction*> " suitableFunctions

Definition at line 350 of file CFunctionDB.cpp.

References fatalError, findFunction(), CFunction::isSuitable(), mLoadedFunctions, CCopasiVector< T >::size(), and TriTrue.

Referenced by SBMLImporter::findCorrespondingFunction(), and CReactionInterface::getListOfPossibleFunctions().

353 {
354  std::vector<CFunction*> ret;
355  CFunction *pFunction;
356 
357  size_t i, imax = mLoadedFunctions.size();
358 
359  for (i = 0; i < imax; i++)
360  {
361  pFunction = dynamic_cast<CFunction *>(mLoadedFunctions[i]);
362 
363  if (!pFunction) continue;
364 
365  if (pFunction->isSuitable(noSubstrates, noProducts, reversibility))
366  ret.push_back(pFunction);
367  }
368 
369  //always add constant flux it is is missing
370  if (reversibility == TriTrue)
371  {
372  if ((noSubstrates > 0) || (noProducts > 0)) //constant flux was not yet added
373  {
374  pFunction = dynamic_cast<CFunction*>(findFunction("Constant flux (reversible)"));
375 
376  if (!pFunction) fatalError();
377 
378  ret.push_back(pFunction);
379  }
380  }
381  else //irreversible
382  {
383  if (noSubstrates > 0) //constant flux was not yet added
384  {
385  pFunction = dynamic_cast<CFunction*>(findFunction("Constant flux (irreversible)"));
386 
387  if (!pFunction) fatalError();
388 
389  ret.push_back(pFunction);
390  }
391  }
392 
393  return ret;
394 }
CCopasiVectorN< CFunction > mLoadedFunctions
Definition: CFunctionDB.h:47
virtual size_t size() const
#define fatalError()
bool isSuitable(const size_t noSubstrates, const size_t noProducts, const TriLogic reversible)
Definition: CFunction.cpp:254
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
CFunction * findFunction(const std::string &functionName)

Member Data Documentation

std::string CFunctionDB::mFilename
private

Filename which contains the function database

Definition at line 42 of file CFunctionDB.h.

Referenced by getFilename(), initObjects(), and setFilename().

CCopasiVectorN< CFunction > CFunctionDB::mLoadedFunctions
private

The documentation for this class was generated from the following files: