29 #include <MemoryX/interface/core/EntityBase.h>
30 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
31 #include <MemoryX/interface/memorytypes/MemorySegments.h>
45 virtual public PersistentObjectClassSegmentBase
57 PersistentObjectClassSegmentBase()
67 ObjectClassBasePtr
getObjectClassById(const ::std::string&
id, const ::Ice::Current& = Ice::emptyCurrent)
const override
69 return ObjectClassBasePtr::dynamicCast(getEntityById(
id));
78 ObjectClassBasePtr
getObjectClassByName(const ::std::string& name, const ::Ice::Current& = Ice::emptyCurrent)
const override
80 return ObjectClassBasePtr::dynamicCast(getEntityByName(name));
91 ObjectClassBasePtr objClass = ObjectClassBasePtr::dynamicCast(getEntityByName(name));
99 objClass->clearParentClasses();
100 ObjectClassList parents = getAllParentClasses(objClass->getName());
104 for (
size_t i = 0; i < parents.size(); i++)
106 objClass->addParentClass(parents.at(i)->getName());
119 ObjectClassList
getChildClasses(
const std::string& parentClassName, const ::Ice::Current& = Ice::emptyCurrent)
const override
121 ObjectClassList result;
122 EntityBaseList children = getEntitiesByAttrValue(
"parentClasses", parentClassName);
124 for (EntityBaseList::const_iterator it = children.begin(); it != children.end(); ++it)
126 result.push_back(ObjectClassBasePtr::dynamicCast(*it));
138 ObjectClassList
getParentClasses(
const std::string& className, const ::Ice::Current& = Ice::emptyCurrent)
const override
141 EntityBasePtr entity = getEntityByName(className);
145 throw armarx::LocalException(
"Could not find class with name ") << className;
148 ObjectClassBasePtr objClass = ObjectClassBasePtr::dynamicCast(entity);
152 throw armarx::LocalException(
"Could not cast class with name ") << className;
155 NameList parentClassNameList = objClass->getParentClasses();
156 ObjectClassList parentClassList;
158 for (NameList::const_iterator it = parentClassNameList.begin(); it != parentClassNameList.end(); ++it)
165 ObjectClassBasePtr ptr = ObjectClassBasePtr::dynamicCast(getEntityByName(*it));
169 ARMARX_INFO_S <<
"Could not cast parent " << *it <<
" of class " << className;
173 parentClassList.push_back(ptr);
177 return parentClassList;
186 ObjectClassList
getClassWithSubclasses(
const std::string& rootClassName, const ::Ice::Current& = Ice::emptyCurrent)
const override
189 ObjectClassList relevantClasses;
190 ObjectClassPtr root = ObjectClassPtr::dynamicCast(getEntityByName(rootClassName));
194 ARMARX_WARNING_S <<
"Parent Object Class '" << rootClassName <<
"' does not exist in segment!";
195 return ObjectClassList();
198 relevantClasses.push_back(root);
202 while (
index !=
int(relevantClasses.size()))
204 ObjectClassBasePtr current = relevantClasses.at(
index);
207 ObjectClassList childs = getChildClasses(current->getName());
209 if (childs.size() != 0)
211 std::copy(childs.begin(), childs.end(), std::back_inserter(relevantClasses));
217 unique(relevantClasses);
219 return relevantClasses;
227 ObjectClassList
getAllParentClasses(
const std::string& className, const ::Ice::Current& = Ice::emptyCurrent)
const override
229 ObjectClassList relevantClasses, classesLeftToCheck;
231 ObjectClassBasePtr current = ObjectClassBasePtr::dynamicCast(getEntityByName(className));
235 return relevantClasses;
243 throw armarx::LocalException(
"current is NULL!");
247 ObjectClassList parents = getParentClasses(current->getName());
249 if (parents.size() != 0)
251 std::copy(parents.begin(), parents.end(), std::back_inserter(relevantClasses));
252 std::copy(parents.begin(), parents.end(), std::back_inserter(classesLeftToCheck));
254 unique(classesLeftToCheck);
255 if (classesLeftToCheck.size() == 0)
259 current = *classesLeftToCheck.rbegin();
260 classesLeftToCheck.pop_back();
264 unique(relevantClasses);
265 return relevantClasses;
274 ObjectComparisonResult
compare(
const ObjectClassBasePtr& objClass,
const ObjectClassBasePtr& other,
const Ice::Current& = Ice::emptyCurrent)
const override
276 if (other->getName() == objClass->getName())
281 ObjectClassList otherParentClasses = getAllParentClasses(other->getName());
282 ObjectClassList parentClasses = getAllParentClasses(objClass->getName());
285 for (ObjectClassList::iterator itOther = otherParentClasses.begin(); itOther != otherParentClasses.end(); itOther++)
287 if (objClass->getName() == (*itOther)->getName())
292 for (ObjectClassList::iterator it = parentClasses.begin(); it != parentClasses.end(); it++)
294 if ((*it)->getName() == (*itOther)->getName())
296 return eEqualParentClass;
301 for (ObjectClassList::iterator it = parentClasses.begin(); it != parentClasses.end(); it++)
303 if ((*it)->getName() == other->getName())
305 return eEqualParentClass;
309 return eNotEqualClass;
312 bool isParentClass(const ::std::string& className, const ::std::string& parentCandidate, const ::Ice::Current& = Ice::emptyCurrent)
const override
314 ObjectClassList parentClasses = getAllParentClasses(className);
316 for (
const auto& parent : parentClasses)
318 if (parent->getName() == parentCandidate)
327 static void unique(ObjectClassList& classes)
329 auto objectClassPtrCompareLess = [](
const ObjectClassBasePtr & lhs,
const ObjectClassBasePtr & rhs)
331 return lhs->getName() < rhs->getName();
333 auto objectClassPtrCompareEq = [](
const ObjectClassBasePtr & lhs,
const ObjectClassBasePtr & rhs)
335 return lhs->getName() == rhs->getName();
337 std::sort(classes.begin(), classes.end(), objectClassPtrCompareLess);
338 auto newEnd = std::unique(classes.begin(), classes.end(), objectClassPtrCompareEq);
339 classes.erase(newEnd, classes.end());