Term.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
27
28namespace armarx
29{
31 {
32 termImpl = nullptr;
33 }
34
35 Term::Term(const Term& other)
36 {
37 if (other.termImpl)
38 {
39 this->termImpl = TermImplPtr::dynamicCast(other.termImpl->ice_clone());
40 }
41 else
42 {
43 this->termImpl = nullptr;
44 }
45 }
46
48 {
49 this->termImpl = impl;
50 }
51
52 Term
53 Term::operator&&(const Term& right) const
54 {
55 if (!this->getImpl())
56 {
57 return right;
58 }
59
60 Term opAnd;
61 opAnd.termImpl = new OperationAnd(this->getImpl(), right.getImpl());
62
63 return opAnd;
64 }
65
66 Term
67 Term::operator||(const Term& right) const
68 {
69 if (!this->getImpl())
70 {
71 return right;
72 }
73
74 Term opOr;
75 opOr.termImpl = new OperationOr(this->getImpl(), right.getImpl());
76 return opOr;
77 }
78
79 Term
80 Term::operator!(void) const
81 {
82 if (!this->getImpl())
83 {
84 return *this;
85 }
86
87 Term opNot;
88 opNot.termImpl = new OperationNot(this->getImpl());
89 return opNot;
90 }
91
92 Term&
93 Term::operator=(const Term& right)
94 {
95 if (right.getImpl())
96 {
97 this->termImpl = TermImplPtr::dynamicCast(right.getImpl()->ice_clone());
98 }
99 else
100 {
101 this->termImpl = nullptr;
102 }
103
104 return *this;
105 }
106
109 {
110 return termImpl;
111 }
112
113 Literal::Literal(const std::string& dataFieldIdentifierStr,
114 const std::string& checkName,
115 const VarList& checkParameters)
116 {
117 termImpl = new LiteralImpl(dataFieldIdentifierStr, checkName, toParamList(checkParameters));
118 }
119
120 Literal::Literal(const DataFieldIdentifier& dataFieldIdentifier,
121 const std::string& checkName,
122 const VarList& checkParameters)
123 {
124 termImpl = new LiteralImpl(dataFieldIdentifier, checkName, toParamList(checkParameters));
125 }
126
127 Literal::Literal(const DataFieldIdentifierPtr& dataFieldIdentifier,
128 const std::string& checkName,
129 const VarList& checkParameters)
130 {
131 termImpl = new LiteralImpl(dataFieldIdentifier, checkName, toParamList(checkParameters));
132 }
133
134 Literal::Literal(const DatafieldRefBasePtr& datafieldRef,
135 const std::string& checkName,
136 const VarList& checkParameters)
137 {
138 termImpl = new LiteralImpl(datafieldRef, checkName, toParamList(checkParameters));
139 }
140
141 VarList
143 {
144 return VarList();
145 }
146
147 VarList
149 {
150 VarList list;
151 list.push_back((param1));
152
153 return list;
154 }
155
156 VarList
157 Literal::createParameterList(const Variant& param1, const Variant& param2)
158 {
159 VarList list;
160 list.push_back((param1));
161 list.push_back((param2));
162
163 return list;
164 }
165
166 VarList
168 const Variant& param2,
169 const Variant& param3)
170 {
171 VarList list;
172 list.push_back((param1));
173 list.push_back((param2));
174 list.push_back((param3));
175
176 return list;
177 }
178
179 ParameterList
180 Literal::toParamList(const VarList& varList) const
181 {
182 ParameterList result;
183
184 for (const auto& var : varList)
185 {
186 result.push_back(new Variant(var));
187 }
188
189 return result;
190 }
191} // namespace armarx
DataFieldIdentifier provide the basis to identify data field within a distributed ArmarX scenario.
LiteralImpls are the basic elements for defining conditional expressions.
Definition LiteralImpl.h:59
Literal(const std::string &dataFieldIdentifierStr, const std::string &checkName, const VarList &checkParameters=createParameterList())
Construct a literal using a datafieldidentifier as string.
Definition Term.cpp:113
ParameterList toParamList(const VarList &varList) const
Definition Term.cpp:180
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition Term.cpp:142
OperationAnd implements a logical AND operation within the expression tree.
Definition Operations.h:72
OperationNot implements a logical NOT operation within the expression tree.
Definition Operations.h:178
OperationOr implements a logical OR operation within the expression tree.
Definition Operations.h:125
Terms are part of the user front end of the ArmarX condition mechanism.
Definition Term.h:112
Term operator!(void) const
The logical NOT operator.
Definition Term.cpp:80
TermImplPtr getImpl() const
Retrieve term implementation object as used in the ArmarX Framework in order to build distributed exp...
Definition Term.cpp:108
Term()
Construct an empty term.
Definition Term.cpp:30
TermImplPtr termImpl
Definition Term.h:194
Term operator||(const Term &right) const
The logical OR operator.
Definition Term.cpp:67
Term & operator=(const Term &right)
The assignment operator.
Definition Term.cpp:93
Term operator&&(const Term &right) const
The logical AND operator.
Definition Term.cpp:53
The Variant class is described here: Variants.
Definition Variant.h:224
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< Variant > VarList
Definition Term.h:197
IceInternal::Handle< TermImpl > TermImplPtr
Typedef of TermImplPtr as IceInternal::Handle<TermImpl> for convenience.
Definition TermImpl.h:41
IceInternal::Handle< DataFieldIdentifier > DataFieldIdentifierPtr
Typedef of DataFieldIdentifierPtr as IceInternal::Handle<DataFieldIdentifier> for convenience.