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 Operation::getOperationType(const Ice::Current& c) const
30  {
31  return opType;
32  }
33 
35  {
36  type = eOperation;
37  opType = eUndefinedOperation;
38  }
39 
40  // OperationAnd
42  {
43  opType = eOperationAnd;
44  addChild(a);
45  addChild(b);
46  }
47 
48  void OperationAnd::update(const Ice::Current& c)
49  {
50  if (childs.size() != 2)
51  {
52  return;
53  }
54 
55  value = childs.at(0)->getValue() && childs.at(1)->getValue();
56 
58  }
59 
60  void OperationAnd::updateWithData(const Ice::Current&)
61  {
62  if (childs.size() != 2)
63  {
64  return;
65  }
66  datafieldValues = childs.at(0)->getDatafields();
67  auto values2 = childs.at(1)->getDatafields();
68  datafieldValues.insert(values2.begin(), values2.end());
69 
70  value = childs.at(0)->getValue() && childs.at(1)->getValue();
71 
73  }
74 
75  void OperationAnd::output(std::ostream& out) const
76  {
77  if (childs.size() != 2)
78  {
79  return;
80  }
81 
82  out << "(" << TermImplPtr::dynamicCast(childs.at(0)) << " && " << TermImplPtr::dynamicCast(childs.at(1)) << ")";
83  }
84 
85  std::string OperationAnd::getOperationString(const Ice::Current& c)
86  {
87  return "&";
88  }
89 
91  {
92  return new OperationAnd(TermImplPtr::dynamicCast(childs.at(0)->ice_clone()), TermImplPtr::dynamicCast(childs.at(1)->ice_clone()));
93  }
94 
96  {
97  opType = eOperationAnd;
98  }
99 
100  // OperationOr
102  {
103  opType = eOperationOr;
104 
105  addChild(a);
106  addChild(b);
107  }
108 
109  void OperationOr::update(const Ice::Current& c)
110  {
111  if (childs.size() != 2)
112  {
113  return;
114  }
115 
116  value = childs.at(0)->getValue() || childs.at(1)->getValue();
117 
119  }
120 
121  void OperationOr::updateWithData(const Ice::Current&)
122  {
123  if (childs.size() != 2)
124  {
125  return;
126  }
127 
128  value = childs.at(0)->getValue() || childs.at(1)->getValue();
129  datafieldValues = childs.at(0)->getDatafields();
130  auto values2 = childs.at(1)->getDatafields();
131  datafieldValues.insert(values2.begin(), values2.end());
133  }
134 
135  void OperationOr::output(std::ostream& out) const
136  {
137  if (childs.size() != 2)
138  {
139  return;
140  }
141 
142  out << "(" << TermImplPtr::dynamicCast(childs.at(0)) << " || " << TermImplPtr::dynamicCast(childs.at(1)) << ")";
143  }
144 
145  std::string OperationOr::getOperationString(const Ice::Current& c)
146  {
147  return "|";
148  }
149 
151  {
152  return new OperationOr(TermImplPtr::dynamicCast(childs.at(0)->ice_clone()), TermImplPtr::dynamicCast(childs.at(1)->ice_clone()));
153  }
154 
156  {
157  opType = eOperationOr;
158  }
159 
160  // OperationNot
162  {
163  opType = eOperationNot;
164 
165  addChild(a);
166  }
167 
168  void OperationNot::update(const Ice::Current& c)
169  {
170  if (childs.size() != 1)
171  {
172  return;
173  }
174 
175  value = !childs.at(0)->getValue();
176 
178  }
179 
180  void OperationNot::updateWithData(const Ice::Current&)
181  {
182  if (childs.size() != 1)
183  {
184  return;
185  }
186 
187  value = !childs.at(0)->getValue();
188  datafieldValues = childs.at(0)->getDatafields();
190  }
191 
192  void OperationNot::output(std::ostream& out) const
193  {
194  if (childs.size() != 1)
195  {
196  return;
197  }
198 
199  out << "!(" << TermImplPtr::dynamicCast(childs.at(0)) << ")";
200  }
201 
202  std::string OperationNot::getOperationString(const Ice::Current& c)
203  {
204  return "!";
205  }
206 
208  {
209  return new OperationNot(TermImplPtr::dynamicCast(childs.at(0)->ice_clone()));
210  }
211 
213  {
214  opType = eOperationNot;
215  }
216 }
armarx::OperationAnd::ice_clone
Ice::ObjectPtr ice_clone() const override
Reimplementation of the ice_clone method.
Definition: Operations.cpp:90
armarx::TermImpl::addChild
void addChild(const TermImplBasePtr &child, const Ice::Current &c=Ice::emptyCurrent) override
Add child to term.
Definition: TermImpl.cpp:37
armarx::TermImpl::updateWithData
void updateWithData(const Ice::Current &c=Ice::emptyCurrent) override
Definition: TermImpl.cpp:77
armarx::OperationNot::ice_clone
Ice::ObjectPtr ice_clone() const override
Reimplementation of the ice_clone method.
Definition: Operations.cpp:207
armarx::OperationNot::updateWithData
void updateWithData(const Ice::Current &) override
Definition: Operations.cpp:180
armarx::OperationOr::ice_clone
Ice::ObjectPtr ice_clone() const override
Reimplementation of the ice_clone method.
Definition: Operations.cpp:150
armarx::Operation::Operation
Operation()
Definition: Operations.cpp:34
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::OperationNot::output
void output(std::ostream &out) const override
output operation to stream
Definition: Operations.cpp:192
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:168
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:48
armarx::OperationOr::OperationOr
OperationOr()
Definition: Operations.cpp:155
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:926
armarx::OperationAnd::output
void output(std::ostream &out) const override
output operation to stream
Definition: Operations.cpp:75
armarx::OperationAnd::updateWithData
void updateWithData(const Ice::Current &) override
Definition: Operations.cpp:60
armarx::OperationOr::getOperationString
std::string getOperationString(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve string identifying the operation.
Definition: Operations.cpp:145
armarx::Operation::getOperationType
OperationType getOperationType(const Ice::Current &c=Ice::emptyCurrent) const override
Retrieve the type of the operation.
Definition: Operations.cpp:29
armarx::OperationOr::output
void output(std::ostream &out) const override
output operation to stream
Definition: Operations.cpp:135
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:109
armarx::OperationOr::updateWithData
void updateWithData(const Ice::Current &) override
Definition: Operations.cpp:121
Operations.h
armarx::OperationAnd::OperationAnd
OperationAnd()
Definition: Operations.cpp:95
armarx::OperationNot::getOperationString
std::string getOperationString(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve string identifying the operation.
Definition: Operations.cpp:202
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::OperationNot::OperationNot
OperationNot()
Definition: Operations.cpp:212
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::OperationAnd::getOperationString
std::string getOperationString(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve string identifying the operation.
Definition: Operations.cpp:85
armarx::TermImpl::update
void update(const Ice::Current &c=Ice::emptyCurrent) override
Updates the parent in the expression tree.
Definition: TermImpl.cpp:69