State.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::Statechart
19 * @author Mirko Waechter( mirko.waechter at kit dot edu)
20 * @date 2012
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 #pragma once
25 
26 
27 #include "StateUtil.h"
28 
32 
33 #include <type_traits>
34 
35 
36 namespace armarx
37 {
38  template <class StateType>
40 
41  class RemoteState;
43 
44  class State;
46 
47  /**
48  @class State
49  @ingroup StatechartGrp
50  Class that offers the main functionality needed to create a statechart.
51  Only functions from this class and StateUtility should be used to define
52  custom statecharts.
53  */
54  class State :
55  virtual public StateUtility
56  {
57 
58  protected:
59  State();
60  State(const State& source);
61  State& operator=(const State& source);
62  ~State() override;
63  public:
64  /*! @brief Function to initialize this state. Must be called in the highest
65  * level of the hierarchy - and only there.
66  * @note init() of substates is automatically called.
67  * @param context pointer to a StatechartContext, that holds the objects to
68  * communicate with other components like observers, kinematic unit etc.
69  */
70  bool init(StatechartContextInterface* context, StatechartManager* manager);
71 
72 
73 
74 
75  //! Returns an id to this state, that is guaranteed to be unique in this process.
76  unsigned int getId() const;
77 
78  /**
79  * @brief Getter for the global state identifier string. It contains all parent states
80  * to the top of the statechart including remote states.
81  * Example: RobotControl->Functional->VisualServo
82  */
83  std::string getGlobalIdString() const;
84 
85 
86 
87  /*!
88  * @brief Getter for the initial state. The initial state is automatically entered,
89  * when this state is entered.
90  * @return Shared pointer to the initial state, NULL if not set.
91  * @see setInitState()
92  */
93  StateBasePtr getInitState() const;
94 
95  bool isUnbreakable() const;
96 
97  /*!
98  * @brief getter function to get the map of output parameters
99  * @return returns the reference to this state's output parameters (the complete map)
100  * @see getOutput, setOutput, getInput, getInputParameters
101  */
103 
104  /*!
105  * @brief getOutput can be used to access a specific input parameter.<br/>
106  *
107  * This version is for complex variant types.
108  * @throw InvalidTypeException
109  * @tparam T Type of the requested variant. The return type depends on this.
110  * @param key of the parameter
111  * @return A pointer to the requested value
112  **/
113  template<typename T>
114  typename std::enable_if_t<std::is_base_of_v<VariantDataClass, T>, IceInternal::Handle<T> >
115  getOutput(const std::string& key) const;
116 
117  /*!
118  * @brief getOutput can be used to access a specific input parameter.<br/>
119  *
120  * This version is for basic variant types like int, float, bool, string.
121  * @throw InvalidTypeException
122  * @tparam T Type of the requested variant. The return type depends on this.
123  * @param key of the parameter
124  * @return A copy of the requested value.
125  **/
126  template<typename T>
127  typename std::enable_if_t < !(std::is_base_of_v<VariantDataClass, T> || std::is_base_of_v<VariantContainerBase, T>), T >
128  getOutput(const std::string& key) const;
129 
130 
131  public:
132 
134 
135  /*! @brief Function to add a new substate to this state. Should be called in the defineState()-function.
136 
137  @param derivedState Template parameter that specifies the derived state class of the added state. Must be derived from StateTemplate or class State itself if no further functionality is required.
138  @param stateName String that describes this state. Should be unique in this hierarchy level.
139  @note Can only be called in defineSubstates() (exception otherwise).
140  @returns returns a shared pointer to the created state for convenience. The state is inserted into the std::vector substateList as well.
141  */
142  template <class derivedState>
143  IceInternal::Handle<derivedState> addState(std::string const& stateName = "");
144 
145  /*! @brief Function to add a new remote substate to this state.
146  *
147  * A Remote State is only a placeholder for the real state that is
148  * located in another application. Most functioncalls to a Remote State
149  * are redirected to the state in other application. The interface is
150  * the same as to a normal state.
151  * @param stateName String that describes this state. Must exist on the
152  * specified proxy, otherwise an exception is thrown. It is the name,
153  * that was set by setStateName(stateName) or addState(stateName).
154  * @param proxyName Name of the Ice Proxy, that offers the state
155  * @note Can only be called in defineSubstates() (exception otherwise).
156  * @returns returns a shared pointer to the created state for convenience.
157  * The state is inserted into the std::vector substateList as well.
158  */
159  virtual RemoteStatePtr addRemoteState(std::string stateName, std::string proxyName, std::string instanceName = "");
160 
161  /*! @brief Function to add a new dynamic remote substate to this state.
162 
163  A Dynamic Remote State
164  is only a placeholder for the real state that is located in another
165  application. Most functioncalls to a Remote State are redirected to the
166  state in other application. The interface is the same as to a normal
167  state.<br/>
168  The differene to a Remote State is, that the location of
169  the real state is unspecified until the Dynamic Remote State-onEnter()
170  function is called by the system. The location of the real state must
171  be specified in the input parameters of the state.<br>
172  So the inputparameter map must contain a field 'proxyName' and a field
173  'stateName' with the corresponding values.
174  @note Can only be called in defineSubstates() (exception otherwise).
175  @returns returns a shared pointer to the created state for convenience.
176  The state is inserted into the std::vector substateList as well.
177  */
178  virtual RemoteStatePtr addDynamicRemoteState(std::string instanceName);
179 
180 
181  TransitionIceBase& addTransition(EventPtr event, StateIceBasePtr sourceState,
182  StateIceBasePtr destinationState,
183  ParameterMappingIceBasePtr mappingToNextStatesInput = nullptr,
184  ParameterMappingIceBasePtr mappingToParentStatesLocal = nullptr,
185  ParameterMappingIceBasePtr mappingToParentStatesOutput = nullptr);
186 
187  /*! @brief Function to add a new transition between to substates to this state.
188  @tparam EventType Type of the event that trigers this transition.
189  @param pSourceState Shared pointer to the state, that must be the active state before this transition. OnExit() is called there.
190  @param pDestination Shared pointer to the state, in which this transition will end. OnEnter() is called there.
191  @param pMapping Mapping from the outputDictionary of pSourceState and the eventDictionary to the inputDictionary of pDestinationState
192  @note Can only be called in defineSubstates() (exception otherwise).
193 
194  @return returns reference to added transition
195  */
196  template <class EventType>
197  TransitionIceBase& addTransition(StateIceBasePtr sourceState,
198  StateIceBasePtr destinationState,
199  ParameterMappingIceBasePtr mappingToNextStatesInput = nullptr,
200  ParameterMappingIceBasePtr mappingToParentStatesLocal = nullptr,
201  ParameterMappingIceBasePtr mappingToParentStatesOutput = nullptr);
202 
203  /**
204  * @brief Function to add a new transition from all substates to @p destinationState.
205  * @note Can only be called in defineSubstates() (exception otherwise).
206  *
207  */
208  template <class EventType>
209  TransitionIceBase& addTransitionFromAllStates(
210  StateIceBasePtr destinationState,
211  ParameterMappingIceBasePtr mappingToNextStatesInput = nullptr,
212  ParameterMappingIceBasePtr mappingToParentStatesLocal = nullptr,
213  ParameterMappingIceBasePtr mappingToParentStatesOutput = nullptr);
214 
215  void inheritInputFromSubstate(std::string stateName);
216 
217  /*! @brief Adds a key,type-pair to the input parameters
218  @param key String to describe the parameter
219  @param type Variable that defines the type of this parameter
220  @param optional Flag to indicate whether or not this parameter must be set, when this state is entered
221  @return returns false if the key already exists. The old type resides.
222  @note Can only be called in defineParameters() (exception otherwise).
223 
224  */
225  bool addToInput(const std::string& key, const ContainerType& type, bool optional, VariantContainerBasePtr defaultValue = VariantContainerBasePtr());
226 
227  /*! @brief Adds a new parameter list to the input parameters with a specific type.
228  @param key String to describe the parameter
229  @param type Variable that defines the type of this parameter
230  @param optional Flag to indicate whether or not this parameter must be set, when this state is entered
231  @return returns false if the key already exists. The old type resides.
232  @note Can only be called in defineParameters() (exception otherwise).
233  */
234  bool addToInput(const std::string& key, VariantTypeId type, bool optional, VariantPtr defaultValue = VariantPtr());
235 
236  /*! @brief Adds a key,type-pair to the local parameters
237  @param key String to describe the parameter
238  @param type Variable that defines the type of this parameter
239  @param optional Flag to indicate whether or not this parameter must be set, when this state is entered
240  @return returns false if the key already exists. The old type resides.
241  @note Can only be called in defineParameters() (exception otherwise).
242  */
243  bool addToLocal(const std::string& key, VariantTypeId type, VariantPtr defaultValue = VariantPtr());
244 
245  /*! @brief Adds a new parameter list to the local parameters with a specific type.
246  @param key String to describe the parameter
247  @param type Variable that defines the type of this parameter
248  @param optional Flag to indicate whether or not this parameter must be set, when this state is entered
249  @return returns false if the key already exists. The old type resides.
250  @note Can only be called in defineParameters() (exception otherwise).
251  */
252  bool addToLocal(const std::string& key, const ContainerType& type, VariantContainerBasePtr defaultValue = VariantContainerBasePtr());
253 
254  /*! @brief Adds a key,type-pair to the output parameters
255  @param key String to describe the parameter
256  @param type Variable that defines the type of this parameter
257  @param optional Flag to indicate whether or not this parameter must be set, when this state is entered
258  @return returns false if the key already exists. The old type resides.
259  @note Can only be called in defineParameters() (exception otherwise).
260  */
261  bool addToOutput(const std::string& key, VariantTypeId type, bool optional);
262 
263  /*! @brief Adds a new parameter list to the output parameters with a specific type.
264  @param key String to describe the parameter
265  @param type Variable that defines the type of this parameter
266  @param optional Flag to indicate whether or not this parameter must be set, when this state is entered
267  @return returns false if the key already exists. The old type resides.
268  @note Can only be called in defineParameters() (exception otherwise).
269  */
270  bool addToOutput(const std::string& key, const ContainerType& type, bool optional);
271 
272 
273 
274 
275 
276 
277 
278  //! @brief Generates a new copy of this state with the same statename, substates, transitions, overidden functions etc.
279  StateBasePtr clone() const override;
280  //! @brief Generates a new copy of this state with the same overidden functions. stateName, substates, transition etc. are not set.
281  StateBasePtr createEmptyCopy() const override;
282 
283  //**************************
284  // Getters
285  //**************************
286 
287 
288  /** @brief Returns a new copy of the inputparameters-dictionary, so that the
289  caller cannot modify them (const won't work due to pointers).
290 
291  These values are reset immediately after this state is left (onExit/onBreak
292  was called)
293  * @return new instance of the inputparameters-dictionary
294  **/
296 
297  /*!
298  * @brief getInput can be used to access a specific input parameter.<br/>
299  *
300  * This version is for complex variant types.
301  * @throw InvalidTypeException
302  * @tparam T Type of the requested variant. The return type depends on this.
303  * @param key of the parameter
304  * @return Since the user must not be able to modify the inputparameters
305  * and constant IceSharedPointers are not possible, a copy of the requested
306  * Variant is returned.
307  **/
308  template<typename T>
309  typename std::enable_if_t<std::is_base_of_v<VariantDataClass, T>, IceInternal::Handle<T> >
310  getInput(const std::string& key) const;
311 
312  /*!
313  * @brief getInput can be used to access a specific input parameter.<br/>
314  *
315  * This version is for basic variant types like int, float, bool, string.
316  * @throw InvalidTypeException
317  * @tparam T Type of the requested variant. The return type depends on this.
318  * @param key of the parameter
319  * @return Since the user must not be able to modify the inputparameters
320  * and constant IceSharedPointers are not possible, a copy of the requested
321  * Variant is returned.
322  **/
323  template<typename T>
324  typename std::enable_if_t < !(std::is_base_of_v<VariantDataClass, T> || std::is_base_of_v<VariantContainerBase, T>), T >
325  getInput(const std::string& key) const;
326 
327  /*!
328  * @brief getInput can be used to access a specific input parameter.
329  *
330  * @throw InvalidTypeException
331  * @tparam T Type of the requested variant. The return type depends on this.
332  * @param key of the parameter
333  * @return Since the user must not be able to modify the inputparameters
334  * and constant IceSharedPointers are not possible, a copy of the requested
335  * Variant is returned.
336  */
337  VariantPtr getInput(const std::string& key) const;
338 
339 
340  /*!
341  * @brief Getter for the local parameter map.
342  *
343  * @return returns a reference to the local parameters map.
344  */
346 
347  /*!
348  * @brief getLocal can be used to access a specific input parameter.<br/>
349  *
350  * This version is for complex variant types.
351  * @throw InvalidTypeException
352  * @tparam T Type of the requested variant. The return type depends on this.
353  * @param key of the parameter
354  * @return A pointer to the requested value
355  **/
356  template<typename T>
357  typename std::enable_if_t<std::is_base_of_v<VariantDataClass, T>, IceInternal::Handle<T> >
358  getLocal(const std::string& key) const;
359 
360  /*!
361  * @brief getLocal can be used to access a specific input parameter.<br/>
362  *
363  * This version is for basic variant types like int, float, bool, string.
364  * @throw InvalidTypeException
365  * @tparam T Type of the requested variant. The return type depends on this.
366  * @param key of the parameter
367  * @return A copy of the requested value.
368  **/
369  template<typename T>
370  typename std::enable_if_t < !(std::is_base_of_v<VariantDataClass, T> || std::is_base_of_v<VariantContainerBase, T>), T >
371  getLocal(const std::string& key) const;
372 
373 
374 
375 
376  VariantContainerBasePtr getLocalContainer(std::string const& key);
377 
378 
379 
380  /**
381  * Checks whether a given input parameter is set or not.
382  * @param key Name of the input parameter
383  * @return returns true if the given parameter is set.
384  **/
385  bool isInputParameterSet(const std::string& key) const;
386  bool isLocalParameterSet(const std::string& key) const;
387  bool isOutputParameterSet(const std::string& key) const;
388 
389  //**************************
390  // Setters
391  //**************************
392  /*!
393  * @brief setInput() sets an input parameter.
394  *
395  * @param key of the parameter
396  * @param value of the parameter of any by the Variant supported type
397  */
398  void setInput(std::string const& key, const Variant& value);
399 
400  /*!
401  * @brief setInput() sets an input parameter <b>list</b>.
402  *
403  * @param key of the parameter
404  * @param value of the parameter of any by the Variant supported type
405  */
406  void setInput(std::string const& key, const VariantContainerBase& valueList);
407 
408 
409  /*!
410  * @brief setLocal() sets a local parameter.
411  *
412  * Local means, that this parameter
413  * can be written and read in this state's onEnter(), onBreak(), onEnter() and only
414  * there.
415  *
416  * @param key of the parameter
417  * @param value of the parameter of any by the Variant supported type
418  */
419  void setLocal(std::string const& key, const Variant& value);
420 
421  /*!
422  * @brief setLocal() sets a local parameter <b>list</b>.
423  *
424  * Local means, that this parameter
425  * can be written and read in this state's onEnter(), onBreak(), onEnter() and only
426  * there.
427  *
428  * @param key of the parameter
429  * @param value of the parameter of any by the Variant supported type
430  */
431  void setLocal(std::string const& key, const VariantContainerBase& valueList);
432 
433 
434  /*!
435  * @brief setOuput() sets an output parameter of this state.<br/>
436  *
437  * Can be called in onEnter(), onBreak(), onExit(). Following states
438  * can access this parameter.
439  *
440  * @param key of the parameter
441  * @param value of the parameter of any by the Variant supported type
442  */
443  void setOutput(std::string const& key, const Variant& value);
444 
445  /*!
446  * @brief setOuput() sets an output parameter LIST of this state.<br/>
447  *
448  * Can be called in onEnter(), onBreak(), onExit(). Following states
449  * can access this parameter.
450  *
451  * @param key of the parameter
452  * @param value of the parameter of any by the Variant supported type
453  */
454  void setOutput(std::string const& key, const VariantContainerBase& valueList);
455 
456 
457  /** @brief Sets the initial substate of this state.
458  * This initial state is automatically entered, when the parent state is entered.
459  * On the implicit transition a parameter mapping from the parent's input and
460  * local parameters is done. The mapping can be specified
461  * with setInitialStateMapping()
462  * @param initState: The state that should be the initial state
463  * @param initialStateMapping: A ParameterMapping that maps *this's input to
464  * the state's input in the first parameter(use mapFromParent()). This mapping is
465  * copied and then stored.
466  *
467  * @note Can only be called in defineSubstates() (exception otherwise).
468  *
469  */
471  /*!
472  * @brief With this function the state can be made unbreakable.
473  *
474  * Unbreakable means that a parent state cannot be left, while this state is active.
475  * @param set: Set to true if the state should be made unbreakable
476  */
477  void setUnbreakable(bool setUnbreakable = true);
478 
479  /**
480  * @brief setUseRunFunction can be used to configurate whether the thread
481  * with the async. run-function should be started/used.
482  *
483  * This should be set to false in time-critical states.
484  *
485  * @see StateBase::run(), _baseRun(), _startRun()
486  * @param useRunFuntion
487  */
488  void setUseRunFunction(bool useRunFuntion);
489 
490  /**
491  * @brief Use this function in the onEnter() function, if you want to avoid
492  * that the substates (i.e. the initial state) are entered.
493  */
494  void cancelSubstates();
495 
496  void setStateName(const std::string& newName);
497 
498  void setStateClassNameFromTypeName(const std::string& typeName);
499 
500  public:
501  // /*! @brief Function to jump directly into a state. Should only be called for statemachine-debugging.
502 
503  // @param stateName Name of the target state
504  // @param inputDictionary Dictionary for the state specified by @c stateName. Content is copied to the @c inputDictionary of @c stateName.
505  // */
506  // bool JumpToState(std::string stateName, StringVariantMap inputDictionary);
507 
508  StatePtr operator [](std::string const& stateName);
509 
510  template <class EventType, class StateType> friend class FinalStateBase;
511  template <typename ContextType> friend class RemoteStateOfferer;
512  friend class RemoteStateWrapper;
513  template <class StateType> friend class StateTemplate;
514 
515  private:
516  struct Impl;
517  std::unique_ptr<Impl> simpl;
518  };
519 
520 
521  ///////////////////////////////////////////////////////////////
522  ////// Implementations of State
523  ///////////////////////////////////////////////////////////////
524 
525  template <> StatePtr State::addState<State>(std::string const& stateName);
526 
527  template <class derivedState>
529  {
530  // if the compiler points to the next line, something with the template parameter has been done wrong. see the message-string in the macro for further information
531  static_assert(std::is_same_v<typename derivedState::Type, derivedState>,
532  "The template parameter 'derivedState' must be derived from StateTemplate<derivedState> or the class 'State' itself! It must not inherit from a class that inherits from StateTemplate!");
533 
534 
535  __checkPhase(eSubstatesDefinitions, __PRETTY_FUNCTION__);
536 
537  IceInternal::Handle<derivedState> pNewState = derivedState::createInstance(stateName);
538  // stateName = pNewState->getStateName();
539 
540  addState(pNewState);
541 
542  return pNewState;
543  }
544 
545 
546  template <class EventType>
547  TransitionIceBase& State::addTransition(StateIceBasePtr sourceState,
548  StateIceBasePtr destinationState,
549  ParameterMappingIceBasePtr mappingToNextStatesInput,
550  ParameterMappingIceBasePtr mappingToParentStatesLocal,
551  ParameterMappingIceBasePtr mappingToParentStatesOutput)
552  {
553  return addTransition(createEvent<EventType>(), sourceState, destinationState, mappingToNextStatesInput, mappingToParentStatesLocal, mappingToParentStatesOutput);
554  }
555 
556 
557  template <class EventType>
559  StateIceBasePtr destinationState,
560  ParameterMappingIceBasePtr mappingToNextStatesInput,
561  ParameterMappingIceBasePtr mappingToParentStatesLocal,
562  ParameterMappingIceBasePtr mappingToParentStatesOutput)
563  {
564  __checkPhase(eSubstatesDefinitions, __PRETTY_FUNCTION__);
565  TransitionIceBase t;
566 
567  assert(destinationState._ptr);
568  t.evt = new EventType(EVENTTOALL);
569  t.destinationState = destinationState;
570 
571  if (mappingToNextStatesInput)
572  {
573  t.mappingToNextStatesInput = PMPtr::dynamicCast(mappingToNextStatesInput)->clone();
574  }
575 
576  if (mappingToParentStatesLocal)
577  {
578  t.mappingToParentStatesLocal = PMPtr::dynamicCast(mappingToParentStatesLocal)->clone();
579  }
580 
581  if (mappingToParentStatesOutput)
582  {
583  t.mappingToParentStatesOutput = PMPtr::dynamicCast(mappingToParentStatesOutput)->clone();
584  }
585 
586  t.fromAll = true;
587 
589  throw exceptions::local::eStatechartLogicError("Cannot insert a general transition on event '" + t.evt->eventName
590  + "' from any state to '" + destinationState->stateName + "' into state '" + getStateName() + "'! There already exists a transition to that state on that event.");
591 
592  transitions.push_back(t);
593  return *transitions.rbegin();
594  }
595 
596  template<typename T>
597  typename std::enable_if_t<std::is_base_of_v<VariantDataClass, T>, IceInternal::Handle<T> >
598  State::getInput(const std::string& key) const
599  {
600  __checkPhaseMin(eDefined, __PRETTY_FUNCTION__);
601  VariantContainerBasePtr varContainer;
602  getParameterContainer(inputParameters, key, varContainer);
603  if (varContainer && !SingleVariantPtr::dynamicCast(varContainer)) // we are only interested in real containers, not singlevariant containers
604  {
605  return IceInternal::Handle<T>::dynamicCast(varContainer);
606  }
607  else
608  {
609  VariantPtr var;
610  getParameter(inputParameters, key, var);
611  return IceInternal::Handle<T>::dynamicCast(var->get<T>());
612  }
613  }
614 
615 
616  template<typename T>
617  typename std::enable_if_t < !(std::is_base_of_v<VariantDataClass, T> || std::is_base_of_v<VariantContainerBase, T>), T >
618  State::getInput(const std::string& key) const
619  {
620  __checkPhaseMin(eDefined, __PRETTY_FUNCTION__);
621  VariantPtr var;
622  getParameter(inputParameters, key, var);
623  return var->get<T>();
624  }
625 
626 
627  template<typename T>
628  typename std::enable_if_t<std::is_base_of_v<VariantDataClass, T>, IceInternal::Handle<T> >
629  State::getLocal(const std::string& key) const
630  {
631  __checkPhaseMin(eDefined, __PRETTY_FUNCTION__);
632  VariantContainerBasePtr varContainer;
633  getParameterContainer(localParameters, key, varContainer);
634  if (varContainer && !SingleVariantPtr::dynamicCast(varContainer)) // we are only interested in real containers, not singlevariant containers
635  {
636  return IceInternal::Handle<T>::dynamicCast(varContainer);
637  }
638  else
639  {
640  VariantPtr var;
641  getParameter(localParameters, key, var);
642  return IceInternal::Handle<T>::dynamicCast(var->get<T>());
643  }
644  }
645 
646 
647  template<typename T>
648  typename std::enable_if_t < !(std::is_base_of_v<VariantDataClass, T> || std::is_base_of_v<VariantContainerBase, T>), T >
649  State::getLocal(const std::string& key) const
650  {
651  __checkPhaseMin(eDefined, __PRETTY_FUNCTION__);
652  VariantPtr var;
653  getParameter(localParameters, key, var);
654  return var->get<T>();
655  }
656 
657 
658  template<typename T>
659  typename std::enable_if_t<std::is_base_of_v<VariantDataClass, T>, IceInternal::Handle<T> >
660  State::getOutput(const std::string& key) const
661  {
662  __checkPhaseMin(eDefined, __PRETTY_FUNCTION__);
663  VariantContainerBasePtr varContainer;
664  getParameterContainer(outputParameters, key, varContainer);
665  if (varContainer && !SingleVariantPtr::dynamicCast(varContainer)) // we are only interested in real containers, not singlevariant containers
666  {
667  return IceInternal::Handle<T>::dynamicCast(varContainer);
668  }
669  else
670  {
671  VariantPtr var;
672  getParameter(outputParameters, key, var);
673  return IceInternal::Handle<T>::dynamicCast(var->get<T>());
674  }
675  }
676 
677 
678  template<typename T>
679  typename std::enable_if_t < !(std::is_base_of_v<VariantDataClass, T> || std::is_base_of_v<VariantContainerBase, T>), T >
680  State::getOutput(const std::string& key) const
681  {
682  __checkPhaseMin(eDefined, __PRETTY_FUNCTION__);
683  VariantPtr var;
684  getParameter(outputParameters, key, var);
685  return var->get<T>();
686  }
687 
688 
689 
690 }
armarx::State::isOutputParameterSet
bool isOutputParameterSet(const std::string &key) const
Definition: State.cpp:499
armarx::StateBase::getParameterContainer
void getParameterContainer(const StateParameterMap &paramMap, const std::string &key, VariantContainerBasePtr &valueContainer) const
Definition: StateBase.cpp:714
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::State::getOutputParameters
StateParameterMap & getOutputParameters() override
getter function to get the map of output parameters
Definition: State.cpp:111
armarx::State::Impl
Definition: State.cpp:49
SingleTypeVariantList.h
armarx::FinalStateBase
Definition: FinalState.h:48
armarx::RemoteStateWrapper
Definition: RemoteStateWrapper.h:50
armarx::State::isUnbreakable
bool isUnbreakable() const
Definition: State.cpp:106
armarx::StateTemplate
Definition: State.h:39
armarx::State::setOutput
void setOutput(std::string const &key, const Variant &value)
setOuput() sets an output parameter of this state.
Definition: State.cpp:434
armarx::State::setUseRunFunction
void setUseRunFunction(bool useRunFuntion)
setUseRunFunction can be used to configurate whether the thread with the async.
Definition: State.cpp:344
armarx::State::getInput
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > getInput(const std::string &key) const
getInput can be used to access a specific input parameter.
Definition: State.h:598
armarx::StateBase::__checkPhaseMin
void __checkPhaseMin(StatePhase allowedType, const char *functionName) const
Definition: StateBase.cpp:225
armarx::ParameterMappingPtr
IceInternal::Handle< ParameterMapping > ParameterMappingPtr
Definition: ParameterMapping.h:43
armarx::State::~State
~State() override
Definition: State.cpp:82
armarx::StateBase::getStateName
std::string getStateName() const
getStateName
Definition: StateBase.cpp:523
armarx::StatechartContextInterface
Definition: StatechartContextInterface.h:46
armarx::State::init
bool init(StatechartContextInterface *context, StatechartManager *manager)
Function to initialize this state. Must be called in the highest level of the hierarchy - and only th...
Definition: State.cpp:84
armarx::State::setLocal
void setLocal(std::string const &key, const Variant &value)
setLocal() sets a local parameter.
Definition: State.cpp:417
armarx::exceptions::local::eStatechartLogicError
Definition: Exception.h:30
armarx::StateBase::eDefined
@ eDefined
Definition: StateBase.h:271
armarx::State::setStateName
void setStateName(const std::string &newName)
Definition: State.cpp:355
armarx::State::isInputParameterSet
bool isInputParameterSet(const std::string &key) const
Checks whether a given input parameter is set or not.
Definition: State.cpp:489
armarx::State::addState
StateBasePtr addState(StateBasePtr pNewState)
Definition: State.cpp:135
armarx::State::getGlobalIdString
std::string getGlobalIdString() const
Getter for the global state identifier string.
Definition: State.cpp:96
armarx::State::createEmptyCopy
StateBasePtr createEmptyCopy() const override
Generates a new copy of this state with the same overidden functions. stateName, substates,...
Definition: State.cpp:457
armarx::StateController::__checkExistenceOfTransition
bool __checkExistenceOfTransition(const TransitionIceBase &transition)
Definition: StateController.cpp:631
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::State::cancelSubstates
void cancelSubstates()
Use this function in the onEnter() function, if you want to avoid that the substates (i....
Definition: State.cpp:349
StringValueMap.h
armarx::VariantPtr
IceInternal::Handle< Variant > VariantPtr
Definition: Variant.h:42
armarx::State::setInitState
StateBasePtr setInitState(StateBasePtr initState, ParameterMappingPtr initialStateMapping=ParameterMappingPtr())
Sets the initial substate of this state.
Definition: State.cpp:319
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::RemoteStateOfferer
Class that holds states, which offer functionality for other states over Ice.
Definition: RemoteStateOfferer.h:182
armarx::State::getLocal
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > getLocal(const std::string &key) const
getLocal can be used to access a specific input parameter.
Definition: State.h:629
armarx::State::addToLocal
bool addToLocal(const std::string &key, VariantTypeId type, VariantPtr defaultValue=VariantPtr())
Adds a key,type-pair to the local parameters.
Definition: State.cpp:307
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::State::getLocalParameters
StateParameterMap & getLocalParameters()
Getter for the local parameter map.
Definition: State.cpp:385
armarx::State::setUnbreakable
void setUnbreakable(bool setUnbreakable=true)
With this function the state can be made unbreakable.
Definition: State.cpp:338
armarx::State::addTransition
TransitionIceBase & addTransition(EventPtr event, StateIceBasePtr sourceState, StateIceBasePtr destinationState, ParameterMappingIceBasePtr mappingToNextStatesInput=nullptr, ParameterMappingIceBasePtr mappingToParentStatesLocal=nullptr, ParameterMappingIceBasePtr mappingToParentStatesOutput=nullptr)
Definition: State.cpp:232
armarx::State::State
State()
Definition: State.cpp:56
armarx::RemoteState
This Statetype is used to create a state instance that represents a state that is located in another ...
Definition: RemoteState.h:62
armarx::State::addToInput
bool addToInput(const std::string &key, const ContainerType &type, bool optional, VariantContainerBasePtr defaultValue=VariantContainerBasePtr())
Adds a key,type-pair to the input parameters.
Definition: State.cpp:280
armarx::State::getOutput
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > getOutput(const std::string &key) const
getOutput can be used to access a specific input parameter.
Definition: State.h:660
armarx::State::clone
StateBasePtr clone() const override
Generates a new copy of this state with the same statename, substates, transitions,...
Definition: State.cpp:450
armarx::State::getLocalContainer
VariantContainerBasePtr getLocalContainer(std::string const &key)
Definition: State.cpp:479
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
armarx::State
Definition: State.h:54
armarx::State::inheritInputFromSubstate
void inheritInputFromSubstate(std::string stateName)
Definition: State.cpp:266
armarx::StateUtility
Definition: StateUtil.h:47
armarx::StateBase::eSubstatesDefinitions
@ eSubstatesDefinitions
Definition: StateBase.h:269
armarx::State::addTransitionFromAllStates
TransitionIceBase & addTransitionFromAllStates(StateIceBasePtr destinationState, ParameterMappingIceBasePtr mappingToNextStatesInput=nullptr, ParameterMappingIceBasePtr mappingToParentStatesLocal=nullptr, ParameterMappingIceBasePtr mappingToParentStatesOutput=nullptr)
Function to add a new transition from all substates to destinationState.
Definition: State.h:558
armarx::State::addDynamicRemoteState
virtual RemoteStatePtr addDynamicRemoteState(std::string instanceName)
Function to add a new dynamic remote substate to this state.
Definition: State.cpp:200
armarx::State::getId
unsigned int getId() const
Returns an id to this state, that is guaranteed to be unique in this process.
Definition: State.cpp:91
armarx::State::setStateClassNameFromTypeName
void setStateClassNameFromTypeName(const std::string &typeName)
Definition: State.cpp:360
StateUtil.h
armarx::State::addRemoteState
virtual RemoteStatePtr addRemoteState(std::string stateName, std::string proxyName, std::string instanceName="")
Function to add a new remote substate to this state.
Definition: State.cpp:151
armarx::State::addToOutput
bool addToOutput(const std::string &key, VariantTypeId type, bool optional)
Adds a key,type-pair to the output parameters.
Definition: State.cpp:287
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::State::getInitState
StateBasePtr getInitState() const
Getter for the initial state. The initial state is automatically entered, when this state is entered.
Definition: State.cpp:101
armarx::State::operator=
State & operator=(const State &source)
Definition: State.cpp:74
armarx::State::getInputParameters
StateParameterMap getInputParameters() override
Returns a new copy of the inputparameters-dictionary, so that the caller cannot modify them (const wo...
Definition: State.cpp:366
Variant.h
armarx::State::setInput
void setInput(std::string const &key, const Variant &value)
setInput() sets an input parameter.
Definition: State.cpp:390
armarx::StateBase::__checkPhase
void __checkPhase(StatePhase allowedType, const char *functionName) const
Helper function for checking if a function was called in valid position of the statechart.
Definition: StateBase.cpp:134
armarx::State::isLocalParameterSet
bool isLocalParameterSet(const std::string &key) const
Definition: State.cpp:494
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::StatechartManager
Definition: StatechartManager.h:42
armarx::StateBase::getParameter
void getParameter(const StateParameterMap &paramMap, const std::string &key, VariantPtr &value) const
Definition: StateBase.cpp:801
EVENTTOALL
#define EVENTTOALL
Definition: StateBase.h:42