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

Commit

Permalink
Rework getAttribute API
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
clero committed May 12, 2015
1 parent 72fc977 commit 1d4a7de
Show file tree
Hide file tree
Showing 32 changed files with 178 additions and 158 deletions.
5 changes: 3 additions & 2 deletions parameter/BitParameterBlockType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ uint32_t CBitParameterBlockType::getSize() const
bool CBitParameterBlockType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
{
// Size
_uiSize = xmlElement.getAttributeInteger("Size") / 8;
xmlElement.getAttribute("Size", _uiSize);
_uiSize /= 8;

// Base
return base::fromXml(xmlElement, serializingContext);
Expand All @@ -75,7 +76,7 @@ CInstanceConfigurableElement* CBitParameterBlockType::doInstantiate() const
void CBitParameterBlockType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
{
// Size
xmlElement.setAttributeString("Size", CUtility::toString(_uiSize * 8));
xmlElement.setAttribute("Size", CUtility::toString(_uiSize * 8));

base::toXml(xmlElement, serializingContext);
}
12 changes: 6 additions & 6 deletions parameter/BitParameterType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ void CBitParameterType::showProperties(string& strResult) const
bool CBitParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
{
// Pos
_uiBitPos = xmlElement.getAttributeInteger("Pos");
xmlElement.getAttribute("Pos", _uiBitPos);

// Size
_uiBitSize = xmlElement.getAttributeInteger("Size");
xmlElement.getAttribute("Size", _uiBitSize);

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

_uiMax = xmlElement.getAttributeInteger("Max");
xmlElement.getAttribute("Max", _uiMax);

if (_uiMax > getMaxEncodableValue()) {

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

// Size
xmlElement.setAttributeString("Size", CUtility::toString(_uiBitSize));
xmlElement.setAttribute("Size", _uiBitSize);

// Maximum
xmlElement.setAttributeString("Max", CUtility::toString(_uiMax));
xmlElement.setAttribute("Max", _uiMax);

base::toXml(xmlElement, serializingContext);

Expand Down
3 changes: 2 additions & 1 deletion parameter/ComponentInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ bool CComponentInstance::fromXml(const CXmlElement& xmlElement, CXmlSerializingC

const CComponentLibrary* pComponentLibrary = parameterBuildContext.getComponentLibrary();

std::string strComponentType = xmlElement.getAttributeString("Type");
std::string strComponentType;
xmlElement.getAttribute("Type", strComponentType);

_pComponentType = pComponentLibrary->getComponentType(strComponentType);

Expand Down
3 changes: 2 additions & 1 deletion parameter/ComponentType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ bool CComponentType::fromXml(const CXmlElement& xmlElement, CXmlSerializingConte
// Check for Extends attribute (extensions will be populated after and not before)
if (xmlElement.hasAttribute("Extends")) {

std::string strExtendsType = xmlElement.getAttributeString("Extends");
std::string strExtendsType;
xmlElement.getAttribute("Extends", strExtendsType);

_pExtendsComponentType = pComponentLibrary->getComponentType(strExtendsType);

Expand Down
2 changes: 1 addition & 1 deletion parameter/CompoundRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool CCompoundRule::fromXml(const CXmlElement& xmlElement, CXmlSerializingContex
void CCompoundRule::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
{
// Set type
xmlElement.setAttributeString("Type", _apcTypes[_bTypeAll]);
xmlElement.setAttribute("Type", _apcTypes[_bTypeAll]);

// Base
base::toXml(xmlElement, serializingContext);
Expand Down
13 changes: 8 additions & 5 deletions parameter/ConfigurableDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void CConfigurableDomain::toXml(CXmlElement& xmlElement, CXmlSerializingContext&
base::toXml(xmlElement, serializingContext);

// Sequence awareness
xmlElement.setAttributeBoolean("SequenceAware", _bSequenceAware);
xmlElement.setAttribute("SequenceAware", _bSequenceAware);
}

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

// Set Path attribute
xmlChildConfigurableElement.setAttributeString("Path", pConfigurableElement->getPath());
xmlChildConfigurableElement.setAttribute("Path", pConfigurableElement->getPath());
}
}

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

// Sequence awareness (optional)
_bSequenceAware = xmlElement.hasAttribute("SequenceAware") && xmlElement.getAttributeBoolean("SequenceAware");
xmlElement.getAttribute("SequenceAware", _bSequenceAware);

setName(xmlElement.getAttributeString("Name"));
std::string name;
xmlElement.getAttribute("Name", name);
setName(name);

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

// Locate configurable element
string strConfigurableElementPath = xmlConfigurableElementElement.getAttributeString("Path");
string strConfigurableElementPath;
xmlConfigurableElementElement.getAttribute("Path", strConfigurableElementPath);

CPathNavigator pathNavigator(strConfigurableElementPath);
string strError;
Expand Down
2 changes: 1 addition & 1 deletion parameter/ConfigurableDomains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard,
void CConfigurableDomains::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
{
// Set attribute
xmlElement.setAttributeString("SystemClassName", getName());
xmlElement.setAttribute("SystemClassName", getName());

base::childrenToXml(xmlElement, serializingContext);
}
Expand Down
5 changes: 3 additions & 2 deletions parameter/DomainConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ bool CDomainConfiguration::parseSettings(CXmlElement& xmlConfigurationSettingsEl
while (it.next(xmlConfigurableElementSettingsElement)) {

// Retrieve area configuration
string strConfigurableElementPath = xmlConfigurableElementSettingsElement.getAttributeString("Path");
string strConfigurableElementPath;
xmlConfigurableElementSettingsElement.getAttribute("Path", strConfigurableElementPath);

CAreaConfiguration* pAreaConfiguration = findAreaConfiguration(strConfigurableElementPath);

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

// Set Path attribute
xmlConfigurableElementSettingsElement.setAttributeString("Path", pConfigurableElement->getPath());
xmlConfigurableElementSettingsElement.setAttribute("Path", pConfigurableElement->getPath());

// Delegate composing to area configuration
((CDomainConfiguration&)(*this)).serializeConfigurableElementSettings((CAreaConfiguration*)pAreaConfiguration, xmlConfigurableElementSettingsElement, serializingContext, true);
Expand Down
5 changes: 3 additions & 2 deletions parameter/EnumParameterType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ void CEnumParameterType::showProperties(string& strResult) const
bool CEnumParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
{
// Size in bits
uint32_t uiSizeInBits = xmlElement.getAttributeInteger("Size");
uint32_t uiSizeInBits;
xmlElement.getAttribute("Size", uiSizeInBits);

// Size
setSize(uiSizeInBits / 8);
Expand Down Expand Up @@ -345,7 +346,7 @@ bool CEnumParameterType::isValid(int iNumerical, CParameterAccessContext& parame
void CEnumParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
{
// Size
xmlElement.setAttributeString("Size", CUtility::toString(getSize() * 8));
xmlElement.setAttribute("Size", getSize() * 8);

base::toXml(xmlElement, serializingContext);
}
10 changes: 6 additions & 4 deletions parameter/EnumValuePair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ string CEnumValuePair::getNumericalAsString() const
bool CEnumValuePair::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
{
// Literal
setName(xmlElement.getAttributeString("Literal"));
std::string name;
xmlElement.getAttribute("Literal", name);
setName(name);

// Numerical
_iNumerical = xmlElement.getAttributeSignedInteger("Numerical");
xmlElement.getAttribute("Numerical", _iNumerical);

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

// Numerical
xmlElement.setAttributeString("Numerical", getNumericalAsString());
xmlElement.setAttribute("Numerical", getNumericalAsString());

base::toXml(xmlElement, serializingContext);
}
22 changes: 14 additions & 8 deletions parameter/FixedPointParameterType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,30 @@ void CFixedPointParameterType::handleValueSpaceAttribute(CXmlElement& xmlConfigu
// Provide value space only if not the default one
if (configurationAccessContext.valueSpaceIsRaw()) {

xmlConfigurableElementSettingsElement.setAttributeString("ValueSpace", "Raw");
xmlConfigurableElementSettingsElement.setAttribute("ValueSpace", "Raw");
}
}
}

bool CFixedPointParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
{
// Size
uint32_t uiSizeInBits = xmlElement.getAttributeInteger("Size");
uint32_t uiSizeInBits;
xmlElement.getAttribute("Size", uiSizeInBits);

// Q notation
_uiIntegral = xmlElement.getAttributeInteger("Integral");
_uiFractional = xmlElement.getAttributeInteger("Fractional");
xmlElement.getAttribute("Integral", _uiIntegral);
xmlElement.getAttribute("Fractional", _uiFractional);

// Size vs. Q notation integrity check
if (uiSizeInBits < getUtilSizeInBits()) {

serializingContext.setError("Inconsistent Size vs. Q notation for " + getKind() + " " + xmlElement.getPath() + ": Summing (Integral + _uiFractional + 1) should not exceed given Size (" + xmlElement.getAttributeString("Size") + ")");
std::string size;
xmlElement.getAttribute("Size", size);
serializingContext.setError(
"Inconsistent Size vs. Q notation for " + getKind() + " " + xmlElement.getPath() +
": Summing (Integral + _uiFractional + 1) should not exceed given Size (" +
size + ")");

return false;
}
Expand Down Expand Up @@ -364,13 +370,13 @@ double CFixedPointParameterType::binaryQnmToDouble(int32_t iValue) const
void CFixedPointParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
{
// Size
xmlElement.setAttributeString("Size", CUtility::toString(getSize() * 8));
xmlElement.setAttribute("Size", getSize() * 8);

// Integral
xmlElement.setAttributeString("Integral", CUtility::toString(_uiIntegral));
xmlElement.setAttribute("Integral", _uiIntegral);

// Fractional
xmlElement.setAttributeString("Fractional", CUtility::toString(_uiFractional));
xmlElement.setAttribute("Fractional", _uiFractional);

base::toXml(xmlElement, serializingContext);
}
2 changes: 1 addition & 1 deletion parameter/FrameworkConfigurationLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CFrameworkConfigurationLocation::CFrameworkConfigurationLocation(const std::stri
// From IXmlSink
bool CFrameworkConfigurationLocation::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
{
_strPath = xmlElement.getAttributeString("Path");
xmlElement.getAttribute("Path", _strPath);

if (_strPath.empty()) {

Expand Down
30 changes: 18 additions & 12 deletions parameter/IntegerParameterType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,27 @@ void CIntegerParameterType::showProperties(string& strResult) const
bool CIntegerParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
{
// Sign
_bSigned = xmlElement.getAttributeBoolean("Signed");
xmlElement.getAttribute("Signed", _bSigned);

// Size in bits
uint32_t uiSizeInBits = xmlElement.getAttributeInteger("Size");
uint32_t uiSizeInBits = 0;
xmlElement.getAttribute("Size", uiSizeInBits);

// Size
setSize(uiSizeInBits / 8);

// Min / Max
// TODO: Make IntegerParameter template
if (_bSigned) {

// Signed means we have one less util bit
uiSizeInBits--;

if (xmlElement.hasAttribute("Min")) {

_uiMin = (uint32_t)xmlElement.getAttributeSignedInteger("Min");
int min = 0;
xmlElement.getAttribute("Min", min);
_uiMin = (uint32_t) min;
} else {

_uiMin = 1UL << uiSizeInBits;
Expand All @@ -119,7 +123,9 @@ bool CIntegerParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializi

if (xmlElement.hasAttribute("Max")) {

_uiMax = (uint32_t)xmlElement.getAttributeSignedInteger("Max");
int max = 0;
xmlElement.getAttribute("Max", max);
_uiMax = (uint32_t) max;

signExtend((int32_t&)_uiMax);
} else {
Expand All @@ -129,14 +135,14 @@ bool CIntegerParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializi
} else {
if (xmlElement.hasAttribute("Min")) {

_uiMin = xmlElement.getAttributeInteger("Min");
xmlElement.getAttribute("Min", _uiMin);
} else {

_uiMin = 0;
}
if (xmlElement.hasAttribute("Max")) {

_uiMax = xmlElement.getAttributeInteger("Max");
xmlElement.getAttribute("Max", _uiMax);
} else {

_uiMax = (uint32_t)-1L >> (8 * sizeof(uint32_t) - uiSizeInBits);
Expand Down Expand Up @@ -435,27 +441,27 @@ const CParameterAdaptation* CIntegerParameterType::getParameterAdaptation() cons
void CIntegerParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
{
// Sign
xmlElement.setAttributeBoolean("Signed", _bSigned);
xmlElement.setAttribute("Signed", _bSigned);

if (_bSigned) {

// Mininmum
xmlElement.setAttributeString("Min", CUtility::toString((int32_t)_uiMin));
xmlElement.setAttribute("Min", (int32_t)_uiMin);

// Maximum
xmlElement.setAttributeString("Max", CUtility::toString((int32_t)_uiMax));
xmlElement.setAttribute("Max", (int32_t)_uiMax);

} else {

// Minimum
xmlElement.setAttributeString("Min", CUtility::toString(_uiMin));
xmlElement.setAttribute("Min", _uiMin);

// Maximum
xmlElement.setAttributeString("Max", CUtility::toString(_uiMax));
xmlElement.setAttribute("Max", _uiMax);
}

// Size
xmlElement.setAttributeString("Size", CUtility::toString(getSize() * 8));
xmlElement.setAttribute("Size", getSize() * 8);

base::toXml(xmlElement, serializingContext);

Expand Down
4 changes: 2 additions & 2 deletions parameter/LinearParameterAdaptation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool CLinearParameterAdaptation::fromXml(const CXmlElement& xmlElement, CXmlSeri
// Get SlopeNumerator
if (xmlElement.hasAttribute("SlopeNumerator")) {

_dSlopeNumerator = xmlElement.getAttributeDouble("SlopeNumerator");
xmlElement.getAttribute("SlopeNumerator", _dSlopeNumerator);

} else {
// Default
Expand All @@ -74,7 +74,7 @@ bool CLinearParameterAdaptation::fromXml(const CXmlElement& xmlElement, CXmlSeri
// Get SlopeDenominator
if (xmlElement.hasAttribute("SlopeDenominator")) {

_dSlopeDenominator = xmlElement.getAttributeDouble("SlopeDenominator");
xmlElement.getAttribute("SlopeDenominator", _dSlopeDenominator);

// Avoid by 0 division errors
if (_dSlopeDenominator == 0) {
Expand Down
4 changes: 2 additions & 2 deletions parameter/LogarithmicParameterAdaptation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool CLogarithmicParameterAdaptation::fromXml(const CXmlElement& xmlElement,

if (xmlElement.hasAttribute("LogarithmBase")) {

_dLogarithmBase = xmlElement.getAttributeDouble("LogarithmBase");
xmlElement.getAttribute("LogarithmBase", _dLogarithmBase);

// Avoid negative and 1 values
if (_dLogarithmBase <= 0 || _dLogarithmBase == 1) {
Expand All @@ -71,7 +71,7 @@ bool CLogarithmicParameterAdaptation::fromXml(const CXmlElement& xmlElement,
}

if (xmlElement.hasAttribute("FloorValue")) {
_dFloorValue = xmlElement.getAttributeDouble("FloorValue");
xmlElement.getAttribute("FloorValue", _dFloorValue);
}
// Base
return base::fromXml(xmlElement, serializingContext);
Expand Down
Loading

0 comments on commit 1d4a7de

Please sign in to comment.