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
30
32{
33
37
38 void
39 StateParameter::setDefaultValue(const VariantContainerBasePtr& value)
40 {
41 profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())].first =
42 value;
43 }
44
45 VariantContainerBasePtr
47 {
48 return profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())]
49 .first;
50 }
51
52 void
53 StateParameter::setDefaultValueJson(const QString& valueJson)
54 {
55 profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())].second =
56 valueJson;
57 }
58
59 QString
61 {
62 return profileDefaultValues[QString::fromUtf8(StatechartProfiles::GetRootName().data())]
63 .second;
64 }
65
67 StateParameter::FromIceStateParameter(armarx::StateParameterIceBasePtr param)
68 {
70 p->setDefaultValue(param->defaultValue);
71 JSONObjectPtr json = new JSONObject();
72 std::string typeName;
73 try
74 {
75 if (param->defaultValue)
76 {
77 typeName =
78 VariantContainerType::allTypesToString(param->defaultValue->getContainerType());
79 //std::string dataType = Variant::getDataType(Variant::getTypeId(typeName));
80 p->type = QString::fromStdString(typeName);
81 //p->dataType.fromStdString(dataType);
82 json->serializeIceObject(param->defaultValue);
83 p->setDefaultValueJson(QString::fromStdString(json->asString(false)));
84 }
85 }
86 catch (std::exception& e)
87 {
88 ARMARX_INFO_S << "Default value serialization failed: " << typeName << " - "
89 << e.what();
90 }
91
92 p->optional = param->optionalParam;
93
94 return p;
95 }
96
97 StateParameterIceBasePtr
99 {
100 StateParameterIceBasePtr r = armarx::StateParameter::create();
101 r->defaultValue = param->getDefaultValue();
102 r->optionalParam = param->optional;
103 r->set = false;
104 return r;
105 }
106
107 armarx::StateParameterMap
109 {
110 armarx::StateParameterMap result;
111 StateParameterMap::const_iterator it = params.begin();
112 for (; it != params.end(); it++)
113 {
114 result[it.key().toStdString()] = ToIceStateParameter(it.value());
115 }
116 return result;
117 }
118
119} // namespace armarx::statechartmodel
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition JSONObject.h:44
static StateParameterPtr create()
static std::string GetRootName()
static std::string allTypesToString(const ContainerTypePtr &type)
StateParameterProfileDefaultValueMap profileDefaultValues
static armarx::StateParameterIceBasePtr ToIceStateParameter(statechartmodel::StateParameterPtr param)
static statechartmodel::StateParameterPtr FromIceStateParameter(armarx::StateParameterIceBasePtr param)
void setDefaultValue(const VariantContainerBasePtr &value)
void setDefaultValueJson(const QString &valueJson)
static armarx::StateParameterMap ToIceStateParameterMap(statechartmodel::StateParameterMap params)
VariantContainerBasePtr getDefaultValue()
#define ARMARX_INFO_S
Definition Logging.h:202
QMap< QString, StateParameterPtr > StateParameterMap
std::shared_ptr< StateParameter > StateParameterPtr
IceInternal::Handle< JSONObject > JSONObjectPtr
Definition JSONObject.h:34