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

Public Member Functions

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

Private Types

enum  Element { ParameterDescription = 0 }
 

Private Attributes

unsigned C_INT32 mOrder
 

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 2942 of file CCopasiXMLParser.h.

Member Enumeration Documentation

Enumerator
ParameterDescription 

Definition at line 2949 of file CCopasiXMLParser.h.

Constructor & Destructor Documentation

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

Destructor

Definition at line 1451 of file CCopasiXMLParser.cpp.

Member Function Documentation

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

End element handler

Parameters
constXML_Char *pszName

Definition at line 1575 of file CCopasiXMLParser.cpp.

References CCopasiMessage::EXCEPTION, MCXML, CExpatTemplate< CExpat >::mParser, START_ELEMENT, and UNKNOWN_ELEMENT.

1576 {
1577  switch (mCurrentElement)
1578  {
1579  case ParameterDescription:
1580 
1581  if (strcmp(pszName, "ParameterDescription"))
1583  pszName, "ParameterDescription", mParser.getCurrentLineNumber());
1584 
1587 
1588  /* Tell the parent element we are done. */
1589  mParser.onEndElement(pszName);
1590  break;
1591 
1592  case UNKNOWN_ELEMENT:
1594  break;
1595 
1596  default:
1598  pszName, "???", mParser.getCurrentLineNumber());
1599  break;
1600  }
1601 
1602  return;
1603 }
#define START_ELEMENT
#define MCXML
virtual void onEndElement(const XML_Char *pszName)
#define UNKNOWN_ELEMENT
int getCurrentLineNumber() const
Definition: CExpat.h:470
void CCopasiXMLParser::ParameterDescriptionElement::reset ( )
virtual

Reset the element handler to start values.

Reimplemented from CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon >.

Definition at line 1605 of file CCopasiXMLParser.cpp.

void CCopasiXMLParser::ParameterDescriptionElement::start ( const XML_Char *  pszName,
const XML_Char **  papszAttrs 
)
virtual

Start element handler

Parameters
constXML_Char *pszName
constXML_Char **papszAttrs

Definition at line 1456 of file CCopasiXMLParser.cpp.

References CFunctionParameters::add(), C_INT32, C_INVALID_INDEX, CCopasiMessage::EXCEPTION, CFunctionParameters::findParameterByName(), CFunctionParameter::FLOAT64, CFunction::getVariables(), CCopasiXMLParser::mCommon, MCXML, SCopasiXMLParserCommon::mFunctionParameterKeyMap, CExpatTemplate< CExpat >::mParser, SCopasiXMLParserCommon::mPredefinedFunction, SCopasiXMLParserCommon::pFunction, CFunctionParameter::setIsUsed(), CCopasiObject::setObjectName(), CFunctionParameter::setType(), CFunctionParameter::setUsage(), CFunctionParameters::size(), StringPrint(), strToUnsignedInt(), CFunctionParameters::swap(), CFunctionParameter::TEMPORARY, UNKNOWN_ELEMENT, CFunctionParameter::VFLOAT64, and CFunctionParameter::xmlRole2Enum().

