29 #include <MemoryX/interface/core/EntityBase.h>
30 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
31 #include <MemoryX/interface/memorytypes/MemorySegments.h>
41 virtual public PersistentRelationSegmentBase
46 PersistentRelationSegmentBase()
50 RelationBasePtr
getRelationById(const ::std::string&
id, const ::Ice::Current& = Ice::emptyCurrent)
const override
52 return RelationBasePtr::dynamicCast(getEntityById(
id));
55 RelationList
getRelationsByName(const ::std::string& name, const ::Ice::Current& = Ice::emptyCurrent)
const override
57 EntityBaseList rels = getEntitiesByAttrValue(
"name", name);
60 for (EntityBaseList::const_iterator it = rels.begin(); it != rels.end(); ++it)
62 RelationBasePtr rel = RelationBasePtr::dynamicCast(*it);
63 result.push_back(rel);
73 for (
const auto&
id : getAllEntityIds())
75 RelationBasePtr rel = RelationBasePtr::dynamicCast(getEntityById(
id));
77 if (rel->getSign() ==
sign)
79 result.push_back(rel);
86 RelationList
getRelationsByEntityId(const ::std::string& entityId, const ::Ice::Current& = Ice::emptyCurrent)
const override
90 for (
const auto&
id : getAllEntityIds())
92 RelationBasePtr rel = RelationBasePtr::dynamicCast(getEntityById(
id));
93 EntityRefList relEntities = rel->getEntities();
95 for (EntityRefBasePtr& relEntity : relEntities)
97 if (relEntity->entityId == entityId)
99 result.push_back(rel);
108 RelationList
getRelationsByEntityRef(
const EntityRefBasePtr& entityRef, const ::Ice::Current& = Ice::emptyCurrent)
const override
110 return getRelationsByEntityId(entityRef->entityId);
115 return getRelationsByAttrValues(entities);
118 RelationBasePtr
getRelationByAttrValues(
const std::string& name,
const EntityRefList& entities,
bool sign, const ::Ice::Current& = Ice::emptyCurrent)
const override
120 RelationBasePtr result;
121 RelationList resultList = getRelationsByAttrValues(entities, name,
true,
sign);
123 if (resultList.size() != 0)
125 result = resultList[0];
131 RelationList getRelationsByAttrValues(
const EntityRefList& entities,
const std::string& name =
"",
bool considerSign =
false,
bool sign =
true, const ::Ice::Current& = Ice::emptyCurrent)
const
135 for (
const auto& entity : getAllEntities())
137 RelationBasePtr rel = RelationBasePtr::dynamicCast(entity);
139 if (!name.empty() && (rel->getName() != name))
144 if (considerSign && (
sign != rel->getSign()))
149 EntityRefList relEntities = rel->getEntities();
151 bool foundArgs =
true;
153 for (
const auto& entityRef : entities)
155 foundArgs &= std::find_if(relEntities.cbegin(), relEntities.cend(), [&](
const memoryx::EntityRefBasePtr & e)
157 return entityRef->equals(e);
158 }) != relEntities.cend();
163 result.push_back(rel);
174 throw armarx::LocalException(
"Not yet implemented");
178 throw armarx::LocalException(
"Not yet implemented");