|
42 | 42 |
|
43 | 43 | using std::string; |
44 | 44 | using std::list; |
45 | | -using std::ostringstream; |
46 | 45 |
|
47 | 46 | CSubsystem::CSubsystem(const string &strName, core::log::Logger &logger) |
48 | 47 | : base(strName), _pComponentLibrary(new CComponentLibrary), |
@@ -186,38 +185,38 @@ string CSubsystem::formatMappingDataList( |
186 | 185 | { |
187 | 186 | // The list is parsed in reverse order because it has been filled from the leaf to the trunk |
188 | 187 | // of the tree. When formatting the mapping, we want to start from the subsystem level |
189 | | - ostringstream ossStream; |
| 188 | + std::list<string> mappings; |
190 | 189 | list<const CConfigurableElement *>::const_reverse_iterator it; |
191 | 190 | for (it = configurableElementPath.rbegin(); it != configurableElementPath.rend(); ++it) { |
192 | 191 |
|
193 | | - const CInstanceConfigurableElement *pInstanceConfigurableElement = |
194 | | - static_cast<const CInstanceConfigurableElement *>(*it); |
195 | | - |
196 | | - ossStream << pInstanceConfigurableElement->getFormattedMapping() << ", "; |
| 192 | + auto maybeMapping = (*it)->getFormattedMapping(); |
| 193 | + if (not maybeMapping.empty()) { |
| 194 | + mappings.push_back(maybeMapping); |
| 195 | + } |
197 | 196 | } |
198 | | - return ossStream.str(); |
| 197 | + |
| 198 | + return utility::asString(mappings, ", "); |
199 | 199 | } |
200 | 200 |
|
201 | 201 | // Find the CSubystemObject containing a specific CInstanceConfigurableElement |
202 | 202 | const CSubsystemObject *CSubsystem::findSubsystemObjectFromConfigurableElement( |
203 | 203 | const CInstanceConfigurableElement *pInstanceConfigurableElement) const |
204 | 204 | { |
205 | 205 |
|
206 | | - const CSubsystemObject *pSubsystemObject = NULL; |
207 | | - |
208 | 206 | list<CSubsystemObject *>::const_iterator it; |
209 | 207 | for (it = _subsystemObjectList.begin(); it != _subsystemObjectList.end(); ++it) { |
210 | 208 |
|
211 | 209 | // Check if one of the SubsystemObjects is associated with a ConfigurableElement |
212 | 210 | // corresponding to the expected one |
213 | | - pSubsystemObject = *it; |
| 211 | + const CSubsystemObject *pSubsystemObject = *it; |
| 212 | + |
214 | 213 | if (pSubsystemObject->getConfigurableElement() == pInstanceConfigurableElement) { |
215 | 214 |
|
216 | | - break; |
| 215 | + return pSubsystemObject; |
217 | 216 | } |
218 | 217 | } |
219 | 218 |
|
220 | | - return pSubsystemObject; |
| 219 | + return nullptr; |
221 | 220 | } |
222 | 221 |
|
223 | 222 | void CSubsystem::findSubsystemLevelMappingKeyValue( |
@@ -277,14 +276,16 @@ string CSubsystem::getMapping(list<const CConfigurableElement *> &configurableEl |
277 | 276 | // Get the first element, which is the element containing the amended mapping |
278 | 277 | const CInstanceConfigurableElement *pInstanceConfigurableElement = |
279 | 278 | static_cast<const CInstanceConfigurableElement *>(configurableElementPath.front()); |
280 | | - configurableElementPath.pop_front(); |
281 | | - // Now the list only contains elements whose mapping are related to the context |
282 | 279 |
|
283 | 280 | // Format context mapping data |
284 | 281 | string strValue = formatMappingDataList(configurableElementPath); |
285 | 282 |
|
286 | 283 | // Print the mapping of the first node, which corresponds to a SubsystemObject |
287 | | - strValue += getFormattedSubsystemMappingData(pInstanceConfigurableElement); |
| 284 | + auto subsystemObjectAmendedMapping = |
| 285 | + getFormattedSubsystemMappingData(pInstanceConfigurableElement); |
| 286 | + if (not subsystemObjectAmendedMapping.empty()) { |
| 287 | + strValue += ", " + subsystemObjectAmendedMapping; |
| 288 | + } |
288 | 289 |
|
289 | 290 | return strValue; |
290 | 291 | } |
@@ -330,6 +331,15 @@ bool CSubsystem::getMappingData(const std::string &strKey, const std::string *&p |
330 | 331 | return false; |
331 | 332 | } |
332 | 333 |
|
| 334 | +// Returns the formatted mapping |
| 335 | +std::string CSubsystem::getFormattedMapping() const |
| 336 | +{ |
| 337 | + if (!_pMappingData) { |
| 338 | + return ""; |
| 339 | + } |
| 340 | + return _pMappingData->asString(); |
| 341 | +} |
| 342 | + |
333 | 343 | // Mapping generic context handling |
334 | 344 | bool CSubsystem::handleMappingContext(const CConfigurableElement *pConfigurableElement, |
335 | 345 | CMappingContext &context, string &strError) const |
|
0 commit comments