36 StatechartContext* ParameterMapping::__context =
nullptr;
38 ParameterMapping::ParameterMapping(
const ParameterMapping&
source) :
41 ParameterMappingIceBase(
source),
52 if (priorities.size() == 0)
59 PriorityMap::reverse_iterator it = priorities.rbegin();
61 for (; it != priorities.rend(); ++it)
63 SourceDictionaryMap::iterator itSourceDict = sourceDictionaries.find(it->second);
65 if (itSourceDict != sourceDictionaries.end())
72 PriorityMap::iterator it = priorities.begin();
76 for (; it != priorities.end(); ++it)
78 __fillFromMappingSource(it->second, targetDictionary);
82 void ParameterMapping::__fillFromMappingSource(MappingSource mappingSource,
StateParameterMap& targetDictionary)
84 if (mappingSource == eDataField)
89 else if (mappingSource == eValue)
99 SourceDictionaryMap::iterator itSourceDict = sourceDictionaries.find(mappingSource);
101 if (itSourceDict != sourceDictionaries.end())
103 for (StateParameterMap::iterator itTargetDict = targetDictionary.begin(); itTargetDict != targetDictionary.end(); itTargetDict++)
106 StringVariantContainerBaseMap::const_iterator itSourceEntry =
_hasMappingEntry(itTargetDict->first, itSourceDict->second, itSourceDict->first);
108 if (itSourceEntry != itSourceDict->second.end())
110 __copyDataFromSourceDict(itSourceEntry, itTargetDict);
118 void ParameterMapping::__copyDataFromSourceDict(StringVariantContainerBaseMap::const_iterator& itSourceEntry, StateParameterMap::iterator itTargetEntry)
120 if (itSourceEntry->second->getSize() > 0)
124 throw exceptions::local::eStatechartLogicError(
"Cannot map different types: " +
127 + itTargetEntry->first
131 + itSourceEntry->first
142 itTargetEntry->second->value = itSourceEntry->second;
148 itTargetEntry->second->set =
true;
153 for (StringVariantContainerBaseMap::const_iterator it = sourceDictionary.begin(); it != sourceDictionary.end(); it++)
156 param->value = it->second->cloneContainer();
157 param->optionalParam =
false;
160 targetDictionary[it->first] = param;
166 std::map<std::string, std::pair < DataFieldIdentifierBaseList, std::vector<StateParameterPtr> > > observerSplittedMap;
169 MappingList::const_iterator itMapping;
171 for (itMapping = mappings.begin(); itMapping != mappings.end(); ++itMapping)
173 if (itMapping->mappingSrc == eDataField)
175 StateParameterMap::iterator itTargetDict = targetDictionary.find(itMapping->targetKey);
177 if (itTargetDict != targetDictionary.end())
181 observerSplittedMap[
id->observerName].first.push_back(
id);
182 observerSplittedMap[
id->observerName].second.push_back(StateParameterPtr::dynamicCast(itTargetDict->second));
188 if (!__context && observerSplittedMap.size() != 0)
190 throw LocalException(
"StatechartContext Pointer is NULL");
193 std::map<std::string, std::pair < DataFieldIdentifierBaseList, std::vector<StateParameterPtr> > >::iterator itObservers = observerSplittedMap.begin();
195 for (; itObservers != observerSplittedMap.end(); ++itObservers)
197 std::string observerName = itObservers->first;
198 std::vector<StateParameterPtr>& paramList = itObservers->second.second;
201 for (
unsigned int i = 0; i < variants.size() && i < paramList.size(); ++i)
203 if (!variants.at(i)->getInitialized())
207 const Variant&
data = *VariantPtr::dynamicCast(variants.at(i));
209 paramList.at(i)->set =
true;
218 MappingList::const_iterator itMapping;
220 for (itMapping = mappings.begin(); itMapping != mappings.end(); ++itMapping)
222 if (itMapping->mappingSrc == eValue)
224 StateParameterMap::iterator itTargetDict = targetDictionary.find(itMapping->targetKey);
226 if (itTargetDict != targetDictionary.end())
228 itTargetDict->second->value = itMapping->value;
229 itTargetDict->second->set =
true;
250 return ParameterMappingPtr::dynamicCast(
ice_clone());
257 useParentsInput = rhs.useParentsInput;
258 __greedyInput = rhs.__greedyInput;
259 priorities = rhs.priorities;
260 mappings = rhs.mappings;
261 sourceDictionaries.clear();
263 for (SourceDictionaryMap::const_iterator it = rhs.sourceDictionaries.begin(); it != rhs.sourceDictionaries.end(); ++it)
273 switch (mappingSource)
297 if (mappingSourceString ==
"Parent")
301 else if (mappingSourceString ==
"Output")
305 else if (mappingSourceString ==
"DataField")
309 else if (mappingSourceString ==
"Event")
313 else if (mappingSourceString ==
"Value")
319 return eMappingSourcesCount;
324 StringVariantContainerBaseMap::const_iterator
ParameterMapping::_hasMappingEntry(
const std::string& keyDestination,
const StringVariantContainerBaseMap& sourceDict, MappingSource allowedMappingSource)
326 StringVariantContainerBaseMap::const_iterator result;
327 Ice::StringSeq fieldsDest =
_getFields(keyDestination);
333 int destWildcardIndex = -1;
334 MappingList::const_iterator it;
336 for (it = mappings.begin(); it != mappings.end(); ++it)
338 if (it->mappingSrc != allowedMappingSource)
344 Ice::StringSeq mappingFields =
_getFields(it->targetKey);
346 for (
unsigned int i = 0; i < fieldsDest.size(); ++i)
348 if (i >= mappingFields.size())
353 if (mappingFields.at(i) ==
"*")
355 destWildcardIndex = i;
359 if (!(mappingFields.at(i) ==
"*" || mappingFields.at(i) == fieldsDest.at(i)))
369 result =
_findSourceEntry(it->sourceKey, sourceDict, destWildcardIndex, fieldsDest);
371 if (result != sourceDict.end())
379 if (it == mappings.end())
381 result = sourceDict.end();
387 StringVariantContainerBaseMap::const_iterator
390 StringVariantContainerBaseMap::const_iterator result = sourceDict.end();
391 Ice::StringSeq mappingFields =
_getFields(sourceKey);
393 for (result = sourceDict.begin(); result != sourceDict.end(); ++result)
395 Ice::StringSeq fieldsSrcDict =
_getFields(result->first);
398 for (
unsigned int i = 0; i < fieldsSrcDict.size(); ++i)
400 if (i >= mappingFields.size())
405 assert(i < fieldsSrcDict.size());
407 if (mappingFields.at(i) ==
"*")
410 for (
int j = 0; j < int(fieldsSrcDict.size()) - int(i); ++j)
412 assert(i + j < fieldsSrcDict.size());
413 assert(destWildcardIndex + j < (
int)fieldsDest.size());
415 if (fieldsSrcDict.at(i + j) != fieldsDest.at(destWildcardIndex + j))
428 else if (mappingFields.at(i) != fieldsSrcDict.at(i))
448 std::vector<std::string> result;
451 while ((pos =
source.find(seperator)) != std::string::npos)
453 result.push_back(
source.substr(0, pos));
463 int lowestPriority = 0;
465 if (priorityMap.begin() != priorityMap.end())
467 lowestPriority = priorityMap.begin()->first;
472 for (
int i = 0; i < (int) eMappingSourcesCount; ++i)
474 PriorityMap::iterator it = priorityMap.begin();
476 for (; it != priorityMap.end(); ++it)
478 if (
int(it->second) == i)
486 priorityMap[--lowestPriority] = MappingSource(i);
505 if (priorities.find(priorityLevel) != priorities.end())
507 std::stringstream stream;
508 stream <<
"Priority level " << priorityLevel <<
" already exists!";
512 priorities[priorityLevel] = mappingSrc;
521 sourceDictionaries[mappingSrc] = sourceDict;
527 if (!
value && mappingSource == eValue)
532 entry.mappingSrc = mappingSource;
533 entry.targetKey = targetKey;
534 entry.sourceKey = sourceKey;
536 mappings.push_back(entry);
597 ParameterMapping::__context = context;
605 for (const ::armarx::MappingEntry& elem : mapping.mappings)