Operations.cpp
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::Core
19* @author Kai Welke (welke _at_ kit _dot_ edu)
20* @date 2012 Kai Welke
21* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22* GNU General Public License
23*/
24
26
27namespace armarx
28{
29 OperationType
30 Operation::getOperationType(const Ice::Current& c) const
31 {
32 return opType;
33 }
34
36 {
37 type = eOperation;
38 opType = eUndefinedOperation;
39 }
40
41 // OperationAnd
43 {
44 opType = eOperationAnd;
45 addChild(a);
46 addChild(b);
47 }
48
49 void
50 OperationAnd::update(const Ice::Current& c)
51 {
52 if (childs.size() != 2)
53 {
54 return;
55 }
56
57 value = childs.at(0)->getValue() && childs.at(1)->getValue();
58
60 }
61
62 void
63 OperationAnd::updateWithData(const Ice::Current&)
64 {
65 if (childs.size() != 2)
66 {
67 return;
68 }
69 datafieldValues = childs.at(0)->getDatafields();
70 auto values2 = childs.at(1)->getDatafields();
71 datafieldValues.insert(values2.begin(), values2.end());
72
73 value = childs.at(0)->getValue() && childs.at(1)->getValue();
74
76 }
77
78 void
79 OperationAnd::output(std::ostream& out) const
80 {
81 if (childs.size() != 2)
82 {
83 return;
84 }
85
86 out << "(" << TermImplPtr::dynamicCast(childs.at(0)) << " && "
87 << TermImplPtr::dynamicCast(childs.at(1)) << ")";
88 }
89
90 std::string
92 {
93 return "&";
94 }
95
96 Ice::ObjectPtr
98 {
99 return new OperationAnd(TermImplPtr::dynamicCast(childs.at(0)->ice_clone()),
100 TermImplPtr::dynamicCast(childs.at(1)->ice_clone()));
101 }
102
104 {
105 opType = eOperationAnd;
106 }
107
108 // OperationOr
110 {
111 opType = eOperationOr;
112
113 addChild(a);
114 addChild(b);
115 }
116
117 void
118 OperationOr::update(const Ice::Current& c)
119 {
120 if (childs.size() != 2)
121 {
122 return;
123 }
124
125 value = childs.at(0)->getValue() || childs.at(1)->getValue();
126
128 }
129
130 void
131 OperationOr::updateWithData(const Ice::Current&)
132 {
133 if (childs.size() != 2)
134 {
135 return;
136 }
137
138 value = childs.at(0)->getValue() || childs.at(1)->getValue();
139 datafieldValues = childs.at(0)->getDatafields();
140 auto values2 = childs.at(1)->getDatafields();
141 datafieldValues.insert(values2.begin(), values2.end());
143 }
144
145 void
146 OperationOr::output(std::ostream& out) const
147 {
148 if (childs.size() != 2)
149 {
150 return;
151 }
152
153 out << "(" << TermImplPtr::dynamicCast(childs.at(0)) << " || "
154 << TermImplPtr::dynamicCast(childs.at(1)) << ")";
155 }
156
157 std::string
159 {
160 return "|";
161 }
162
163 Ice::ObjectPtr
165 {
166 return new OperationOr(TermImplPtr::dynamicCast(childs.at(0)->ice_clone()),
167 TermImplPtr::dynamicCast(childs.at(1)->ice_clone()));
168 }
169
171 {
172 opType = eOperationOr;
173 }
174
175 // OperationNot
177 {
178 opType = eOperationNot;
179
180 addChild(a);
181 }
182
183 void
184 OperationNot::update(const Ice::Current& c)
185 {
186 if (childs.size() != 1)
187 {
188 return;
189 }
190
191 value = !childs.at(0)->getValue();
192
194 }
195
196 void
197 OperationNot::updateWithData(const Ice::Current&)
198 {
199 if (childs.size() != 1)
200 {
201 return;
202 }
203
204 value = !childs.at(0)->getValue();
205 datafieldValues = childs.at(0)->getDatafields();
207 }
208
209 void
210 OperationNot::output(std::ostream& out) const
211 {
212 if (childs.size() != 1)
213 {
214 return;
215 }
216
217 out << "!(" << TermImplPtr::dynamicCast(childs.at(0)) << ")";
218 }
219
220 std::string
222 {
223 return "!";
224 }
225
226 Ice::ObjectPtr
228 {
229 return new OperationNot(TermImplPtr::dynamicCast(childs.at(0)->ice_clone()));
230 }
231
233 {
234 opType = eOperationNot;
235 }
236} // namespace armarx
constexpr T c
void update(const Ice::Current &c=Ice::emptyCurrent) override
Implementation for updating this term from its children in the expression tree.
void output(std::ostream &out) const override
output operation to stream
std::string getOperationString(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve string identifying the operation.
Ice::ObjectPtr ice_clone() const override
Reimplementation of the ice_clone method.
void updateWithData(const Ice::Current &) override
void update(const Ice::Current &c=Ice::emptyCurrent) override
Implementation for updating this term from its children in the expression tree.
void output(std::ostream &out) const override
output operation to stream
std::string getOperationString(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve string identifying the operation.
Ice::ObjectPtr ice_clone() const override
Reimplementation of the ice_clone method.
void updateWithData(const Ice::Current &) override
void update(const Ice::Current &c=Ice::emptyCurrent) override
Implementation for updating this term from its children in the expression tree.
void output(std::ostream &out) const override
output operation to stream
std::string getOperationString(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve string identifying the operation.
Ice::ObjectPtr ice_clone() const override
Reimplementation of the ice_clone method.
void updateWithData(const Ice::Current &) override
OperationType getOperationType(const Ice::Current &c=Ice::emptyCurrent) const override
Retrieve the type of the operation.
void update(const Ice::Current &c=Ice::emptyCurrent) override
Updates the parent in the expression tree.
Definition TermImpl.cpp:76
void updateWithData(const Ice::Current &c=Ice::emptyCurrent) override
Definition TermImpl.cpp:85
void addChild(const TermImplBasePtr &child, const Ice::Current &c=Ice::emptyCurrent) override
Add child to term.
Definition TermImpl.cpp:38
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< TermImpl > TermImplPtr
Typedef of TermImplPtr as IceInternal::Handle<TermImpl> for convenience.
Definition TermImpl.h:41