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,
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 
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 
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 */
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:13
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
memoryx::Relation::getSourceAttributes
std::string getSourceAttributes() const
Definition: Relation.cpp:118
memoryx::Entity::putAttribute
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition: Entity.cpp:347
memoryx::Relation::clone
RelationPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: Relation.cpp:148
memoryx::Entity::getAttribute
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition: Entity.cpp:311
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:354
memoryx::Relation::setAttributes
void setAttributes(std::string const &attributes)
Definition: Relation.cpp:112
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:94
armarx::sign
T sign(T t)
Definition: algorithm.h:214
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::Relation::getAttributes
std::string getAttributes() const
Definition: Relation.cpp:106
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
memoryx::Relation::setSourceAttributes
void setSourceAttributes(std::string const &attributes)
Definition: Relation.cpp:124
memoryx::Entity::output
void output(std::ostream &stream) const
Definition: Entity.cpp:436
Relation.h
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
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::Relation::setEntities
void setEntities(const EntityRefList &entities, const ::Ice::Current &=Ice::emptyCurrent) override
set the entities involved in this relation
Definition: Relation.cpp:68
memoryx::Relation::getTargetAttributes
std::string getTargetAttributes() const
Definition: Relation.cpp:130
memoryx::Relation::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: Relation.cpp:142
memoryx::Relation::setSign
void setSign(bool sign, const ::Ice::Current &=Ice::emptyCurrent) override
Set whether this relation is true or false.
Definition: Relation.cpp:88
memoryx::EntityAttribute
Attribute of MemoryX entities.
Definition: EntityAttribute.h:49
memoryx::Relation::getSign
bool getSign(const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve whether this relation is true or false.
Definition: Relation.cpp:82
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:53
memoryx::Entity
Definition: Entity.h:245
memoryx::Entity::setName
void setName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
Set name of this entity.
Definition: Entity.cpp:188
memoryx::Relation::setTargetAttributes
void setTargetAttributes(std::string const &attributes)
Definition: Relation.cpp:136
memoryx::Relation::setProb
void setProb(::Ice::Float prob, const ::Ice::Current &=Ice::emptyCurrent) override
Set probability that this relation actually exists.
Definition: Relation.cpp:100