41 ParameterMappingIceBase(
source),
50 if (priorities.size() == 0)
57 PriorityMap::reverse_iterator it = priorities.rbegin();
59 for (; it != priorities.rend(); ++it)
61 SourceDictionaryMap::iterator itSourceDict = sourceDictionaries.find(it->second);
63 if (itSourceDict != sourceDictionaries.end())
70 PriorityMap::iterator it = priorities.begin();
74 for (; it != priorities.end(); ++it)
76 __fillFromMappingSource(it->second, targetDictionary);
81 ParameterMapping::__fillFromMappingSource(MappingSource mappingSource,
82 StateParameterMap& targetDictionary)
84 if (mappingSource == eDataField)
87 _fillFromDataField(targetDictionary);
89 else if (mappingSource == eValue)
92 _fillFromValues(targetDictionary);
99 SourceDictionaryMap::iterator itSourceDict = sourceDictionaries.find(mappingSource);
101 if (itSourceDict != sourceDictionaries.end())
103 for (StateParameterMap::iterator itTargetDict = targetDictionary.begin();
104 itTargetDict != targetDictionary.end();
108 StringVariantContainerBaseMap::const_iterator itSourceEntry = _hasMappingEntry(
109 itTargetDict->first, itSourceDict->second, itSourceDict->first);
111 if (itSourceEntry != itSourceDict->second.end())
113 __copyDataFromSourceDict(itSourceEntry, itTargetDict);
121 ParameterMapping::__copyDataFromSourceDict(
122 StringVariantContainerBaseMap::const_iterator& itSourceEntry,
123 StateParameterMap::iterator itTargetEntry)
125 if (itSourceEntry->second->getSize() > 0)
127 if (!VariantContainerType::compare(itTargetEntry->second->value->getContainerType(),
128 itSourceEntry->second->getContainerType()))
130 throw exceptions::local::eStatechartLogicError(
131 "Cannot map different types: " +
132 VariantContainerType::allTypesToString(
133 itTargetEntry->second->value->getContainerType()) +
134 " (" + itTargetEntry->first +
") vs. " +
135 VariantContainerType::allTypesToString(
136 itSourceEntry->second->getContainerType()) +
137 " (" + itSourceEntry->first +
")");
147 itTargetEntry->second->value = itSourceEntry->second;
151 itTargetEntry->second->set =
true;
156 StringVariantContainerBaseMap& sourceDictionary)
158 for (StringVariantContainerBaseMap::const_iterator it = sourceDictionary.begin();
159 it != sourceDictionary.end();
163 param->value = it->second->cloneContainer();
164 param->optionalParam =
false;
167 targetDictionary[it->first] = param;
174 std::map<std::string,
175 std::pair<DataFieldIdentifierBaseList, std::vector<StateParameterPtr>>>
179 MappingList::const_iterator itMapping;
181 for (itMapping = mappings.begin(); itMapping != mappings.end(); ++itMapping)
183 if (itMapping->mappingSrc == eDataField)
185 StateParameterMap::iterator itTargetDict =
186 targetDictionary.find(itMapping->targetKey);
188 if (itTargetDict != targetDictionary.end())
192 observerSplittedMap[
id->observerName].first.push_back(
id);
193 observerSplittedMap[
id->observerName].second.push_back(
194 StateParameterPtr::dynamicCast(itTargetDict->second));
200 if (!__context && observerSplittedMap.size() != 0)
202 throw LocalException(
"StatechartContext Pointer is NULL");
205 std::map<std::string,
206 std::pair<DataFieldIdentifierBaseList, std::vector<StateParameterPtr>>>::iterator
207 itObservers = observerSplittedMap.begin();
209 for (; itObservers != observerSplittedMap.end(); ++itObservers)
211 std::string observerName = itObservers->first;
212 std::vector<StateParameterPtr>& paramList = itObservers->second.second;
213 TimedVariantBaseList variants =
214 __context->getDataListFromObserver(observerName, itObservers->second.first);
216 for (
unsigned int i = 0; i < variants.size() && i < paramList.size(); ++i)
218 if (!variants.at(i)->getInitialized())
222 const Variant&
data = *VariantPtr::dynamicCast(variants.at(i));
224 paramList.at(i)->set =
true;
232 MappingList::const_iterator itMapping;
234 for (itMapping = mappings.begin(); itMapping != mappings.end(); ++itMapping)
236 if (itMapping->mappingSrc == eValue)
238 StateParameterMap::iterator itTargetDict =
239 targetDictionary.find(itMapping->targetKey);
241 if (itTargetDict != targetDictionary.end())
243 itTargetDict->second->value = itMapping->value;
244 itTargetDict->second->set =
true;
259 Ice::ObjectPtr ptr =
new ParameterMapping(*
this);
266 return ParameterMappingPtr::dynamicCast(
ice_clone());
274 useParentsInput = rhs.useParentsInput;
275 __greedyInput = rhs.__greedyInput;
276 priorities = rhs.priorities;
277 mappings = rhs.mappings;
278 sourceDictionaries.clear();
280 for (SourceDictionaryMap::const_iterator it = rhs.sourceDictionaries.begin();
281 it != rhs.sourceDictionaries.end();
293 switch (mappingSource)
318 if (mappingSourceString ==
"Parent")
322 else if (mappingSourceString ==
"Output")
326 else if (mappingSourceString ==
"DataField")
330 else if (mappingSourceString ==
"Event")
334 else if (mappingSourceString ==
"Value")
340 return eMappingSourcesCount;
344 StringVariantContainerBaseMap::const_iterator
346 const StringVariantContainerBaseMap& sourceDict,
347 MappingSource allowedMappingSource)
349 StringVariantContainerBaseMap::const_iterator result;
350 Ice::StringSeq fieldsDest =
_getFields(keyDestination);
356 int destWildcardIndex = -1;
357 MappingList::const_iterator it;
359 for (it = mappings.begin(); it != mappings.end(); ++it)
361 if (it->mappingSrc != allowedMappingSource)
367 Ice::StringSeq mappingFields =
_getFields(it->targetKey);
369 for (
unsigned int i = 0; i < fieldsDest.size(); ++i)
371 if (i >= mappingFields.size())
376 if (mappingFields.at(i) ==
"*")
378 destWildcardIndex = i;
382 if (!(mappingFields.at(i) ==
"*" || mappingFields.at(i) == fieldsDest.at(i)))
392 result =
_findSourceEntry(it->sourceKey, sourceDict, destWildcardIndex, fieldsDest);
394 if (result != sourceDict.end())
401 if (it == mappings.end())
403 result = sourceDict.end();
409 StringVariantContainerBaseMap::const_iterator
411 const StringVariantContainerBaseMap& sourceDict,
412 int destWildcardIndex,
413 const Ice::StringSeq& fieldsDest)
415 StringVariantContainerBaseMap::const_iterator result = sourceDict.end();
416 Ice::StringSeq mappingFields =
_getFields(sourceKey);
418 for (result = sourceDict.begin(); result != sourceDict.end(); ++result)
420 Ice::StringSeq fieldsSrcDict =
_getFields(result->first);
423 for (
unsigned int i = 0; i < fieldsSrcDict.size(); ++i)
425 if (i >= mappingFields.size())
430 assert(i < fieldsSrcDict.size());
432 if (mappingFields.at(i) ==
"*")
435 for (
int j = 0; j < int(fieldsSrcDict.size()) - int(i); ++j)
437 assert(i + j < fieldsSrcDict.size());
438 assert(destWildcardIndex + j < (
int)fieldsDest.size());
440 if (fieldsSrcDict.at(i + j) != fieldsDest.at(destWildcardIndex + j))
453 else if (mappingFields.at(i) != fieldsSrcDict.at(i))
472 std::vector<std::string> result;
475 while ((pos = source.find(seperator)) != std::string::npos)
477 result.push_back(source.substr(0, pos));
478 source = source.substr(pos + 1);
481 result.push_back(source);
488 int lowestPriority = 0;
490 if (priorityMap.begin() != priorityMap.end())
492 lowestPriority = priorityMap.begin()->first;
497 for (
int i = 0; i < (int)eMappingSourcesCount; ++i)
499 PriorityMap::iterator it = priorityMap.begin();
501 for (; it != priorityMap.end(); ++it)
503 if (
int(it->second) == i)
511 priorityMap[--lowestPriority] = MappingSource(i);
530 MappingSource mappingSrc,
531 const Ice::Current&
c)
533 if (priorities.find(priorityLevel) != priorities.end())
535 std::stringstream stream;
536 stream <<
"Priority level " << priorityLevel <<
" already exists!";
540 priorities[priorityLevel] = mappingSrc;
546 const StringVariantContainerBaseMap& sourceDict,
547 const Ice::Current&
c)
550 sourceDictionaries[mappingSrc] = sourceDict;
556 const std::string& sourceKey,
557 const std::string& targetKey,
558 VariantContainerBasePtr value)
560 if (!value && mappingSource == eValue)
565 entry.mappingSrc = mappingSource;
566 entry.targetKey = targetKey;
567 entry.sourceKey = sourceKey;
569 mappings.push_back(entry);
581 const std::string& targetKey,
582 const Ice::Current&
c)
597 const std::string& targetKey,
598 const Ice::Current&
c)
613 const std::string& targetKey,
614 const Ice::Current&
c)
629 const std::string& targetKey,
630 const Ice::Current&
c)
647 ParameterMapping::__context = context;
654 for (const ::armarx::MappingEntry& elem : mapping.mappings)
657 << elem.sourceKey <<
" -> " << elem.targetKey <<
"\n";
DataFieldIdentifier provide the basis to identify data field within a distributed ArmarX scenario.
Base Class for all Logging classes.
This class maps parameters from several source dictionaries to one input dictionary.
void _fillFromValues(StateParameterMap &targetDictionary)
void _greedyMapping(StateParameterMap &targetDictionary, StringVariantContainerBaseMap &sourceDictionary)
ParameterMappingPtr mapFromParent(const std::string &parentKey, const std::string &targetKey, const Ice::Current &c=Ice::emptyCurrent)
Adds an entry to the ParameterMapping, that maps the sourceKey's value from the parent's input parame...
static void _setStatechartContext(StatechartContext *__context)
ParameterMappingPtr setTargetDictToGreedy(bool on=true)
Sets the behaviour of the mapping into the target dictionary to greedy.
virtual ParameterMappingPtr clone() const
Returns a new instance of ParameterMapping with the contents of this instance.
void _applyMapping(StateParameterMap &targetDictionary)
This function applies a given mapping to the given inputdictionary.
void _fillFromDataField(StateParameterMap &targetDictionary)
ParameterMapping & operator=(const ParameterMapping &rhs)
ParameterMappingPtr mapFromOutput(const std::string &sourceKey, const std::string &targetKey, const Ice::Current &c=Ice::emptyCurrent)
Adds an entry to the ParameterMapping, that maps the sourceKey's value from the output parameters of ...
static void _addMissingSources(PriorityMap &priorityMap)
ParameterMappingPtr setSourcePriority(int priorityLevel, MappingSource mappingSrc, const Ice::Current &c=Ice::emptyCurrent)
Adds a priority for a specific source dictionary to the mapping.
StringVariantContainerBaseMap::const_iterator _findSourceEntry(const std::string sourceKey, const StringVariantContainerBaseMap &sourceDict, int destWildcardIndex, const Ice::StringSeq &fieldsDest)
StringVariantContainerBaseMap::const_iterator _hasMappingEntry(const std::string &keyDestination, const StringVariantContainerBaseMap &sourceDict, MappingSource allowedMappingSource)
Checks wether the mapping has an entry like keyDestination that maps onto a parameter of mapSource.
void addMappingEntry(MappingSource mappingSource, const std::string &sourceKey, const std::string &targetKey, VariantContainerBasePtr value=nullptr)
static Ice::StringSeq _getFields(std::string source, char seperator='.')
Takes a string and seperates the string by the seperator-char.
friend class StatechartContext
static std::string MappingSourceToString(MappingSource mappingSource)
ParameterMappingPtr mapFromEvent(const std::string &eventKey, const std::string &targetKey, const Ice::Current &c=Ice::emptyCurrent)
Adds an entry to the ParameterMapping, that maps the sourceKey's value from the event parameters of t...
::Ice::ObjectPtr ice_clone() const override
Returns a new instance of ParameterMapping with the contents of this instance.
ParameterMappingPtr _addSourceDictionary(MappingSource mappingSrc, const StringVariantContainerBaseMap &sourceDict, const Ice::Current &c=Ice::emptyCurrent)
ParameterMappingPtr mapFromDataField(const DataFieldIdentifierBasePtr &dataFieldIdentifier, const std::string &targetKey, const Ice::Current &c=Ice::emptyCurrent)
Adds an entry to the ParameterMapping, that maps the value of the datafield entry to the targetKey's ...
static ParameterMappingPtr createMapping()
Creates a new instance of a ParameterMapping. Since the constructors are private, this method must be...
static MappingSource StringToMappingSource(const std::string &mappingSourceString)
The SingleVariant class is required to store single Variant instances in VariantContainer subclasses.
static StateParameterPtr create()
This class contains a statechart and provides the interfaces to distributed components.
The Variant class is described here: Variants.
void copyDictionary(const StringVariantContainerBaseMap &source, StringVariantContainerBaseMap &destination)
Clears the destination map and copies the parameters of the source in it.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< StateParameter > StateParameterPtr
IceInternal::Handle< DataFieldIdentifierBase > DataFieldIdentifierBasePtr
IceInternal::Handle< DataFieldIdentifier > DataFieldIdentifierPtr
Typedef of DataFieldIdentifierPtr as IceInternal::Handle<DataFieldIdentifier> for convenience.
IceInternal::Handle< ParameterMapping > ParameterMappingPtr
ParameterMappingPtr createMapping()
Returns a new and empty instance of ParameterMapping.
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
ARMARXCORE_IMPORT_EXPORT ostream & operator<<(ostream &stream, const armarx::RunningTaskIceBase &task)