StateUtilFunctions.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 ArmarX::
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 
25 #pragma once
26 
27 
30 #include <ArmarXCore/interface/statechart/StatechartIce.h>
31 
32 #include <string>
33 
34 
35 //! this macro declares a new event-class derived vom Event, to have a compiletime check for typos in events
36 #define DEFINEEVENT(NEWEVENT) struct NEWEVENT : Event{ \
37  NEWEVENT(std::string eventReceiverName): \
38  Event(eventReceiverName, #NEWEVENT){ }\
39  };
40 
41 
42 
43 
44 namespace armarx
45 {
46 
49 
50  enum TransitionErrorType // order of errors is importance
51  {
55  eTransitionNoError // this one must be last
56  };
57 
59  {
61  //! vector to store info data in
62  std::vector<std::string> infos;
63  };
64 }
65 
67 {
69  StringVariantContainerBaseMap getSetValues(const StateParameterMap& paramMap);
70  StringVariantContainerBaseMap getValues(const StateParameterMap& paramMap);
71 
72 
73  /*! \brief Sets all entries of the given dictionary to the stored default values
74 
75  */
76  void unsetParameters(StateParameterMap& paramMap);
77  bool checkForCompleteParameters(const StateParameterMap& paramMap, std::string* logOutput = nullptr);
78 
79 
80  /**
81  * @brief Waits for all ChannelRefs to be initialized in the given Map.
82  *
83  * Times out after some delay.
84  * @param paramMap parameter map, that is to be checked for initialized ChannelRefs
85  * @return true if all ChannelRef are initialized
86  */
87  bool waitForChannelRefs(const StateParameterMap& paramMap);
88 
89  //! \brief Adds the (key,defaulfValue) pair to the event-dictionary. The type of the entry is determined with defaultValue.
90  //! \deprecated
91  bool addToDictionary(EventPtr event, const std::string key, const Variant& value);
92  bool addToDictionary(EventPtr event, const std::string key, const SingleTypeVariantListPtr& valueList);
93  //! \brief Checks whether the maps have equal keys and equal Types.
94  bool equalKeys(const StringVariantContainerBaseMap& dict1, const StringVariantContainerBaseMap& dict2);
95  //! \brief Checks whether the maps have equal keys and equal Types.
96  bool equalKeys(const StateParameterMap& dict1, const StateParameterMap& dict2);
97  //! \brief Clears the destination map and copies the parameters of the source in it.
98  //! The copies have their own memory.
99  void copyDictionary(const StringVariantContainerBaseMap& source, StringVariantContainerBaseMap& destination);
100  //! \brief Clears the destination map and copies the parameters of the source in it.
101  //! The copies have their own memory.
102  void copyDictionary(const StateParameterMap& source, StateParameterMap& destination);
103  //! \brief Clears the destination map and copies the parameters of the source in it.
104  //! The copies have their own memory.
105  void copyDictionary(const StateParameterMap& source, StringVariantContainerBaseMap& destination);
106  //! \brief Clears the destination map and copies the parameters of the source in it.
107  //! The copies have their own memory.
108  void copyDictionary(const StringVariantContainerBaseMap& source, StateParameterMap& destination);
109  //! \brief Tries to fill the destination map with matching entries of the source map. Entries that could not be found, are not changed.
110  void fillDictionary(const StringVariantContainerBaseMap& source, StringVariantContainerBaseMap& destination);
111  //! \brief Tries to fill the destination map with matching entries of the source map. Entries that could not be found, are not changed.
112  void fillDictionary(const StringVariantContainerBaseMap& source, StateParameterMap& destination);
113 
114  //! Converts the map into a string-representation.
115  std::string getDictionaryString(const StringVariantContainerBaseMap& mymap);
116  //! Converts the map into a string-representation.
117  std::string getDictionaryString(const StateParameterMap& mymap);
118 
119  std::string getVariantString(const VariantBasePtr& var, const std::string& name = "");
120  std::string getVariantString(const VariantPtr& var, const std::string& name = "");
121 
122 }
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::StateUtilFunctions::fillDictionary
void fillDictionary(const StringVariantContainerBaseMap &source, StringVariantContainerBaseMap &destination)
Tries to fill the destination map with matching entries of the source map. Entries that could not be ...
Definition: StateUtilFunctions.cpp:155
armarx::StateUtilFunctions::waitForChannelRefs
bool waitForChannelRefs(const StateParameterMap &paramMap)
Waits for all ChannelRefs to be initialized in the given Map.
Definition: StateUtilFunctions.cpp:390
armarx::eTransitionNoError
@ eTransitionNoError
Definition: StateUtilFunctions.h:55
armarx::eTransitionErrorInput
@ eTransitionErrorInput
Definition: StateUtilFunctions.h:54
armarx::TransitionError::errorType
TransitionErrorType errorType
Definition: StateUtilFunctions.h:60
armarx::SingleTypeVariantListPtr
IceInternal::Handle< SingleTypeVariantList > SingleTypeVariantListPtr
Definition: SingleTypeVariantList.h:39
IceInternal::Handle< SingleTypeVariantList >
armarx::eTransitionErrorUndefined
@ eTransitionErrorUndefined
Definition: StateUtilFunctions.h:52
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::StateUtilFunctions::getVariantString
std::string getVariantString(const VariantBasePtr &var, const std::string &name="")
Event.h
armarx::StateUtilFunctions::copyDictionary
void copyDictionary(const StringVariantContainerBaseMap &source, StringVariantContainerBaseMap &destination)
Clears the destination map and copies the parameters of the source in it.
Definition: StateUtilFunctions.cpp:184
armarx::TransitionErrorType
TransitionErrorType
Definition: StateUtilFunctions.h:50
armarx::StateUtilFunctions::equalKeys
bool equalKeys(const StringVariantContainerBaseMap &dict1, const StringVariantContainerBaseMap &dict2)
Checks whether the maps have equal keys and equal Types.
Definition: StateUtilFunctions.cpp:136
armarx::StateUtilFunctions::transitionErrorToString
std::string transitionErrorToString(TransitionErrorType type)
Definition: StateUtilFunctions.cpp:36
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
armarx::TransitionError
Definition: StateUtilFunctions.h:58
armarx::StateUtilFunctions::getDictionaryString
std::string getDictionaryString(const StringVariantContainerBaseMap &mymap)
Converts the map into a string-representation.
Definition: StateUtilFunctions.cpp:232
armarx::StateUtilFunctions::unsetParameters
void unsetParameters(StateParameterMap &paramMap)
Sets all entries of the given dictionary to the stored default values.
Definition: StateUtilFunctions.cpp:450
armarx::eTransitionErrorUnexpectedEvent
@ eTransitionErrorUnexpectedEvent
Definition: StateUtilFunctions.h:53
armarx::StateUtilFunctions::addToDictionary
bool addToDictionary(EventPtr event, const std::string key, const Variant &value)
Adds the (key,defaulfValue) pair to the event-dictionary.
Definition: StateUtilFunctions.cpp:83
armarx::TransitionError::infos
std::vector< std::string > infos
vector to store info data in
Definition: StateUtilFunctions.h:62
armarx::StateUtilFunctions::getValues
StringVariantContainerBaseMap getValues(const StateParameterMap &paramMap)
Definition: StateUtilFunctions.cpp:70
armarx::StateUtilFunctions::getSetValues
StringVariantContainerBaseMap getSetValues(const StateParameterMap &paramMap)
Definition: StateUtilFunctions.cpp:54
Variant.h
armarx::VariantType::SingleTypeVariantList
const VariantTypeId SingleTypeVariantList
Definition: SingleTypeVariantList.h:193
armarx::StateUtilFunctions::checkForCompleteParameters
bool checkForCompleteParameters(const StateParameterMap &paramMap, std::string *logOutput=nullptr)
Definition: StateUtilFunctions.cpp:354
armarx::StateUtilFunctions
Definition: StateUtilFunctions.h:66
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28