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