COPASI API  4.16.103
Public Member Functions | Private Types | Private Attributes | List of all members
CCopasiXMLParser::FunctionElement Class Reference
Inheritance diagram for CCopasiXMLParser::FunctionElement:
Inheritance graph
[legend]
Collaboration diagram for CCopasiXMLParser::FunctionElement:
Collaboration graph
[legend]

Public Member Functions

virtual void end (const XML_Char *pszName)
 
 FunctionElement (CCopasiXMLParser &parser, SCopasiXMLParserCommon &common)
 
virtual void start (const XML_Char *pszName, const XML_Char **papszAttrs)
 
virtual ~FunctionElement ()
 
- Public Member Functions inherited from CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon >
 CXMLElementHandler (CCopasiXMLParser &parser, SCopasiXMLParserCommon &common)
 
virtual void end (const XML_Char *C_UNUSED(pszName))
 
virtual void reset ()
 
virtual void start (const XML_Char *C_UNUSED(pszName), const XML_Char **C_UNUSED(papszAttrs))
 
virtual ~CXMLElementHandler ()
 

Private Types

enum  Element {
  Function = 0, MiriamAnnotation, Comment, ListOfUnsupportedAnnotations,
  Expression, ListOfParameterDescriptions, MathML
}
 

Private Attributes

std::set< size_t > mExistingFunctionIndex
 
std::string mKey
 
ListOfParameterDescriptionsElementmpListOfParameterDescriptionsElement
 
MathMLElementmpMathMLElement
 

Additional Inherited Members

- Protected Member Functions inherited from CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon >
void addFix (const std::string &key, CCopasiObject *pObject)
 
void deleteCurrentHandler ()
 
- Protected Attributes inherited from CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon >
SCopasiXMLParserCommonmCommon
 
C_INT32 mCurrentElement
 
C_INT32 mLastKnownElement
 
CCopasiXMLParsermParser
 
CXMLElementHandlermpCurrentHandler
 

Detailed Description

Definition at line 3033 of file CCopasiXMLParser.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

CCopasiXMLParser::FunctionElement::FunctionElement ( CCopasiXMLParser parser,
SCopasiXMLParserCommon common 
)
CCopasiXMLParser::FunctionElement::~FunctionElement ( )
virtual

Destructor

Definition at line 764 of file CCopasiXMLParser.cpp.

References pdelete.

765 {
768 }
#define pdelete(p)
Definition: copasi.h:215
ListOfParameterDescriptionsElement * mpListOfParameterDescriptionsElement

Member Function Documentation

void CCopasiXMLParser::FunctionElement::end ( const XML_Char *  pszName)
virtual

End element handler

Parameters
constXML_Char *pszName

Definition at line 1011 of file CCopasiXMLParser.cpp.

References CCopasiVectorN< CType >::add(), SCopasiXMLParserCommon::CharacterData, CCopasiMessage::EXCEPTION, CFunction::getKey(), CAnnotation::getUnsupportedAnnotations(), CFunction::getVariables(), CCopasiXMLParser::mCommon, MCXML, SCopasiXMLParserCommon::mFunctionParameterKeyMap, CExpatTemplate< CExpat >::mParser, SCopasiXMLParserCommon::mpExpression, SCopasiXMLParserCommon::mPredefinedFunction, pdelete, SCopasiXMLParserCommon::pFunction, SCopasiXMLParserCommon::pFunctionList, CFunction::setInfix(), CExpression::setInfix(), CAnnotation::setMiriamAnnotation(), CAnnotation::setNotes(), START_ELEMENT, and UNKNOWN_ELEMENT.

