Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 481ce2b

Browse files
committed
Rework getAttribute API
getAttribute API forces the user to call a specific API for each call getAttributeString etc.. This patch replaces this API by a template one. The success of of the action can now be checked. It can be useful one to check that a conversion succeed. Signed-off-by: Jules Clero <[email protected]>
1 parent 72fc977 commit 481ce2b

31 files changed

+177
-158
lines changed

parameter/BitParameterBlockType.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ uint32_t CBitParameterBlockType::getSize() const
5959
bool CBitParameterBlockType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
6060
{
6161
// Size
62-
_uiSize = xmlElement.getAttributeInteger("Size") / 8;
62+
xmlElement.getAttribute("Size", _uiSize);
63+
_uiSize /= 8;
6364

6465
// Base
6566
return base::fromXml(xmlElement, serializingContext);
@@ -75,7 +76,7 @@ CInstanceConfigurableElement* CBitParameterBlockType::doInstantiate() const
7576
void CBitParameterBlockType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
7677
{
7778
// Size
78-
xmlElement.setAttributeString("Size", CUtility::toString(_uiSize * 8));
79+
xmlElement.setAttribute("Size", CUtility::toString(_uiSize * 8));
7980

8081
base::toXml(xmlElement, serializingContext);
8182
}

parameter/BitParameterType.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ void CBitParameterType::showProperties(string& strResult) const
7474
bool CBitParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
7575
{
7676
// Pos
77-
_uiBitPos = xmlElement.getAttributeInteger("Pos");
77+
xmlElement.getAttribute("Pos", _uiBitPos);
7878

7979
// Size
80-
_uiBitSize = xmlElement.getAttributeInteger("Size");
80+
xmlElement.getAttribute("Size", _uiBitSize);
8181

8282
// Validate bit pos and size still fit into parent type
8383
const CBitParameterBlockType* pBitParameterBlockType = static_cast<const CBitParameterBlockType*>(getParent());
@@ -99,7 +99,7 @@ bool CBitParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingCo
9999
// Max
100100
if (xmlElement.hasAttribute("Max")) {
101101

102-
_uiMax = xmlElement.getAttributeInteger("Max");
102+
xmlElement.getAttribute("Max", _uiMax);
103103

104104
if (_uiMax > getMaxEncodableValue()) {
105105

@@ -246,13 +246,13 @@ bool CBitParameterType::isEncodable(uint64_t uiData) const
246246
void CBitParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
247247
{
248248
// Position
249-
xmlElement.setAttributeString("Pos", CUtility::toString(_uiBitPos));
249+
xmlElement.setAttribute("Pos", _uiBitPos);
250250

251251
// Size
252-
xmlElement.setAttributeString("Size", CUtility::toString(_uiBitSize));
252+
xmlElement.setAttribute("Size", _uiBitSize);
253253

254254
// Maximum
255-
xmlElement.setAttributeString("Max", CUtility::toString(_uiMax));
255+
xmlElement.setAttribute("Max", _uiMax);
256256

257257
base::toXml(xmlElement, serializingContext);
258258

parameter/ComponentInstance.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ bool CComponentInstance::fromXml(const CXmlElement& xmlElement, CXmlSerializingC
8080

8181
const CComponentLibrary* pComponentLibrary = parameterBuildContext.getComponentLibrary();
8282

83-
std::string strComponentType = xmlElement.getAttributeString("Type");
83+
std::string strComponentType;
84+
xmlElement.getAttribute("Type", strComponentType);
8485

8586
_pComponentType = pComponentLibrary->getComponentType(strComponentType);
8687

parameter/ComponentType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ bool CComponentType::fromXml(const CXmlElement& xmlElement, CXmlSerializingConte
8989
// Check for Extends attribute (extensions will be populated after and not before)
9090
if (xmlElement.hasAttribute("Extends")) {
9191

92-
std::string strExtendsType = xmlElement.getAttributeString("Extends");
92+
std::string strExtendsType;
93+
xmlElement.getAttribute("Extends", strExtendsType);
9394

9495
_pExtendsComponentType = pComponentLibrary->getComponentType(strExtendsType);
9596

parameter/CompoundRule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ bool CCompoundRule::fromXml(const CXmlElement& xmlElement, CXmlSerializingContex
150150
void CCompoundRule::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
151151
{
152152
// Set type
153-
xmlElement.setAttributeString("Type", _apcTypes[_bTypeAll]);
153+
xmlElement.setAttribute("Type", _apcTypes[_bTypeAll]);
154154

155155
// Base
156156
base::toXml(xmlElement, serializingContext);

parameter/ConfigurableDomain.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void CConfigurableDomain::toXml(CXmlElement& xmlElement, CXmlSerializingContext&
120120
base::toXml(xmlElement, serializingContext);
121121

122122
// Sequence awareness
123-
xmlElement.setAttributeBoolean("SequenceAware", _bSequenceAware);
123+
xmlElement.setAttribute("SequenceAware", _bSequenceAware);
124124
}
125125

126126
void CConfigurableDomain::childrenToXml(CXmlElement& xmlElement,
@@ -168,7 +168,7 @@ void CConfigurableDomain::composeConfigurableElements(CXmlElement& xmlElement) c
168168
xmlConfigurableElementsElement.createChild(xmlChildConfigurableElement, "ConfigurableElement");
169169

170170
// Set Path attribute
171-
xmlChildConfigurableElement.setAttributeString("Path", pConfigurableElement->getPath());
171+
xmlChildConfigurableElement.setAttribute("Path", pConfigurableElement->getPath());
172172
}
173173
}
174174

@@ -217,9 +217,11 @@ bool CConfigurableDomain::fromXml(const CXmlElement& xmlElement, CXmlSerializing
217217
static_cast<CXmlDomainImportContext&>(serializingContext);
218218

219219
// Sequence awareness (optional)
220-
_bSequenceAware = xmlElement.hasAttribute("SequenceAware") && xmlElement.getAttributeBoolean("SequenceAware");
220+
xmlElement.getAttribute("SequenceAware", _bSequenceAware);
221221

222-
setName(xmlElement.getAttributeString("Name"));
222+
std::string name;
223+
xmlElement.getAttribute("Name", name);
224+
setName(name);
223225

224226
// Local parsing. Do not dig
225227
if (!parseDomainConfigurations(xmlElement, xmlDomainImportContext) ||
@@ -273,7 +275,8 @@ bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElemen
273275
while (it.next(xmlConfigurableElementElement)) {
274276

275277
// Locate configurable element
276-
string strConfigurableElementPath = xmlConfigurableElementElement.getAttributeString("Path");
278+
string strConfigurableElementPath;
279+
xmlConfigurableElementElement.getAttribute("Path", strConfigurableElementPath);
277280

278281
CPathNavigator pathNavigator(strConfigurableElementPath);
279282
string strError;

parameter/ConfigurableDomains.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard,
111111
void CConfigurableDomains::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
112112
{
113113
// Set attribute
114-
xmlElement.setAttributeString("SystemClassName", getName());
114+
xmlElement.setAttribute("SystemClassName", getName());
115115

116116
base::childrenToXml(xmlElement, serializingContext);
117117
}

parameter/DomainConfiguration.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ bool CDomainConfiguration::parseSettings(CXmlElement& xmlConfigurationSettingsEl
8686
while (it.next(xmlConfigurableElementSettingsElement)) {
8787

8888
// Retrieve area configuration
89-
string strConfigurableElementPath = xmlConfigurableElementSettingsElement.getAttributeString("Path");
89+
string strConfigurableElementPath;
90+
xmlConfigurableElementSettingsElement.getAttribute("Path", strConfigurableElementPath);
9091

9192
CAreaConfiguration* pAreaConfiguration = findAreaConfiguration(strConfigurableElementPath);
9293

@@ -131,7 +132,7 @@ void CDomainConfiguration::composeSettings(CXmlElement& xmlConfigurationSettings
131132
xmlConfigurationSettingsElement.createChild(xmlConfigurableElementSettingsElement, "ConfigurableElement");
132133

133134
// Set Path attribute
134-
xmlConfigurableElementSettingsElement.setAttributeString("Path", pConfigurableElement->getPath());
135+
xmlConfigurableElementSettingsElement.setAttribute("Path", pConfigurableElement->getPath());
135136

136137
// Delegate composing to area configuration
137138
((CDomainConfiguration&)(*this)).serializeConfigurableElementSettings((CAreaConfiguration*)pAreaConfiguration, xmlConfigurableElementSettingsElement, serializingContext, true);

parameter/EnumParameterType.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ void CEnumParameterType::showProperties(string& strResult) const
8282
bool CEnumParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
8383
{
8484
// Size in bits
85-
uint32_t uiSizeInBits = xmlElement.getAttributeInteger("Size");
85+
uint32_t uiSizeInBits;
86+
xmlElement.getAttribute("Size", uiSizeInBits);
8687

8788
// Size
8889
setSize(uiSizeInBits / 8);
@@ -345,7 +346,7 @@ bool CEnumParameterType::isValid(int iNumerical, CParameterAccessContext& parame
345346
void CEnumParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
346347
{
347348
// Size
348-
xmlElement.setAttributeString("Size", CUtility::toString(getSize() * 8));
349+
xmlElement.setAttribute("Size", getSize() * 8);
349350

350351
base::toXml(xmlElement, serializingContext);
351352
}

parameter/EnumValuePair.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ string CEnumValuePair::getNumericalAsString() const
5959
bool CEnumValuePair::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
6060
{
6161
// Literal
62-
setName(xmlElement.getAttributeString("Literal"));
62+
std::string name;
63+
xmlElement.getAttribute("Literal", name);
64+
setName(name);
6365

6466
// Numerical
65-
_iNumerical = xmlElement.getAttributeSignedInteger("Numerical");
67+
xmlElement.getAttribute("Numerical", _iNumerical);
6668

6769
// Base
6870
return base::fromXml(xmlElement, serializingContext);
@@ -80,10 +82,10 @@ void CEnumValuePair::logValue(string& strValue, CErrorContext& errorContext) con
8082
void CEnumValuePair::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
8183
{
8284
// Literal
83-
xmlElement.setAttributeString("Literal", this->getName());
85+
xmlElement.setAttribute("Literal", this->getName());
8486

8587
// Numerical
86-
xmlElement.setAttributeString("Numerical", getNumericalAsString());
88+
xmlElement.setAttribute("Numerical", getNumericalAsString());
8789

8890
base::toXml(xmlElement, serializingContext);
8991
}

0 commit comments

Comments
 (0)