Skip to content

Commit

Permalink
Bug 3226: CCopasiParameter of type CN are correctly loaded in CopasiML.
Browse files Browse the repository at this point in the history
  • Loading branch information
shoops committed Apr 5, 2024
1 parent 3780d32 commit cf13c1a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions copasi/xml/CCopasiXMLInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 - 2020 by Pedro Mendes, Rector and Visitors of the
// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the
// University of Virginia, University of Heidelberg, and University
// of Connecticut School of Medicine.
// All rights reserved.
Expand Down Expand Up @@ -463,7 +463,7 @@ bool CCopasiXMLInterface::saveParameter(const CCopasiParameter & parameter)
break;

case CCopasiParameter::Type::CN:
Attributes.add("value", parameter.getValue< CCommonName >());
Attributes.add("value", parameter.getValue< CRegisteredCommonName >());

if (!saveElement("Parameter", Attributes)) success = false;

Expand Down
32 changes: 17 additions & 15 deletions copasi/xml/parser/ParameterHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 - 2020 by Pedro Mendes, Rector and Visitors of the
// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the
// University of Virginia, University of Heidelberg, and University
// of Connecticut School of Medicine.
// All rights reserved.
Expand All @@ -18,6 +18,8 @@
#include "ParameterHandler.h"

#include "CXMLParser.h"
#include "copasi/CopasiDataModel/CDataModel.h"
#include "copasi/core/CRegisteredCommonName.h"
#include "copasi/utilities/CCopasiParameter.h"

/**
Expand Down Expand Up @@ -47,7 +49,6 @@ CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName,
std::string sValue("");
bool UnmappedKey = false;

void * pValue = NULL;
CCopasiParameter::Type type;

C_FLOAT64 d;
Expand All @@ -69,26 +70,28 @@ CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName,
sValue = cValue;
}

mpData->pCurrentParameter = new CCopasiParameter(name, type);

switch (type)
{
case CCopasiParameter::Type::DOUBLE:
d = CCopasiXMLInterface::DBL(sValue.c_str());
pValue = &d;
mpData->pCurrentParameter->setValue(d);
break;

case CCopasiParameter::Type::UDOUBLE:
d = CCopasiXMLInterface::DBL(sValue.c_str());
pValue = &d;
mpData->pCurrentParameter->setValue(d);
break;

case CCopasiParameter::Type::INT:
i = strToInt(sValue.c_str());
pValue = &i;
mpData->pCurrentParameter->setValue(i);
break;

case CCopasiParameter::Type::UINT:
ui = strToUnsignedInt(sValue.c_str());
pValue = &ui;
mpData->pCurrentParameter->setValue(ui);
break;

case CCopasiParameter::Type::BOOL:
Expand All @@ -102,19 +105,17 @@ CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName,
b = true;
}

pValue = &b;
mpData->pCurrentParameter->setValue(b);
break;

case CCopasiParameter::Type::STRING:
case CCopasiParameter::Type::FILE:
case CCopasiParameter::Type::CN:
pValue = &sValue;
mpData->pCurrentParameter->setValue(sValue);
break;

case CCopasiParameter::Type::KEY:
{
if (sValue != "" &&
CKeyFactory::isValidKey(sValue))
if (sValue != "" && CKeyFactory::isValidKey(sValue))
{
CDataObject * pObject = mpData->mKeyMap.get(sValue);

Expand All @@ -128,20 +129,21 @@ CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName,
}
}

pValue = &sValue;
mpData->pCurrentParameter->setValue(sValue);
}
break;

case CCopasiParameter::Type::CN:
mpData->pCurrentParameter->setValue(CRegisteredCommonName(sValue, mpData->pDataModel));
break;

default:
if (cType != NULL) // otherwise missing attribute will have been logged
CCopasiMessage(CCopasiMessage::ERROR, MCXML + 16, name.c_str(), cType, mpParser->getCurrentLineNumber());

pValue = NULL;
break;
}

mpData->pCurrentParameter = new CCopasiParameter(name, type, pValue);

if (UnmappedKey)
{
mpData->UnmappedKeyParameters.push_back(mpData->pCurrentParameter->getKey());
Expand Down
3 changes: 2 additions & 1 deletion copasi/xml/parser/TaskHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "copasi/utilities/CTaskFactory.h"
#include "copasi/model/CModel.h"
#include "copasi/function/CExpression.h"
#include "copasi/CopasiDataModel/CDataModel.h"

/**
* Replace Task with the name type of the handler and implement the
Expand Down Expand Up @@ -241,7 +242,7 @@ bool TaskHandler::processEnd(const XML_Char * pszName)
continue;

pGroup->addParameter("Role", CCopasiParameter::Type::UINT, entry.second.first);
pGroup->addParameter("Object CN", CCopasiParameter::Type::CN, CRegisteredCommonName(entry.second.second, pGroup));
pGroup->addParameter("Object CN", CCopasiParameter::Type::CN, CRegisteredCommonName(entry.second.second, mpData->pDataModel));
}
}
}
Expand Down

0 comments on commit cf13c1a

Please sign in to comment.