1012 {
1013  switch (mCurrentElement)
1014  {
1015  case Function:
1016 
1017  if (strcmp(pszName, "Function"))
1019  pszName, "Function", mParser.getCurrentLineNumber());
1020 
1023 
1024  /* Tell the parent element we are done. */
1025  mParser.onEndElement(pszName);
1026 
1027  if (mCommon.pFunction != NULL)
1028  {
1030  {
1031  // TODOWe need to check whether any existing function with the same
1032  // name is identical
1033 
1034  std::set< size_t >::const_iterator it = mExistingFunctionIndex.begin();
1035  std::set< size_t >::const_iterator end = mExistingFunctionIndex.end();
1036 
1037  for (; it != end; ++it)
1038  {
1039  CFunction * pFunction = (*mCommon.pFunctionList)[*it];
1040 
1041  if (*pFunction == *mCommon.pFunction)
1042  {
1045 
1046  break;
1047  }
1048  }
1049 
1050  /* We have a new function and add it to the list */
1051  if (it == end)
1052  {
1054  }
1055  }
1056 
1058 
1059  std::map< size_t, std::string >::const_iterator it = mCommon.mFunctionParameterKeyMap.begin();
1060  std::map< size_t, std::string >::const_iterator end = mCommon.mFunctionParameterKeyMap.end();
1061 
1062  for (; it != end; ++it)
1063  {
1064  addFix(it->second, mCommon.pFunction->getVariables()[it->first]);
1065  }
1066  }
1067 
1068  break;
1069 
1070  case MiriamAnnotation:
1071 
1072  if (strcmp(pszName, "MiriamAnnotation"))
1074  pszName, "MiriamAnnotation", mParser.getCurrentLineNumber());
1075 
1076  if (mCommon.pFunction != NULL)
1077  {
1079  mCommon.CharacterData = "";
1080  }
1081 
1082  break;
1083 
1084  case Comment:
1085 
1086  if (strcmp(pszName, "Comment"))
1088  pszName, "Comment", mParser.getCurrentLineNumber());
1089 
1090  if (mCommon.pFunction != NULL)
1091  {
1093  mCommon.CharacterData = "";
1094  }
1095 
1096  break;
1097 
1099 
1100  if (strcmp(pszName, "ListOfUnsupportedAnnotations"))
1102  pszName, "ListOfUnsupportedAnnotations", mParser.getCurrentLineNumber());
1103 
1104  if (mCommon.pFunction != NULL)
1105  {
1107  }
1108 
1109  break;
1110 
1111  case Expression:
1112 
1113  if (strcmp(pszName, "Expression"))
1115  pszName, "Expression", mParser.getCurrentLineNumber());
1116 
1117  if (mCommon.pFunction != NULL)
1118  {
1120  {
1121  // do not yet compile the function as it might depend on elements not
1122  // read yet
1124  }
1125  }
1126  else if (mCommon.mpExpression != NULL)
1127  {
1129  }
1130 
1131  break;
1132 
1134 
1135  if (strcmp(pszName, "ListOfParameterDescriptions"))
1137  pszName, "ListOfParameterDescriptions", mParser.getCurrentLineNumber());
1138 
1139  break;
1140 
1141  case MathML:
1142 
1143  if (strcmp(pszName, "MathML"))
1145  pszName, "MathML", mParser.getCurrentLineNumber());
1146 
1147  if (mCommon.pFunction != NULL)
1148  {
1151  }
1152  else if (mCommon.mpExpression != NULL)
1153  {
1155  }
1156 
1157  // MathML is in place of Expression in old CopasiML files.
1158  mLastKnownElement = Expression;
1159  break;
1160 
1161  case UNKNOWN_ELEMENT:
1162  break;
1163 
1164  default:
1166  pszName, "???", mParser.getCurrentLineNumber());
1167  break;
1168  }
1169 
1171 
1172  return;
1173 }
CCopasiVectorN< CFunction > * pFunctionList
virtual bool setInfix(const std::string &infix)
Definition: CExpression.cpp:63
#define pdelete(p)
Definition: copasi.h:215
#define START_ELEMENT
void setNotes(const std::string &notes)
#define MCXML
const CAnnotation::UnsupportedAnnotation & getUnsupportedAnnotations() const
void setMiriamAnnotation(const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
virtual bool setInfix(const std::string &infix)
Definition: CFunction.cpp:73
const std::string & getKey() const
Definition: CFunction.cpp:58
virtual void onEndElement(const XML_Char *pszName)
std::map< size_t, std::string > mFunctionParameterKeyMap
void addFix(const std::string &key, CCopasiObject *pObject)
Definition: CXMLHandler.h:119
#define UNKNOWN_ELEMENT
virtual bool add(const CType &src)
virtual void end(const XML_Char *pszName)
ListOfUnsupportedAnnotationsElement mListOfUnsupportedAnnotationsElement
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
UnsupportedAnnotation & getUnsupportedAnnotations()
int getCurrentLineNumber() const
Definition: CExpat.h:470
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
void CCopasiXMLParser::FunctionElement::start ( const XML_Char *  pszName,
const XML_Char **  papszAttrs 
)
virtual

Start element handler

Parameters
constXML_Char *pszName
constXML_Char **papszAttrs

Definition at line 770 of file CCopasiXMLParser.cpp.

References C_INVALID_INDEX, CEvaluationTree::create(), CCopasiMessage::EXCEPTION, CEvaluationTree::Expression, CEvaluationTree::Function, CCopasiVectorN< CType >::getIndex(), CEvaluationTree::MassAction, CCopasiXMLParser::mCommon, MCXML, SCopasiXMLParserCommon::mFunctionParameterKeyMap, SCopasiXMLParserCommon::mKey2ObjectiveFunction, CExpatTemplate< CExpat >::mParser, SCopasiXMLParserCommon::mpExpression, SCopasiXMLParserCommon::mPredefinedFunction, pdelete, SCopasiXMLParserCommon::pFunction, SCopasiXMLParserCommon::pFunctionList, CEvaluationTree::PreDefined, CCopasiObject::setObjectName(), CFunction::setReversible(), toEnum(), TriFalse, TriTrue, TriUnspecified, UNKNOWN_ELEMENT, CEvaluationTree::UserDefined, and CEvaluationTree::XMLType.

772 {
773  const char * type;
775  const char * Name;
776  const char * Reversible;
777  size_t Index;
778 
779  mpCurrentHandler = NULL;
781 
782  while (mpCurrentHandler == NULL)
783  {
784  mCurrentElement++; /* We should always be on the next element */
785  CEvaluationTree* pEvaluationTree = NULL;
786 
787  switch (mCurrentElement)
788  {
789  case Function:
790 
791  if (strcmp(pszName, "Function"))
793  pszName, "Function", mParser.getCurrentLineNumber());
794 
795  mKey = mParser.getAttributeValue("key", papszAttrs);
796  Name = mParser.getAttributeValue("name", papszAttrs);
797  type = mParser.getAttributeValue("type", papszAttrs);
799 
800  Reversible = mParser.getAttributeValue("reversible", papszAttrs, false);
801 
802  if (!Reversible) // We may have an old file format using positive
803  Reversible = mParser.getAttributeValue("positive", papszAttrs, "unspecified");
804 
806 
809  mExistingFunctionIndex.clear();
810 
811  pEvaluationTree = CEvaluationTree::create(Type);
812 
813  if (Type == CEvaluationTree::Expression)
814  {
815  mCommon.pFunction = NULL;
816 
817  mCommon.mpExpression = static_cast< CExpression * >(pEvaluationTree);
819  }
820  else
821  {
822  mCommon.mpExpression = NULL;
823 
824  mCommon.pFunction = static_cast<CFunction *>(pEvaluationTree);
826 
827  if (!strcmp(Reversible, "true"))
829  else if (!strcmp(Reversible, "false"))
831  else
833 
834  Index = mCommon.pFunctionList->getIndex(Name);
835 
836  if (Index != C_INVALID_INDEX) // A function with that name exists.
837  {
838  mExistingFunctionIndex.insert(Index);
839 
840  switch ((*mCommon.pFunctionList)[Index]->getType())
841  {
843 
844  if (Type == CEvaluationTree::MassAction)
845  {
849  }
850  else
851  {
852  size_t Counter = 0;
853  std::string NewName;
854 
855  while (true)
856  {
857  Counter++;
858  std::ostringstream ss;
859  ss << Name << " [" << Counter << "]";
860  NewName = ss.str();
861  Index = mCommon.pFunctionList->getIndex(NewName);
862 
863  if (Index == C_INVALID_INDEX)
864  break;
865 
866  mExistingFunctionIndex.insert(Index);
867  }
868 
869  mCommon.pFunction->setObjectName(NewName);
870  }
871 
872  break;
873 
875 
876  if (Type == CEvaluationTree::PreDefined)
877  {
881  }
882  else
883  {
884  size_t Counter = 0;
885  std::string NewName;
886 
887  while (true)
888  {
889  Counter++;
890  std::ostringstream ss;
891  ss << Name << " [" << Counter << "]";
892  NewName = ss.str();
893  Index = mCommon.pFunctionList->getIndex(NewName);
894 
895  if (Index == C_INVALID_INDEX)
896  break;
897 
898  mExistingFunctionIndex.insert(Index);
899  }
900 
901  mCommon.pFunction->setObjectName(NewName);
902  }
903 
904  break;
905 
908  // Create a unique name
909  {
910  size_t Counter = 0;
911  std::string NewName;
912 
913  while (true)
914  {
915  Counter++;
916  std::ostringstream ss;
917  ss << Name << " [" << Counter << "]";
918  NewName = ss.str();
919  Index = mCommon.pFunctionList->getIndex(NewName);
920 
921  if (Index == C_INVALID_INDEX)
922  break;
923 
924  mExistingFunctionIndex.insert(Index);
925  }
926 
927  mCommon.pFunction->setObjectName(NewName);
928  }
929 
930  break;
931 
932  default:
933  break;
934  }
935  }
936  }
937 
938  return;
939 
940  case MiriamAnnotation:
941 
942  if (!strcmp(pszName, "MiriamAnnotation"))
944 
945  break;
946 
947  case Comment:
948 
949  if (!strcmp(pszName, "Comment"))
951 
952  break;
953 
955 
956  if (!strcmp(pszName, "ListOfUnsupportedAnnotations"))
958 
959  break;
960 
961  case Expression:
962 
963  if (!strcmp(pszName, "Expression"))
965  else if (!strcmp(pszName, "MathML"))
966  {
967  /* If we do not have a MathML element handler we create one. */
968  if (!mpMathMLElement)
969  mpMathMLElement = new MathMLElement(mParser, mCommon);
970 
973  }
974  else
976  pszName, "Expression", mParser.getCurrentLineNumber());
977 
978  break;
979 
981 
982  if (strcmp(pszName, "ListOfParameterDescriptions"))
984  pszName, "ListOfParameterDescriptions", mParser.getCurrentLineNumber());
985 
986  /* If we do not have a ListOfParameterDescriptions element handler we create one. */
988  mpListOfParameterDescriptionsElement = new ListOfParameterDescriptionsElement(mParser, mCommon);
989 
990  /* Push the ListOfParameterDescriptions element handler on the stack and call it. */
992  break;
993 
994  default:
997  break;
998  }
999  }
1000 
1002 
1004  {
1006  }
1007 
1008  mParser.onStartElement(pszName, papszAttrs);
1009 }
CCopasiVectorN< CFunction > * pFunctionList
#define pdelete(p)
Definition: copasi.h:215
UnknownElement mUnknownElement
const char * getAttributeValue(const std::string &name, const char **attributes, const bool &required=true) const
Definition: CExpat.h:685
#define MCXML
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
std::map< std::string, CExpression * > mKey2ObjectiveFunction
void setReversible(const TriLogic &reversible)
Definition: CFunction.cpp:142
std::map< size_t, std::string > mFunctionParameterKeyMap
ListOfParameterDescriptionsElement * mpListOfParameterDescriptionsElement
#define UNKNOWN_ELEMENT
virtual void onStartElement(const XML_Char *pszName, const XML_Char **papszAttrs)
void pushElementHandler(CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon > *elementHandler)
CharacterDataElement mCharacterDataElement
CType toEnum(const char *attribute, const char **enumNames, const CType &enumDefault)
Definition: utility.h:107
MiriamAnnotationElement mMiriamAnnotationElement
ListOfUnsupportedAnnotationsElement mListOfUnsupportedAnnotationsElement
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
int getCurrentLineNumber() const
Definition: CExpat.h:470
static const char * XMLType[]
CommentElement mCommentElement
bool setObjectName(const std::string &name)
static CEvaluationTree * create(CEvaluationTree::Type type)

Member Data Documentation

std::set< size_t > CCopasiXMLParser::FunctionElement::mExistingFunctionIndex
private

The index of a function with the same name

Definition at line 3069 of file CCopasiXMLParser.h.

std::string CCopasiXMLParser::FunctionElement::mKey
private

The key in the CopasiML file

Definition at line 3064 of file CCopasiXMLParser.h.

ListOfParameterDescriptionsElement* CCopasiXMLParser::FunctionElement::mpListOfParameterDescriptionsElement
private

Definition at line 3059 of file CCopasiXMLParser.h.

MathMLElement* CCopasiXMLParser::FunctionElement::mpMathMLElement
private

Definition at line 3054 of file CCopasiXMLParser.h.


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