Skip to content

Commit cf13c1a

Browse files
committed
Bug 3226: CCopasiParameter of type CN are correctly loaded in CopasiML.
1 parent 3780d32 commit cf13c1a

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

copasi/xml/CCopasiXMLInterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2019 - 2020 by Pedro Mendes, Rector and Visitors of the
1+
// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the
22
// University of Virginia, University of Heidelberg, and University
33
// of Connecticut School of Medicine.
44
// All rights reserved.
@@ -463,7 +463,7 @@ bool CCopasiXMLInterface::saveParameter(const CCopasiParameter & parameter)
463463
break;
464464

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

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

copasi/xml/parser/ParameterHandler.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2019 - 2020 by Pedro Mendes, Rector and Visitors of the
1+
// Copyright (C) 2019 - 2024 by Pedro Mendes, Rector and Visitors of the
22
// University of Virginia, University of Heidelberg, and University
33
// of Connecticut School of Medicine.
44
// All rights reserved.
@@ -18,6 +18,8 @@
1818
#include "ParameterHandler.h"
1919

2020
#include "CXMLParser.h"
21+
#include "copasi/CopasiDataModel/CDataModel.h"
22+
#include "copasi/core/CRegisteredCommonName.h"
2123
#include "copasi/utilities/CCopasiParameter.h"
2224

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

50-
void * pValue = NULL;
5152
CCopasiParameter::Type type;
5253

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

73+
mpData->pCurrentParameter = new CCopasiParameter(name, type);
74+
7275
switch (type)
7376
{
7477
case CCopasiParameter::Type::DOUBLE:
7578
d = CCopasiXMLInterface::DBL(sValue.c_str());
76-
pValue = &d;
79+
mpData->pCurrentParameter->setValue(d);
7780
break;
7881

7982
case CCopasiParameter::Type::UDOUBLE:
8083
d = CCopasiXMLInterface::DBL(sValue.c_str());
81-
pValue = &d;
84+
mpData->pCurrentParameter->setValue(d);
8285
break;
8386

8487
case CCopasiParameter::Type::INT:
8588
i = strToInt(sValue.c_str());
86-
pValue = &i;
89+
mpData->pCurrentParameter->setValue(i);
8790
break;
8891

8992
case CCopasiParameter::Type::UINT:
9093
ui = strToUnsignedInt(sValue.c_str());
91-
pValue = &ui;
94+
mpData->pCurrentParameter->setValue(ui);
9295
break;
9396

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

105-
pValue = &b;
108+
mpData->pCurrentParameter->setValue(b);
106109
break;
107110

108111
case CCopasiParameter::Type::STRING:
109112
case CCopasiParameter::Type::FILE:
110-
case CCopasiParameter::Type::CN:
111-
pValue = &sValue;
113+
mpData->pCurrentParameter->setValue(sValue);
112114
break;
113115

114116
case CCopasiParameter::Type::KEY:
115117
{
116-
if (sValue != "" &&
117-
CKeyFactory::isValidKey(sValue))
118+
if (sValue != "" && CKeyFactory::isValidKey(sValue))
118119
{
119120
CDataObject * pObject = mpData->mKeyMap.get(sValue);
120121

@@ -128,20 +129,21 @@ CXMLHandler * ParameterHandler::processStart(const XML_Char * pszName,
128129
}
129130
}
130131

131-
pValue = &sValue;
132+
mpData->pCurrentParameter->setValue(sValue);
132133
}
133134
break;
134135

136+
case CCopasiParameter::Type::CN:
137+
mpData->pCurrentParameter->setValue(CRegisteredCommonName(sValue, mpData->pDataModel));
138+
break;
139+
135140
default:
136141
if (cType != NULL) // otherwise missing attribute will have been logged
137142
CCopasiMessage(CCopasiMessage::ERROR, MCXML + 16, name.c_str(), cType, mpParser->getCurrentLineNumber());
138143

139-
pValue = NULL;
140144
break;
141145
}
142146

143-
mpData->pCurrentParameter = new CCopasiParameter(name, type, pValue);
144-
145147
if (UnmappedKey)
146148
{
147149
mpData->UnmappedKeyParameters.push_back(mpData->pCurrentParameter->getKey());

copasi/xml/parser/TaskHandler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "copasi/utilities/CTaskFactory.h"
2727
#include "copasi/model/CModel.h"
2828
#include "copasi/function/CExpression.h"
29+
#include "copasi/CopasiDataModel/CDataModel.h"
2930

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

243244
pGroup->addParameter("Role", CCopasiParameter::Type::UINT, entry.second.first);
244-
pGroup->addParameter("Object CN", CCopasiParameter::Type::CN, CRegisteredCommonName(entry.second.second, pGroup));
245+
pGroup->addParameter("Object CN", CCopasiParameter::Type::CN, CRegisteredCommonName(entry.second.second, mpData->pDataModel));
245246
}
246247
}
247248
}

0 commit comments

Comments
 (0)