StateParameter.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
18 * @date 2014
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "StateParameter.h"
24 
26 
31 
33 {
34 
36  optional(false)
37  {
38  }
39 
40  void StateParameter::setDefaultValue(const VariantContainerBasePtr& value)
41  {
42  profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())].first = value;
43  }
44 
45  VariantContainerBasePtr StateParameter::getDefaultValue()
46  {
47  return profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())].first;
48  }
49 
50  void StateParameter::setDefaultValueJson(const QString& valueJson)
51  {
52  profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())].second = valueJson;
53  }
54 
56  {
57  return profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())].second;
58  }
59 
60 
62  {
64  p->setDefaultValue(param->defaultValue);
65  JSONObjectPtr json = new JSONObject();
66  std::string typeName;
67  try
68  {
69  if (param->defaultValue)
70  {
71  typeName = VariantContainerType::allTypesToString(param->defaultValue->getContainerType());
72  //std::string dataType = Variant::getDataType(Variant::getTypeId(typeName));
73  p->type = QString::fromStdString(typeName);
74  //p->dataType.fromStdString(dataType);
75  json->serializeIceObject(param->defaultValue);
76  p->setDefaultValueJson(QString::fromStdString(json->asString(false)));
77  }
78  }
79  catch (std::exception& e)
80  {
81  ARMARX_INFO_S << "Default value serialization failed: " << typeName << " - " << e.what();
82  }
83 
84  p->optional = param->optionalParam;
85 
86  return p;
87  }
88 
90  {
91  StateParameterIceBasePtr r = armarx::StateParameter::create();
92  r->defaultValue = param->getDefaultValue();
93  r->optionalParam = param->optional;
94  r->set = false;
95  return r;
96  }
97 
99  {
101  StateParameterMap::const_iterator it = params.begin();
102  for (; it != params.end(); it++)
103  {
104  result[it.key().toStdString()] = ToIceStateParameter(it.value());
105  }
106  return result;
107  }
108 
109 }
armarx::statechartmodel::StateParameter::FromIceStateParameter
static statechartmodel::StateParameterPtr FromIceStateParameter(armarx::StateParameterIceBasePtr param)
Definition: StateParameter.cpp:61
JSONObject.h
VariantContainer.h
armarx::JSONObject
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition: JSONObject.h:43
armarx::statechartmodel::StateParameter::ToIceStateParameterMap
static armarx::StateParameterMap ToIceStateParameterMap(statechartmodel::StateParameterMap params)
Definition: StateParameter.cpp:98
armarx::statechartmodel::StateParameter::profileDefaultValues
StateParameterProfileDefaultValueMap profileDefaultValues
Definition: StateParameter.h:69
armarx::statechartmodel::StateParameter::getDefaultValue
VariantContainerBasePtr getDefaultValue()
Definition: StateParameter.cpp:45
StateParameter.h
IceInternal::Handle< JSONObject >
armarx::statechartmodel::StateParameter::ToIceStateParameter
static armarx::StateParameterIceBasePtr ToIceStateParameter(statechartmodel::StateParameterPtr param)
Definition: StateParameter.cpp:89
armarx::statechartmodel::StateParameter
Definition: StateParameter.h:49
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::statechartmodel
Definition: XmlWriter.h:36
StatechartProfiles.h
armarx::statechartmodel::StateParameterPtr
std::shared_ptr< StateParameter > StateParameterPtr
Definition: StateParameter.h:45
armarx::statechartmodel::StateParameter::StateParameter
StateParameter()
Definition: StateParameter.cpp:35
armarx::StateParameter::create
static StateParameterPtr create()
Definition: StateParameter.cpp:58
armarx::StatechartProfiles::GetRootName
static std::string GetRootName()
Definition: StatechartProfiles.h:78
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
Logging.h
armarx::statechartmodel::StateParameter::setDefaultValue
void setDefaultValue(const VariantContainerBasePtr &value)
Definition: StateParameter.cpp:40
armarx::statechartmodel::StateParameter::setDefaultValueJson
void setDefaultValueJson(const QString &valueJson)
Definition: StateParameter.cpp:50
armarx::statechartmodel::StateParameter::getDefaultValueJson
QString getDefaultValueJson()
Definition: StateParameter.cpp:55
armarx::VariantContainerType::allTypesToString
static std::string allTypesToString(const ContainerTypePtr &type)
Definition: VariantContainer.cpp:232