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

Commit 7271b40

Browse files
committed
Merge pull request #138 from dawagner/remove-mappingdata-xmlsink-inheritance
Remove mappingdata xmlsink inheritance The MappingData inheritance from XmlSink can be avoided at no cost.
2 parents 983b149 + 2957860 commit 7271b40

4 files changed

Lines changed: 28 additions & 18 deletions

File tree

parameter/MappingData.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2014, Intel Corporation
2+
* Copyright (c) 2011-2015, Intel Corporation
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without modification,
@@ -36,13 +36,9 @@ CMappingData::CMappingData()
3636
{
3737
}
3838

39-
bool CMappingData::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
39+
bool CMappingData::init(const std::string &rawMapping, std::string &error)
4040
{
41-
assert(xmlElement.hasAttribute("Mapping"));
42-
43-
std::string strMapping = xmlElement.getAttributeString("Mapping");
44-
45-
Tokenizer mappingTok(strMapping, ",");
41+
Tokenizer mappingTok(rawMapping, ",");
4642

4743
std::string strMappingElement;
4844

@@ -71,7 +67,8 @@ bool CMappingData::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext
7167

7268
if (!addValue(strKey, strValue)) {
7369

74-
serializingContext.setError("Duplicate Mapping data: Unable to process Mapping element key = " + strKey + ", value = " + strValue + " from XML element " + xmlElement.getPath());
70+
error = "Unable to process Mapping element key = " + strKey + ", value = " + strValue +
71+
": Duplicate Mapping data";
7572

7673
return false;
7774
}

parameter/MappingData.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2014, Intel Corporation
2+
* Copyright (c) 2011-2015, Intel Corporation
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without modification,
@@ -29,18 +29,23 @@
2929
*/
3030
#pragma once
3131

32-
#include "XmlSink.h"
3332
#include <string>
3433
#include <map>
3534

36-
class CMappingData : public IXmlSink
35+
class CMappingData
3736
{
3837
typedef std::map<std::string, std::string>::const_iterator KeyToValueMapConstIterator;
3938
public:
4039
CMappingData();
4140

42-
// From IXmlSink
43-
virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
41+
/** Initialize mapping data through a raw value
42+
*
43+
* @param[in] rawMapping the raw mapping data which has to be parsed.
44+
* This raw value is a succession of pair "key:value" separated with comma.
45+
* @param[out] error description of the error if there is one, empty otherwise
46+
* @return true on success, false otherwise
47+
*/
48+
bool init(const std::string &rawMapping, std::string &error);
4449

4550
// Query
4651
bool getValue(const std::string& strkey, const std::string*& pStrValue) const;

parameter/Subsystem.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,15 @@ bool CSubsystem::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext&
118118
CXmlElement childElement;
119119

120120
// Manage mapping attribute
121-
if (xmlElement.hasAttribute("Mapping")) {
121+
std::string rawMapping = xmlElement.getAttributeString("Mapping");
122+
if (!rawMapping.empty()) {
122123

124+
std::string error;
123125
_pMappingData = new CMappingData;
124-
if (!_pMappingData->fromXml(xmlElement, serializingContext)) {
126+
if (!_pMappingData->init(rawMapping, error)) {
125127

128+
serializingContext.setError("Invalid Mapping data from XML element '" +
129+
xmlElement.getPath() + "': " + error);
126130
return false;
127131
}
128132
}

parameter/TypeElement.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2014, Intel Corporation
2+
* Copyright (c) 2011-2015, Intel Corporation
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without modification,
@@ -110,10 +110,14 @@ bool CTypeElement::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext
110110
_uiArrayLength = 0; // Scalar
111111
}
112112
// Manage mapping attribute
113-
if (xmlElement.hasAttribute("Mapping")) {
113+
std::string rawMapping = xmlElement.getAttributeString("Mapping");
114+
if (!rawMapping.empty()) {
114115

115-
if (!getMappingData()->fromXml(xmlElement, serializingContext)) {
116+
std::string error;
117+
if (!getMappingData()->init(rawMapping, error)) {
116118

119+
serializingContext.setError("Invalid Mapping data from XML element '" +
120+
xmlElement.getPath() + "': " + error);
117121
return false;
118122
}
119123
}

0 commit comments

Comments
 (0)