1458 {
1459  const char * Key;
1460  const char * Name;
1461  const char * order;
1462  unsigned C_INT32 Order;
1463  const char * role; /*substrate, product, modifier, constant, other*/
1465  const char * minOccurs;
1466  unsigned C_INT32 MinOccurs;
1467  const char * maxOccurs;
1468  unsigned C_INT32 MaxOccurs;
1469 
1470  mCurrentElement++; /* We should always be on the next element */
1471 
1472  //std::string Usage[] = {"SUBSTRATE", "PRODUCT", "MODIFIER", "PARAMETER"};
1473  CFunctionParameter * pParm = NULL;
1474  CFunction * pFunction = dynamic_cast<CFunction *>(mCommon.pFunction);
1475 
1476  if (!pFunction) mCurrentElement++;
1477 
1478  switch (mCurrentElement)
1479  {
1480  case ParameterDescription:
1481 
1482  if (strcmp(pszName, "ParameterDescription"))
1484  pszName, "ParameterDescription", mParser.getCurrentLineNumber());
1485 
1486  Key = mParser.getAttributeValue("key", papszAttrs);
1487  Name = mParser.getAttributeValue("name", papszAttrs);
1488 
1489  order = mParser.getAttributeValue("order", papszAttrs);
1490  Order = (unsigned C_INT32) atoi(order);
1491 
1492  role = mParser.getAttributeValue("role", papszAttrs);
1493  Role = CFunctionParameter::xmlRole2Enum(role);
1494  //if (Role == "") fatalError();
1495 
1496  minOccurs = mParser.getAttributeValue("minOccurs", papszAttrs, "1");
1497  MinOccurs = strToUnsignedInt(minOccurs);
1498 
1499  maxOccurs = mParser.getAttributeValue("maxOccurs", papszAttrs , "1");
1500 
1501  if (std::string("unbounded") == std::string(maxOccurs))
1502  MaxOccurs = (unsigned C_INT32) - 1;
1503  else
1504  MaxOccurs = strToUnsignedInt(maxOccurs);
1505 
1507  {
1508  addFix(Key, pFunction->getVariables()[Name]);
1509  }
1510  else
1511  {
1512  // If we are here we have a user defined function.
1513  // We need to check whether the variable exists within the function.
1515  size_t Index =
1516  pFunction->getVariables().findParameterByName(Name, DataType);
1517 
1518  bool isUsed = true;
1519 
1520  if (Index == C_INVALID_INDEX)
1521  {
1522  // We add the missing parameter and mark it as unused.
1523  pFunction->getVariables().add(Name,
1525  Role);
1526 
1527  Index = pFunction->getVariables().findParameterByName(Name, DataType);
1528  isUsed = false;
1529  }
1530 
1531  // Make sure that we have enough parameter to swap
1532  size_t Counter = 0;
1533 
1534  while (Order >= pFunction->getVariables().size())
1535  {
1536  std::string NewName = StringPrint("TMP_%d", Counter++);
1537 
1538  while (!pFunction->getVariables().add(NewName,
1541 
1542  NewName = StringPrint("TMP_%d", Counter++);
1543  }
1544 
1545  // Assure that the order is correct
1546  if (Order != Index)
1547  pFunction->getVariables().swap(Order, Index);
1548 
1549  pParm = pFunction->getVariables()[Order];
1550  pParm->setObjectName(Name);
1551  pParm->setUsage(Role);
1552  pParm->setIsUsed(isUsed);
1553 
1554  if (MaxOccurs == 1 && MinOccurs == 1)
1556  else
1558 
1559  mCommon.mFunctionParameterKeyMap[Order] = Key;
1560  }
1561 
1562  break;
1563 
1564  default:
1568  mParser.onStartElement(pszName, papszAttrs);
1569  break;
1570  }
1571 
1572  return;
1573 }
void swap(const size_t &from, const size_t &to)
void setIsUsed(const bool &isUsed)
UnknownElement mUnknownElement
void setUsage(Role usage)
size_t findParameterByName(const std::string &name, CFunctionParameter::DataType &dataType) const
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
void setType(const CFunctionParameter::DataType &type)
#define C_INT32
Definition: copasi.h:90
std::map< size_t, std::string > mFunctionParameterKeyMap
void addFix(const std::string &key, CCopasiObject *pObject)
Definition: CXMLHandler.h:119
#define UNKNOWN_ELEMENT
virtual void onStartElement(const XML_Char *pszName, const XML_Char **papszAttrs)
void add(const CFunctionParameter &parameter)
void pushElementHandler(CXMLElementHandler< CCopasiXMLParser, SCopasiXMLParserCommon > *elementHandler)
unsigned C_INT32 strToUnsignedInt(const char *str, char const **pTail)
Definition: utility.cpp:384
static Role xmlRole2Enum(const std::string &role)
std::string StringPrint(const char *format,...)
Definition: utility.cpp:87
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
int getCurrentLineNumber() const
Definition: CExpat.h:470
bool setObjectName(const std::string &name)
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148

Member Data Documentation

unsigned C_INT32 CCopasiXMLParser::ParameterDescriptionElement::mOrder
private

Order

Definition at line 2957 of file CCopasiXMLParser.h.


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