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 
34 namespace 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  */
54  virtual public TermImplBase
55  {
56  public:
57  /**
58  * Destructor of TermImpl. Assures handling of cyclic IceInternal::Handle dependencies
59  */
60  ~TermImpl() override;
61 
62  /**
63  * Add child to term. This is used to generate an expression tree.
64  *
65  * @param child shared pointer to child
66  */
67  void addChild(const TermImplBasePtr& child, 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& operator<<(std::ostream& stream, const TermImplPtr& rhs)
120  {
121  rhs->output(stream);
122 
123  return stream;
124  }
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& operator<<(std::ostream& stream, const TermImpl* rhs)
134  {
135  rhs->output(stream);
136 
137  return stream;
138  }
139 
140  void removeChildren();
141 
142  protected:
143  /**
144  * Sets the parent for this term in the expression tree.
145  *
146  * @param shared pointer to parent
147  */
148  void setParent(const TermImplBasePtr& parent, const Ice::Current& c = Ice::emptyCurrent) override;
149 
150  /**
151  * Reset the parent of this term.
152  */
153  void resetParent(const Ice::Current& c = Ice::emptyCurrent) override;
154 
155  /**
156  * atomicDecAndTestValue - decrement and test
157  * @v: pointer of type AtomicCounter
158  * @value: value to test for
159  *
160  * Atomically decrements @v by 1 and returns true if the result is value,
161  * or false for all other cases. Note that the guaranteed useful
162  * range of an AtomicCounter is only 24 bits.
163  *
164  * Inlined because this operation is performance critical.
165  */
166  static inline int atomicDecAndTestValue(volatile int* counter, int value);
167 
168  /**
169  * Overwritten version of reference counting from GCShared.
170  * Reference counter increment without garbage collection.
171  * Uses Shared::__incRef instead of GCShared::__incRef()
172  *
173  * @see Shared::__incRef()
174  * @see GCShared::__incRef()
175  */
176  void __incRef() override;
177 
178  /**
179  * Overwritten version of reference counting from GCShared.
180  * Resolves cyclic dependencies in the tree without makin
181  * use of the garbage collector.
182  *
183  * @see Shared::__decRef()
184  * @see GCShared::__decRef()
185  */
186  void __decRef() override;
187 
188  };
189 }
190 extern template class ::IceInternal::Handle<::armarx::TermImpl>;
armarx::TermImpl::output
virtual void output(std::ostream &out) const =0
output to stream.
armarx::TermImpl::operator<<
friend std::ostream & operator<<(std::ostream &stream, const TermImplPtr &rhs)
Streaming operator for this class.
Definition: TermImpl.h:119
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
IceInternal::Handle< TermImpl >
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::TermImpl::operator<<
friend std::ostream & operator<<(std::ostream &stream, const TermImpl *rhs)
Streaming operator for this class.
Definition: TermImpl.h:133
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
ImportExport.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
armarx::TermImpl
Definition: TermImpl.h:53
Variant.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28