TermImpl.h
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
25#pragma once
26
27// ArmarX
30
31// interface
32#include <ArmarXCore/interface/observers/TermImplBase.h>
33
34namespace armarx
35{
36 class TermImpl;
37
38 /**
39 * Typedef of TermImplPtr as IceInternal::Handle<TermImpl> for convenience.
40 */
42
43 /**
44 * @class TermImpl
45 * @ingroup Conditions
46 * TermImpl is the superclass for all implementations of terms in the expression tree, such as LiteralImpl, Operation and ConditionRoot.
47 * The TermImpl is the backend to the API frontend Term. It inherits from Ice::Object in order to allow serialization via
48 * Ice and provides all methods to build an expression tree.
49 *
50 * Each term has a boolean value. Values are updated from the childs in the expression tree by calling update(). Further,
51 * the update method calls the parents state update(). Thus, expression trees consisting of TermImpl are updated from bottom to top.
52 */
53 class ARMARXCORE_IMPORT_EXPORT TermImpl : virtual public TermImplBase
54 {
55 public:
56 /**
57 * Destructor of TermImpl. Assures handling of cyclic IceInternal::Handle dependencies
58 */
59 ~TermImpl() override;
60
61 /**
62 * Add child to term. This is used to generate an expression tree.
63 *
64 * @param child shared pointer to child
65 */
66 void addChild(const TermImplBasePtr& child,
67 const Ice::Current& c = Ice::emptyCurrent) override;
68
69 /**
70 * retrieve childs of this term in the expression tree.
71 *
72 * @return list of child terms
73 */
74 TermImplSequence getChilds(const Ice::Current& c = Ice::emptyCurrent) override;
75
76 /**
77 * retrieve parent of this term in the expression tree. For the root node this is NULL.
78 *
79 * @return shared pointer to parent
80 */
81 TermImplBasePtr getParent(const Ice::Current& c = Ice::emptyCurrent) override;
82
83 /**
84 * retrieve current value of term. Does not evaluate the child nodes.
85 *
86 * @return current value of the term
87 */
88 bool getValue(const Ice::Current& c = Ice::emptyCurrent) const override;
89
90 StringVariantBaseMap getDatafields(const Ice::Current&) const override;
91
92 /**
93 * Retrieve type of term
94 *
95 * @return type of the term
96 */
97 TermType getType(const Ice::Current& c = Ice::emptyCurrent) const override;
98
99 /**
100 * Updates the parent in the expression tree. call update after each change to this->value.
101 */
102 void update(const Ice::Current& c = Ice::emptyCurrent) override;
103
104 void updateWithData(const Ice::Current& c = Ice::emptyCurrent) override;
105
106 /**
107 * output to stream. pure virtual.
108 *
109 * @param stream
110 */
111 virtual void output(std::ostream& out) const = 0;
112
113 /**
114 * Streaming operator for this class
115 *
116 * @param stream stream to output
117 * @param rhs right handside
118 */
119 friend std::ostream&
120 operator<<(std::ostream& stream, const TermImplPtr& rhs)
121 {
122 rhs->output(stream);
123
124 return stream;
125 }
126
127 /**
128 * Streaming operator for this class
129 *
130 * @param stream stream to output
131 * @param rhs right handside
132 */
133 friend std::ostream&
134 operator<<(std::ostream& stream, const TermImpl* rhs)
135 {
136 rhs->output(stream);
137
138 return stream;
139 }
140
141 void removeChildren();
142
143 protected:
144 /**
145 * Sets the parent for this term in the expression tree.
146 *
147 * @param shared pointer to parent
148 */
149 void setParent(const TermImplBasePtr& parent,
150 const Ice::Current& c = Ice::emptyCurrent) override;
151
152 /**
153 * Reset the parent of this term.
154 */
155 void resetParent(const Ice::Current& c = Ice::emptyCurrent) override;
156
157 /**
158 * atomicDecAndTestValue - decrement and test
159 * @v: pointer of type AtomicCounter
160 * @value: value to test for
161 *
162 * Atomically decrements @v by 1 and returns true if the result is value,
163 * or false for all other cases. Note that the guaranteed useful
164 * range of an AtomicCounter is only 24 bits.
165 *
166 * Inlined because this operation is performance critical.
167 */
168 static inline int atomicDecAndTestValue(volatile int* counter, int value);
169
170 /**
171 * Overwritten version of reference counting from GCShared.
172 * Reference counter increment without garbage collection.
173 * Uses Shared::__incRef instead of GCShared::__incRef()
174 *
175 * @see Shared::__incRef()
176 * @see GCShared::__incRef()
177 */
178 void __incRef() override;
179
180 /**
181 * Overwritten version of reference counting from GCShared.
182 * Resolves cyclic dependencies in the tree without makin
183 * use of the garbage collector.
184 *
185 * @see Shared::__decRef()
186 * @see GCShared::__decRef()
187 */
188 void __decRef() override;
189 };
190} // namespace armarx
191extern template class ::IceInternal::Handle<::armarx::TermImpl>;
std::ostream & operator<<(std::ostream &strm, const AbstractInterface &a)
#define ARMARXCORE_IMPORT_EXPORT
constexpr T c
TermImpl is the superclass for all implementations of terms in the expression tree,...
Definition TermImpl.h:54
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
StringVariantBaseMap getDatafields(const Ice::Current &) const override
Definition TermImpl.cpp:64
bool getValue(const Ice::Current &c=Ice::emptyCurrent) const override
retrieve current value of term.
Definition TermImpl.cpp:58
void addChild(const TermImplBasePtr &child, const Ice::Current &c=Ice::emptyCurrent) override
Add child to term.
Definition TermImpl.cpp:38
virtual void output(std::ostream &out) const =0
output to stream.
TermType getType(const Ice::Current &c=Ice::emptyCurrent) const override
Retrieve type of term.
Definition TermImpl.cpp:70
TermImplSequence getChilds(const Ice::Current &c=Ice::emptyCurrent) override
retrieve childs of this term in the expression tree.
Definition TermImpl.cpp:46
TermImplBasePtr getParent(const Ice::Current &c=Ice::emptyCurrent) override
retrieve parent of this term in the expression tree.
Definition TermImpl.cpp:52
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceInternal::Handle< TermImpl > TermImplPtr
Typedef of TermImplPtr as IceInternal::Handle<TermImpl> for convenience.
Definition TermImpl.h:41