ObjectClass.cpp
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::Core
17 * @author Alexey Kozlov ( kozlov at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "ObjectClass.h"
24 
26 
27 namespace memoryx
28 {
29 
31  {
32  EntityAttributePtr parentClassesAttr = new EntityAttribute("parentClasses");
33  putAttribute(parentClassesAttr);
34  EntityAttributePtr isInstanceableAttr = new EntityAttribute("isInstanceable");
35  putAttribute(isInstanceableAttr);
36  }
37 
39  IceUtil::Shared(source),
40  ::armarx::Serializable(source),
41  EntityBase(),// dont copy
42  ObjectClassBase(source),
43  Entity(source)
44  {
45 
46  }
47 
49  {
50  // TODO Auto-generated destructor stub
51  }
52 
53  memoryx::NameList ObjectClass::getParentClasses(const Ice::Current&) const
54  {
55  NameList result;
56 
57  const EntityAttributeBasePtr parentAttr = getParentClassesAttr();
58 
59  for (int i = 0; i < parentAttr->size(); ++i)
60  {
61  result.push_back(parentAttr->getValueAt(i)->getString());
62  }
63 
64  return result;
65  }
66 
67  void ObjectClass::addParentClass(const std::string& className,
68  const Ice::Current&)
69  {
70  getParentClassesAttr()->addValue(armarx::VariantPtr(new armarx::Variant(className)));
71  }
72 
73  void ObjectClass::setParentClass(const std::string& className,
74  const Ice::Current&)
75  {
77  addParentClass(className);
78  }
79 
80  void ObjectClass::clearParentClasses(const Ice::Current&)
81  {
82  getParentClassesAttr()->clear();
83  }
84 
85  void ObjectClass::setInstanceable(bool isInstanceable, const Ice::Current&)
86  {
87  auto attr = getAttribute("isInstanceable");
88  if (attr)
89  {
90  attr->clear();
91  }
92  else
93  {
94  attr = new EntityAttribute("isInstanceable");
95  }
97  }
98 
99  bool ObjectClass::isInstanceable(const Ice::Current&) const
100  {
101  auto attr = getAttribute("isInstanceable");
102 
103  if (attr && attr->size() != 0)
104  {
105  return attr->getValue()->getBool();
106  }
107 
108  return true;
109  }
110 
111  void ObjectClass::output(std::ostream& stream) const
112  {
113  Entity::output(stream);
114  }
115 
116  EntityAttributeBasePtr ObjectClass::getParentClassesAttr() const
117  {
118  return getAttribute("parentClasses");
119  }
120 
122  {
123  return this->clone();
124  }
125 
126  ObjectClassPtr ObjectClass::clone(const Ice::Current& c) const
127  {
128  std::shared_lock lock1(entityMutex);
129  std::scoped_lock lock2(attributesMutex);
130  std::scoped_lock lock3(wrappersMutex);
131  ObjectClassPtr ret = new ObjectClass(*this);
132  // ret->deepCopy(*this);
133  return ret;
134  }
135 
136  ObjectComparisonResult ObjectClass::compare(const ObjectClassBasePtr& other, const Ice::Current&) const
137  {
138  if (other->getName() == getName())
139  {
140  return eEqualClass;
141  }
142 
143  NameList otherParentClasses = other->getParentClasses();
144  NameList parentClasses = getParentClasses();
145  ObjectComparisonResult result = eNotEqualClass;
146 
147  // check parents names
148  for (NameList::iterator itOther = otherParentClasses.begin(); itOther != otherParentClasses.end(); itOther++)
149  {
150  if (getName() == *itOther) // other is a subclass of this -> so its equal
151  {
152  return eEqualClass;
153  }
154 
155  for (NameList::iterator it = parentClasses.begin(); it != parentClasses.end(); it++)
156  {
157  if ((*it) == (*itOther)) // parent of this is equal to parent of other, so only equal class
158  {
159  result = eEqualParentClass;
160  }
161  }
162  }
163 
164  if (result == eEqualParentClass)
165  {
166  return result;
167  }
168 
169  for (NameList::iterator it = parentClasses.begin(); it != parentClasses.end(); it++)
170  {
171  if (*it == other->getName()) // other is parent class of this -> so only equal class
172  {
173  return eEqualParentClass;
174  }
175  }
176 
177  return result;
178  }
179 
180 }
181 
182 
memoryx::ObjectClass::getParentClasses
::memoryx::NameList getParentClasses(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: ObjectClass.cpp:53
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
memoryx::Entity::putAttribute
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition: Entity.cpp:327
memoryx::ObjectClass::isInstanceable
bool isInstanceable(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: ObjectClass.cpp:99
memoryx::Entity::getName
::std::string getName(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve name of this entity.
Definition: Entity.cpp:173
memoryx::ObjectClass::setInstanceable
void setInstanceable(bool isInstanceable, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ObjectClass.cpp:85
memoryx::Entity::getAttribute
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition: Entity.cpp:293
AbstractObjectSerializer.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
ObjectClass.h
IceUtil
Definition: Instance.h:21
memoryx::Entity::output
void output(std::ostream &stream) const
Definition: Entity.cpp:409
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::ObjectClass::~ObjectClass
~ObjectClass() override
Definition: ObjectClass.cpp:48
memoryx::Entity::attributesMutex
std::mutex attributesMutex
Definition: Entity.h:504
memoryx::ObjectClass::ObjectClass
ObjectClass()
Definition: ObjectClass.cpp:30
memoryx::ObjectClass::getParentClassesAttr
EntityAttributeBasePtr getParentClassesAttr() const
Definition: ObjectClass.cpp:116
memoryx::ObjectClass
Definition: ObjectClass.h:37
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
memoryx::ObjectClass::compare
ObjectComparisonResult compare(const ObjectClassBasePtr &other, const Ice::Current &=Ice::emptyCurrent) const override
Definition: ObjectClass.cpp:136
memoryx::ObjectClass::addParentClass
void addParentClass(const ::std::string &className, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ObjectClass.cpp:67
memoryx::Entity::entityMutex
std::shared_mutex entityMutex
Definition: Entity.h:505
memoryx::EntityAttribute
Attribute of MemoryX entities.
Definition: EntityAttribute.h:48
memoryx::ObjectClass::setParentClass
void setParentClass(const ::std::string &className, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ObjectClass.cpp:73
memoryx::ObjectClass::clearParentClasses
void clearParentClasses(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ObjectClass.cpp:80
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
memoryx::ObjectClass::clone
ObjectClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: ObjectClass.cpp:126
memoryx::ObjectClass::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: ObjectClass.cpp:121
memoryx::Entity
Definition: Entity.h:246
memoryx::Entity::wrappersMutex
std::recursive_mutex wrappersMutex
Definition: Entity.h:506
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28