Relation.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 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 "Relation.h"
24
26
27namespace memoryx
28{
29
30 Relation::Relation(const std::string& name,
31 const EntityRefList& entities,
32 bool sign,
33 float prob) :
34 Entity()
35 {
36 setName(name);
37 putAttribute("sign", sign);
38 putAttribute("prob", prob);
39 putAttribute("attributes", "{}");
40 putAttribute("source", "{}");
41 putAttribute("target", "{}");
42 EntityAttributePtr ea = new EntityAttribute("entities");
43
44 for (const auto& entity : entities)
45 {
46 ea->addValue(new armarx::Variant(entity));
47 }
48
49 putAttribute(ea);
50 }
51
52 EntityRefList
53 Relation::getEntities(const ::Ice::Current&) const
54 {
55 EntityRefList result;
56 auto ea = getAttribute("entities");
57
58 for (int i = 0; i < ea->size(); i++)
59 {
60 result.push_back(
61 armarx::VariantPtr::dynamicCast(ea->getValueAt(i))->get<EntityRefBase>());
62 }
63
64 return result;
65 }
66
67 void
68 Relation::setEntities(const EntityRefList& entities, const ::Ice::Current&)
69 {
70 removeAttribute("entities");
71 EntityAttributePtr ea = new EntityAttribute("entities");
72
73 for (const auto& entity : entities)
74 {
75 ea->addValue(new armarx::Variant(entity));
76 }
77
78 putAttribute(ea);
79 }
80
81 bool
82 Relation::getSign(const ::Ice::Current&) const
83 {
84 return getAttribute("sign")->getValue()->getBool();
85 }
86
87 void
88 Relation::setSign(bool sign, const ::Ice::Current&)
89 {
90 getAttribute("sign")->getValue()->setBool(sign);
91 }
92
93 ::Ice::Float
94 Relation::getProb(const ::Ice::Current&) const
95 {
96 return getAttribute("prob")->getValue()->getFloat();
97 }
98
99 void
100 Relation::setProb(::Ice::Float prob, const ::Ice::Current&)
101 {
102 getAttribute("prob")->getValue()->setFloat(prob);
103 }
104
105 std::string
107 {
108 return getAttribute("attributes")->getValue()->getString();
109 }
110
111 void
112 Relation::setAttributes(const std::string& attributes)
113 {
114 getAttribute("attributes")->getValue()->setString(attributes);
115 }
116
117 std::string
119 {
120 return getAttribute("source")->getValue()->getString();
121 }
122
123 void
124 Relation::setSourceAttributes(std::string const& attributes)
125 {
126 getAttribute("source")->getValue()->setString(attributes);
127 }
128
129 std::string
131 {
132 return getAttribute("target")->getValue()->getString();
133 }
134
135 void
136 Relation::setTargetAttributes(std::string const& attributes)
137 {
138 getAttribute("target")->getValue()->setString(attributes);
139 }
140
141 Ice::ObjectPtr
143 {
144 return this->clone();
145 }
146
148 Relation::clone(const Ice::Current& c) const
149 {
150 RelationPtr ret = new Relation(*this);
151 // ret->deepCopy(*this);
152 return ret;
153 }
154
155 void
156 Relation::output(std::ostream& stream) const
157 {
158 Entity::output(stream);
159 }
160
161} /* namespace memoryx */
constexpr T c
The Variant class is described here: Variants.
Definition Variant.h:224
Attribute of MemoryX entities.
void removeAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) override
Remove attribute with given name from entity.
Definition Entity.cpp:354
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition Entity.cpp:311
void setName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
Set name of this entity.
Definition Entity.cpp:188
Entity(const Entity &source)
Definition Entity.cpp:34
void output(std::ostream &stream) const
Definition Entity.cpp:436
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition Entity.cpp:347
::Ice::Float getProb(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve probability that this relation actually exists.
Definition Relation.cpp:94
void setSign(bool sign, const ::Ice::Current &=Ice::emptyCurrent) override
Set whether this relation is true or false.
Definition Relation.cpp:88
std::string getAttributes() const
Definition Relation.cpp:106
void setProb(::Ice::Float prob, const ::Ice::Current &=Ice::emptyCurrent) override
Set probability that this relation actually exists.
Definition Relation.cpp:100
std::string getSourceAttributes() const
Definition Relation.cpp:118
void setEntities(const EntityRefList &entities, const ::Ice::Current &=Ice::emptyCurrent) override
set the entities involved in this relation
Definition Relation.cpp:68
EntityRefList getEntities(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve the entities involved in this relation.
Definition Relation.cpp:53
void setAttributes(std::string const &attributes)
Definition Relation.cpp:112
RelationPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition Relation.cpp:148
std::string getTargetAttributes() const
Definition Relation.cpp:130
Ice::ObjectPtr ice_clone() const override
Definition Relation.cpp:142
Relation(const std::string &name="", const EntityRefList &entities=EntityRefList{}, bool sign=true, float prob=1.f)
Constucts a new Relation.
Definition Relation.cpp:30
void setTargetAttributes(std::string const &attributes)
Definition Relation.cpp:136
void setSourceAttributes(std::string const &attributes)
Definition Relation.cpp:124
bool getSign(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve whether this relation is true or false.
Definition Relation.cpp:82
VirtualRobot headers.
IceInternal::Handle< EntityAttribute > EntityAttributePtr
Typedef of EntityAttributePtr as IceInternal::Handle<EntityAttribute> for convenience.
IceInternal::Handle< Relation > RelationPtr
Definition Relation.h:33