31 #include <MemoryX/interface/core/EntityBase.h>
32 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
33 #include <MemoryX/interface/memorytypes/MemorySegments.h>
34 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
45 virtual public ObjectClassMemorySegmentBase
61 ObjectClassMemorySegmentBase::ObjectClassMemorySegmentBase()
63 this->priorKnowledgePrx = priorKnowledgePrx;
66 classesSegmentPrx = priorKnowledgePrx->getObjectClassesSegment();
78 ObjectClassList touchedClasses;
81 ObjectClassList objectClasses = classesSegmentPrx->getClassWithSubclasses(className);
83 ObjectClassList::iterator iter = objectClasses.begin();
85 while (iter != objectClasses.end())
87 ObjectClassBasePtr priorObjectClass = *iter;
89 ObjectClassBasePtr wmObjectClass = addClass(priorObjectClass);
90 touchedClasses.push_back(wmObjectClass);
95 return touchedClasses;
103 ObjectClassList
getClassWithSubclasses(
const std::string& rootClassName, const ::Ice::Current& = Ice::emptyCurrent)
override
106 ObjectClassList relevantClasses;
107 ObjectClassPtr root = ObjectClassPtr::dynamicCast(getEntityByName(rootClassName));
111 return ObjectClassList();
114 relevantClasses.push_back(root);
118 while (
index !=
int(relevantClasses.size()))
120 ObjectClassBasePtr current = relevantClasses.at(
index);
123 ObjectClassList childs = getChildClasses(current->getName());
125 if (childs.size() != 0)
127 std::copy(childs.begin(), childs.end(), std::back_inserter(relevantClasses));
133 return relevantClasses;
142 ObjectClassBasePtr
updateClass(
const std::string& className,
const ObjectClassBasePtr&
update, const ::Ice::Current& = Ice::emptyCurrent)
override
146 if (
update->getName() != className)
152 EntityBasePtr storedObjectClass = getEntityByName(className);
154 if (!storedObjectClass)
160 std::string refCountAttrName =
"referenceCounter";
162 if (storedObjectClass->hasAttribute(refCountAttrName))
165 int counter = storedObjectClass->getAttribute(refCountAttrName)->getValue()->getInt();
170 updateEntity(storedObjectClass->getId(),
update);
172 return ObjectClassBasePtr::dynamicCast(getEntityById(storedObjectClass->getId()));
185 ObjectClassList objectClasses = classesSegmentPrx->getClassWithSubclasses(className);
187 ObjectClassList::iterator iter = objectClasses.begin();
190 while (iter != objectClasses.end())
192 removeClass((*iter)->getName());
201 for (ObjectClassList::const_iterator it = objects.begin(); it != objects.end(); it++)
210 result += (*it)->getName();
222 Ice::StringSeq result;
224 for (ObjectClassList::const_iterator it = objects.begin(); it != objects.end(); it++)
228 result.push_back((*it)->getName());
232 result.push_back(
"NULL");
241 for (ObjectClassList::const_iterator it = objects.begin(); it != objects.end(); it++)
243 if ((*it)->getName() == object->getName())
253 ObjectClassBasePtr addClass(
const ObjectClassBasePtr& objectClass)
255 std::string refCountAttrName =
"referenceCounter";
258 EntityBasePtr storedObjectClass = getEntityByName(objectClass->getName());
260 if (storedObjectClass)
263 if (storedObjectClass->hasAttribute(refCountAttrName))
265 int counter = storedObjectClass->getAttribute(refCountAttrName)->getValue()->getInt();
271 storedObjectClass->putAttribute(
new EntityAttribute(refCountAttrName,
new armarx::Variant(2)));
277 objectClass->putAttribute(
new EntityAttribute(refCountAttrName,
new armarx::Variant(1)));
278 std::string
id = addEntity(objectClass);
279 storedObjectClass = getEntityById(
id);
282 return ObjectClassBasePtr::dynamicCast(storedObjectClass);
285 void removeClass(
const std::string& className)
287 std::string refCountAttrName =
"referenceCounter";
290 EntityBasePtr storedObjectClass = getEntityByName(className);
292 if (storedObjectClass)
295 if (storedObjectClass->hasAttribute(refCountAttrName))
298 int counter = storedObjectClass->getAttribute(refCountAttrName)->getValue()->getInt();
303 storedObjectClass->putAttribute(
new EntityAttribute(refCountAttrName,
new armarx::Variant(counter)));
308 ARMARX_INFO_S <<
"Removing object class " << storedObjectClass->getName();
309 removeEntity(storedObjectClass->getId());
315 ObjectClassList getChildClasses(
const std::string& parentClassName)
317 ObjectClassList result;
318 EntityBaseList children = getEntitiesByAttrValue(
"parentClasses", parentClassName);
320 for (EntityBaseList::const_iterator it = children.begin(); it != children.end(); ++it)
322 result.push_back(ObjectClassBasePtr::dynamicCast(*it));
328 PriorKnowledgeInterfacePrx priorKnowledgePrx;
329 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx;