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 <MemoryX/interface/core/EntityBase.h>
28 
29 #include <type_traits>
30 #include <mutex>
31 
32 namespace memoryx
33 {
34 
35  class EntityAttribute;
40 
49  public memoryx::EntityAttributeBase
50  {
51  // required for the object factory
52  template <class IceBaseClass, class DerivedClass>
53  friend class ::armarx::GenericFactory;
54  public:
59  EntityAttribute(const std::string& name);
60 
66  EntityAttribute(const std::string& name, const armarx::VariantBasePtr& val);
67 
72  EntityAttribute(const EntityAttribute& other);
73 
74  ~EntityAttribute() override;
75 
81  ::std::string getName(const ::Ice::Current& = Ice::emptyCurrent) const override;
82 
89  void setValue(const ::armarx::VariantBasePtr& val, const ::Ice::Current& = Ice::emptyCurrent) override;
90 
100  const ::memoryx::ProbabilityMeasureBasePtr& uncertainty, const ::Ice::Current& = Ice::emptyCurrent) override;
101 
107  void addValue(const ::armarx::VariantBasePtr& val, const ::Ice::Current& = Ice::emptyCurrent) override;
108 
118  const ::memoryx::ProbabilityMeasureBasePtr& uncertainty, const ::Ice::Current& = Ice::emptyCurrent) override;
119 
125  void removeValueAt(::Ice::Int index, const ::Ice::Current& = Ice::emptyCurrent) override;
126 
136  bool hasValue(const ::armarx::VariantBasePtr& val, const ::Ice::Current& = Ice::emptyCurrent) const override;
137 
143  ::armarx::VariantBasePtr getValue(const ::Ice::Current& = Ice::emptyCurrent) const override;
144 
150  ::memoryx::ProbabilityMeasureBasePtr getUncertainty(const ::Ice::Current& = Ice::emptyCurrent) const override;
151 
158  ::armarx::VariantBasePtr getValueAt(::Ice::Int index, const ::Ice::Current& = Ice::emptyCurrent) const override;
159 
166  ::memoryx::ProbabilityMeasureBasePtr getUncertaintyAt(::Ice::Int index, const ::Ice::Current& = Ice::emptyCurrent) const override;
167 
174  void setElement(const ::memoryx::AttributeElement& elem, const ::Ice::Current& = Ice::emptyCurrent) override;
175 
181  void addElement(const ::memoryx::AttributeElement& elem, const ::Ice::Current& = Ice::emptyCurrent) override;
182 
189  ::memoryx::AttributeElement getElement(const ::Ice::Current& = Ice::emptyCurrent) const override;
190 
196  ::memoryx::AttributeElement getElementAt(::Ice::Int index, const ::Ice::Current& = Ice::emptyCurrent) const override;
197 
203  ::Ice::Int size(const ::Ice::Current& = Ice::emptyCurrent) const override;
204 
208  void clear(const ::Ice::Current& = Ice::emptyCurrent) override;
209 
210 
211 
212  // TODO: cloning does not work since clone needs to be called explicilety on each Variant!!!
213  // But need to solve Value issue before cloning
214  Ice::ObjectPtr ice_clone() const override;
215  EntityAttributePtr clone(const Ice::Current& c = Ice::emptyCurrent) const;
216 
217  public: // serialization
218  void serialize(const armarx::ObjectSerializerBasePtr& serializer, const ::Ice::Current& = Ice::emptyCurrent) const override;
219  void deserialize(const armarx::ObjectSerializerBasePtr& serializer, const ::Ice::Current& = Ice::emptyCurrent) override;
220 
221  protected:
222  mutable std::recursive_mutex valuesMutex;
223 
224  private:
225  void output(std::ostream& stream) const;
226 
227  public: // streaming operator
228  friend std::ostream& operator<<(std::ostream& stream, const EntityAttribute& rhs)
229  {
230  rhs.output(stream);
231  return stream;
232  }
233 
234  friend std::ostream& operator<<(std::ostream& stream, const EntityAttributePtr& rhs)
235  {
236  rhs->output(stream);
237  return stream;
238  }
239 
240  friend std::ostream& operator<<(std::ostream& stream, const EntityAttributeBasePtr& rhs)
241  {
242  stream << EntityAttributePtr::dynamicCast(rhs);
243  return stream;
244  }
245 
246  private:
248  {
249  }
250  };
251 
252 }
253 
memoryx::EntityAttribute::hasValue
bool hasValue(const ::armarx::VariantBasePtr &val, const ::Ice::Current &=Ice::emptyCurrent) const override
Checks whether the value val is currently stored in the attribute.
Definition: EntityAttribute.cpp:155
memoryx::EntityAttribute::getUncertaintyAt
::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...
Definition: EntityAttribute.cpp:194
memoryx::EntityAttribute::getUncertainty
::memoryx::ProbabilityMeasureBasePtr getUncertainty(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieves the uncertainty of the attribute value.
Definition: EntityAttribute.cpp:183
memoryx::EntityAttribute::addValueWithUncertainty
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.
Definition: EntityAttribute.cpp:137
armarx::VariantBasePtr
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr
Definition: ManagedIceObject.h:111
memoryx::EntityAttribute::addElement
void addElement(const ::memoryx::AttributeElement &elem, const ::Ice::Current &=Ice::emptyCurrent) override
Adds attribute element (=value+uncertainty) to the attribute.
Definition: EntityAttribute.cpp:220
memoryx::EntityAttribute::removeValueAt
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.
Definition: EntityAttribute.cpp:202
memoryx::EntityAttribute::getValue
::armarx::VariantBasePtr getValue(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieves the value of the attribute.
Definition: EntityAttribute.cpp:178
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
memoryx::EntityAttribute::getName
::std::string getName(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve name of the attribute.
Definition: EntityAttribute.cpp:82
FactoryCollectionBase.h
memoryx::EntityAttribute::getElement
::memoryx::AttributeElement getElement(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieves the attribute element (=value+uncertainty).
Definition: EntityAttribute.cpp:226
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::EntityAttribute::getElementAt
::memoryx::AttributeElement getElementAt(::Ice::Int index, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieves an attribute element (=value+uncertainty) with a given index.
Definition: EntityAttribute.cpp:231
memoryx::EntityAttribute::operator<<
friend std::ostream & operator<<(std::ostream &stream, const EntityAttributeBasePtr &rhs)
Definition: EntityAttribute.h:240
memoryx::EntityAttribute::operator<<
friend std::ostream & operator<<(std::ostream &stream, const EntityAttributePtr &rhs)
Definition: EntityAttribute.h:234
memoryx::EntityAttribute::getValueAt
::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.
Definition: EntityAttribute.cpp:188
memoryx::EntityAttribute::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: EntityAttribute.cpp:249
memoryx::EntityAttribute::setElement
void setElement(const ::memoryx::AttributeElement &elem, const ::Ice::Current &=Ice::emptyCurrent) override
Sets (single) attribute element (=value+uncertainty) to the attribute.
Definition: EntityAttribute.cpp:212
memoryx::EntityAttribute::serialize
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: EntityAttribute.cpp:280
memoryx::EntityAttribute::operator<<
friend std::ostream & operator<<(std::ostream &stream, const EntityAttribute &rhs)
Definition: EntityAttribute.h:228
memoryx::EntityAttribute::deserialize
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: EntityAttribute.cpp:302
memoryx::EntityAttribute::addValue
void addValue(const ::armarx::VariantBasePtr &val, const ::Ice::Current &=Ice::emptyCurrent) override
Adds value to the end of attribute values list.
Definition: EntityAttribute.cpp:132
memoryx::EntityAttribute::~EntityAttribute
~EntityAttribute() override
Definition: EntityAttribute.cpp:74
memoryx::EntityAttribute::clone
EntityAttributePtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: EntityAttribute.cpp:254
memoryx::EntityAttribute::size
::Ice::Int size(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve number of values stored with the attribute.
Definition: EntityAttribute.cpp:237
memoryx::EntityAttribute
Attribute of MemoryX entities.
Definition: EntityAttribute.h:48
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
memoryx::EntityAttribute::setValueWithUncertainty
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.
Definition: EntityAttribute.cpp:103
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:37
memoryx::EntityAttribute::clear
void clear(const ::Ice::Current &=Ice::emptyCurrent) override
Clears all values.
Definition: EntityAttribute.cpp:243
Variant.h
memoryx::EntityAttribute::setValue
void setValue(const ::armarx::VariantBasePtr &val, const ::Ice::Current &=Ice::emptyCurrent) override
Sets (single) value of the attribute.
Definition: EntityAttribute.cpp:87
memoryx::EntityAttribute::valuesMutex
std::recursive_mutex valuesMutex
Definition: EntityAttribute.h:222