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 
27 namespace 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
91  OperationAnd::getOperationString(const Ice::Current& c)
92  {
93  return "&";
94  }
95 
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
158  OperationOr::getOperationString(const Ice::Current& c)
159  {
160  return "|";
161  }
162 
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
221  OperationNot::getOperationString(const Ice::Current& c)
222  {
223  return "!";
224  }
225 
228  {
229  return new OperationNot(TermImplPtr::dynamicCast(childs.at(0)->ice_clone()));
230  }
231 
233  {
234  opType = eOperationNot;
235  }
236 } // namespace armarx
armarx::OperationAnd::ice_clone
Ice::ObjectPtr ice_clone() const override
Reimplementation of the ice_clone method.
Definition: Operations.cpp:97
armarx::TermImpl::addChild
void addChild(const TermImplBasePtr &child, const Ice::Current &c=Ice::emptyCurrent) override
Add child to term.
Definition: TermImpl.cpp:38
armarx::TermImpl::updateWithData
void updateWithData(const Ice::Current &c=Ice::emptyCurrent) override
Definition: TermImpl.cpp:85
armarx::OperationNot::ice_clone
Ice::ObjectPtr ice_clone() const override
Reimplementation of the ice_clone method.
Definition: Operations.cpp:227
armarx::OperationNot::updateWithData
void updateWithData(const Ice::Current &) override
Definition: Operations.cpp:197
armarx::OperationOr::ice_clone
Ice::ObjectPtr ice_clone() const override
Reimplementation of the ice_clone method.
Definition: Operations.cpp:164
armarx::Operation::Operation
Operation()
Definition: Operations.cpp:35
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::OperationNot::output
void output(std::ostream &out) const override
output operation to stream
Definition: Operations.cpp:210
armarx::OperationNot::update
void update(const Ice::Current &c=Ice::emptyCurrent) override
Implementation for updating this term from its children in the expression tree.
Definition: Operations.cpp:184
armarx::OperationAnd::update
void update(const Ice::Current &c=Ice::emptyCurrent) override
Implementation for updating this term from its children in the expression tree.
Definition: Operations.cpp:50
armarx::OperationOr::OperationOr
OperationOr()
Definition: Operations.cpp:170
IceInternal::Handle< TermImpl >
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::OperationAnd::output
void output(std::ostream &out) const override
output operation to stream
Definition: Operations.cpp:79
armarx::OperationAnd::updateWithData
void updateWithData(const Ice::Current &) override
Definition: Operations.cpp:63
armarx::OperationOr::getOperationString
std::string getOperationString(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve string identifying the operation.
Definition: Operations.cpp:158
armarx::Operation::getOperationType
OperationType getOperationType(const Ice::Current &c=Ice::emptyCurrent) const override
Retrieve the type of the operation.
Definition: Operations.cpp:30
armarx::OperationOr::output
void output(std::ostream &out) const override
output operation to stream
Definition: Operations.cpp:146
armarx::OperationOr::update
void update(const Ice::Current &c=Ice::emptyCurrent) override
Implementation for updating this term from its children in the expression tree.
Definition: Operations.cpp:118
armarx::OperationOr::updateWithData
void updateWithData(const Ice::Current &) override
Definition: Operations.cpp:131
Operations.h
armarx::OperationAnd::OperationAnd
OperationAnd()
Definition: Operations.cpp:103
armarx::OperationNot::getOperationString
std::string getOperationString(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve string identifying the operation.
Definition: Operations.cpp:221
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::OperationNot::OperationNot
OperationNot()
Definition: Operations.cpp:232
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::OperationAnd::getOperationString
std::string getOperationString(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve string identifying the operation.
Definition: Operations.cpp:91
armarx::TermImpl::update
void update(const Ice::Current &c=Ice::emptyCurrent) override
Updates the parent in the expression tree.
Definition: TermImpl.cpp:76