EntityAttribute.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package MemoryX::WorkingMemory
17* @author ALexey Kozlov ( kozlov at kit dot edu), Kai Welke (welke at kit got edu)
18* @date 2012
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#pragma once
24
25#include <mutex>
26#include <type_traits>
27
30
31#include <MemoryX/interface/core/EntityBase.h>
32
33namespace memoryx
34{
35
36 class EntityAttribute;
37 /**
38 * Typedef of EntityAttributePtr as IceInternal::Handle<EntityAttribute> for convenience.
39 */
41
42 /**
43 * Attribute of MemoryX entities.
44 *
45 * Each memory entity can have an arbitraty number of attributes, identified by their names. Essentially, they are stored as a map std::string -> EntityAttribute.
46 * EntityAttribute has one or many AttributeElements, each of them representing a value with uncertainty as a pair (value, probabilityMeasure).
47 * See documentation of memoryx::AttributeElement for details on what types are supported as values.
48 */
49 class EntityAttribute : public memoryx::EntityAttributeBase
50 {
51 // required for the object factory
52 template <class IceBaseClass, class DerivedClass>
53 friend class ::armarx::GenericFactory;
54
55 public:
56 /** Constructs a new EntityAttribute.
57 *
58 * @param name the attribute is identified via this name
59 **/
60 EntityAttribute(const std::string& name);
61
62 /** Constructs a new EntityAttribute and assigns a value
63 *
64 * @param name the attribute is identified via this name
65 * @param value value for this attribute
66 **/
67 EntityAttribute(const std::string& name, const armarx::VariantBasePtr& val);
68
69 /** Constructs a copy from another EntityAttribute instance.
70 *
71 * @param other EntityAttribute to copy from
72 **/
73 EntityAttribute(const EntityAttribute& other);
74
75 ~EntityAttribute() override;
76
77 /**
78 * Retrieve name of the attribute.
79 *
80 * @return attribute name
81 **/
82 ::std::string getName(const ::Ice::Current& = Ice::emptyCurrent) const override;
83
84 /**
85 * Sets (single) value of the attribute. Uncertainty assumed to be empty (=unknown/not specified).
86 * This is equivalent to clearing the attribute value list (clear()) and calling addValue().
87 *
88 * @param val value to set
89 **/
90 void setValue(const ::armarx::VariantBasePtr& val,
91 const ::Ice::Current& = Ice::emptyCurrent) override;
92
93 /**
94 * Sets (single) value of the attribute along with the corresponding uncertainty.
95 * This is equivalent to clearing the attribute values list (clear()) and calling addValueWithUncertainty().
96 *
97 * @param val value to set
98 * @param uncertainty probability distribution representing the value uncertainty
99 *
100 **/
101 void setValueWithUncertainty(const ::armarx::VariantBasePtr& val,
102 const ::memoryx::ProbabilityMeasureBasePtr& uncertainty,
103 const ::Ice::Current& = Ice::emptyCurrent) override;
104
105 /**
106 * Adds value to the end of attribute values list. Uncertainty assumed to be empty (=unknown/not specified).
107 *
108 * @param val value to add
109 **/
110 void addValue(const ::armarx::VariantBasePtr& val,
111 const ::Ice::Current& = Ice::emptyCurrent) override;
112
113 /**
114 * Adds value along with the corresponding uncertainty to the end of attribute values list.
115 * This is equivalent to clearing the attribute value list (clear()) and calling addValueWithUncertainty().
116 *
117 * @param val value to set
118 * @param uncertainty probability distribution representing the value uncertainty
119 *
120 **/
121 void addValueWithUncertainty(const ::armarx::VariantBasePtr& val,
122 const ::memoryx::ProbabilityMeasureBasePtr& uncertainty,
123 const ::Ice::Current& = Ice::emptyCurrent) override;
124
125 /**
126 * Removes the value at a given index from the list of values stored in the attribute.
127 *
128 * @param index of value
129 **/
130 void removeValueAt(::Ice::Int index, const ::Ice::Current& = Ice::emptyCurrent) override;
131
132 /**
133 * Checks whether the value val is currently stored in the attribute. If attribute stores multiple values,
134 * each of them will be compared with val and in case of at least one match the result will be positive.
135 *
136 * NOTE: currently, this method can be used for String values ONLY! To make it applicable for other datatypes,
137 * general comparison method for armarx::Variant should be implemented in Core first.
138 *
139 * @return true if attribute has a value val, false otherwise
140 **/
141 bool hasValue(const ::armarx::VariantBasePtr& val,
142 const ::Ice::Current& = Ice::emptyCurrent) const override;
143
144 /**
145 * Retrieves the value of the attribute. Corresponds to calling getValueAt(0)
146 *
147 * @return value of attribute
148 **/
149 ::armarx::VariantBasePtr getValue(const ::Ice::Current& = Ice::emptyCurrent) const override;
150
151 /**
152 * Retrieves the uncertainty of the attribute value. Corresponds to calling getUncertaintyAt(0)
153 *
154 * @return uncertainty of attribute value
155 **/
156 ::memoryx::ProbabilityMeasureBasePtr
157 getUncertainty(const ::Ice::Current& = Ice::emptyCurrent) const override;
158
159 /**
160 * Retrieve the value at a given index from the list of values stored in the attribute.
161 *
162 * @param index of value
163 * @return value at index
164 **/
166 getValueAt(::Ice::Int index, const ::Ice::Current& = Ice::emptyCurrent) const override;
167
168 /**
169 * Retrieve the uncertainty of the value at a given index from the list of values stored in the attribute.
170 *
171 * @param index of value
172 * @return uncertainty of value at index
173 **/
174 ::memoryx::ProbabilityMeasureBasePtr
175 getUncertaintyAt(::Ice::Int index,
176 const ::Ice::Current& = Ice::emptyCurrent) const override;
177
178 /**
179 * Sets (single) attribute element (=value+uncertainty) to the attribute.
180 * This is equivalent to clearing the attribute value list (clear()) and calling addValue().
181 *
182 * @param elem attribute element to set
183 **/
184 void setElement(const ::memoryx::AttributeElement& elem,
185 const ::Ice::Current& = Ice::emptyCurrent) override;
186
187 /**
188 * Adds attribute element (=value+uncertainty) to the attribute.
189 *
190 * @param elem attribute element to add
191 **/
192 void addElement(const ::memoryx::AttributeElement& elem,
193 const ::Ice::Current& = Ice::emptyCurrent) override;
194
195 /**
196 * Retrieves the attribute element (=value+uncertainty).
197 * Corresponds to calling getElementAt(0).
198 *
199 * @return uncertainty of attribute value
200 **/
201 ::memoryx::AttributeElement
202 getElement(const ::Ice::Current& = Ice::emptyCurrent) const override;
203
204 /**
205 * Retrieves an attribute element (=value+uncertainty) with a given index.
206 *
207 * @return uncertainty of attribute value
208 **/
209 ::memoryx::AttributeElement
210 getElementAt(::Ice::Int index, const ::Ice::Current& = Ice::emptyCurrent) const override;
211
212 /**
213 * Retrieve number of values stored with the attribute
214 *
215 * @return number of values
216 **/
217 ::Ice::Int size(const ::Ice::Current& = Ice::emptyCurrent) const override;
218
219 /**
220 * Clears all values. The attribute will not contain any value after calling clear.
221 **/
222 void clear(const ::Ice::Current& = Ice::emptyCurrent) override;
223
224
225 // TODO: cloning does not work since clone needs to be called explicilety on each Variant!!!
226 // But need to solve Value issue before cloning
227 Ice::ObjectPtr ice_clone() const override;
228 EntityAttributePtr clone(const Ice::Current& c = Ice::emptyCurrent) const;
229
230 public: // serialization
231 void serialize(const armarx::ObjectSerializerBasePtr& serializer,
232 const ::Ice::Current& = Ice::emptyCurrent) const override;
233 void deserialize(const armarx::ObjectSerializerBasePtr& serializer,
234 const ::Ice::Current& = Ice::emptyCurrent) override;
235
236 protected:
237 mutable std::recursive_mutex valuesMutex;
238
239 private:
240 void output(std::ostream& stream) const;
241
242 public: // streaming operator
243 friend std::ostream&
244 operator<<(std::ostream& stream, const EntityAttribute& rhs)
245 {
246 rhs.output(stream);
247 return stream;
248 }
249
250 friend std::ostream&
251 operator<<(std::ostream& stream, const EntityAttributePtr& rhs)
252 {
253 rhs->output(stream);
254 return stream;
255 }
256
257 friend std::ostream&
258 operator<<(std::ostream& stream, const EntityAttributeBasePtr& rhs)
259 {
260 stream << EntityAttributePtr::dynamicCast(rhs);
261 return stream;
262 }
263
264 private:
266 {
267 }
268 };
269
270} // namespace memoryx
uint8_t index
constexpr T c
Attribute of MemoryX entities.
void setValueWithUncertainty(const ::armarx::VariantBasePtr &val, const ::memoryx::ProbabilityMeasureBasePtr &uncertainty, const ::Ice::Current &=Ice::emptyCurrent) override
Sets (single) value of the attribute along with the corresponding uncertainty.
void removeValueAt(::Ice::Int index, const ::Ice::Current &=Ice::emptyCurrent) override
Removes the value at a given index from the list of values stored in the attribute.
void clear(const ::Ice::Current &=Ice::emptyCurrent) override
Clears all values.
bool hasValue(const ::armarx::VariantBasePtr &val, const ::Ice::Current &=Ice::emptyCurrent) const override
Checks whether the value val is currently stored in the attribute.
void setValue(const ::armarx::VariantBasePtr &val, const ::Ice::Current &=Ice::emptyCurrent) override
Sets (single) value of the attribute.
std::recursive_mutex valuesMutex
friend std::ostream & operator<<(std::ostream &stream, const EntityAttribute &rhs)
::memoryx::AttributeElement getElement(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieves the attribute element (=value+uncertainty).
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
void addValue(const ::armarx::VariantBasePtr &val, const ::Ice::Current &=Ice::emptyCurrent) override
Adds value to the end of attribute values list.
::armarx::VariantBasePtr getValue(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieves the value of the attribute.
Ice::ObjectPtr ice_clone() const override
::memoryx::ProbabilityMeasureBasePtr getUncertaintyAt(::Ice::Int index, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve the uncertainty of the value at a given index from the list of values stored in the attribut...
void setElement(const ::memoryx::AttributeElement &elem, const ::Ice::Current &=Ice::emptyCurrent) override
Sets (single) attribute element (=value+uncertainty) to the attribute.
EntityAttributePtr clone(const Ice::Current &c=Ice::emptyCurrent) const
::memoryx::AttributeElement getElementAt(::Ice::Int index, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieves an attribute element (=value+uncertainty) with a given index.
void addValueWithUncertainty(const ::armarx::VariantBasePtr &val, const ::memoryx::ProbabilityMeasureBasePtr &uncertainty, const ::Ice::Current &=Ice::emptyCurrent) override
Adds value along with the corresponding uncertainty to the end of attribute values list.
::memoryx::ProbabilityMeasureBasePtr getUncertainty(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieves the uncertainty of the attribute value.
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
::armarx::VariantBasePtr getValueAt(::Ice::Int index, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve the value at a given index from the list of values stored in the attribute.
::Ice::Int size(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve number of values stored with the attribute.
void addElement(const ::memoryx::AttributeElement &elem, const ::Ice::Current &=Ice::emptyCurrent) override
Adds attribute element (=value+uncertainty) to the attribute.
EntityAttribute(const std::string &name)
Constructs a new EntityAttribute.
::std::string getName(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve name of the attribute.
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr
VirtualRobot headers.
IceInternal::Handle< EntityAttribute > EntityAttributePtr
Typedef of EntityAttributePtr as IceInternal::Handle<EntityAttribute> for convenience.