icub-client
entity.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 WYSIWYD Consortium, European Commission FP7 Project ICT-612139
3  * Authors: Stéphane Lallée
4  * email: stephane.lallee@gmail.com
5  * website: https://github.com/robotology/icub-client/
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * icub-client/license/gpl.txt
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17  */
18 
19 #ifndef __ICUBCLIENT_ENTITY_H__
20 #define __ICUBCLIENT_ENTITY_H__
21 
22 #include <yarp/os/all.h>
23 #include <string>
24 #include <map>
25 #include <list>
26 #include <iostream>
27 #include <sstream>
28 
29 namespace icubclient{
30 
31 //Anticipated declaration of relations (they are used by agents)
32 class Relation;
33 
40 class Entity
41 {
42  friend class OPCClient;
43 
44  //Writing access to name/id is granted only to OPCClient
45 private:
46  int m_opc_id;
47  std::string m_name;
48  std::map<std::string, std::string > m_properties;
49 
50  //The entity status when the class is updated by the OPCClient
51  yarp::os::Bottle m_original_entity;
52  yarp::os::Bottle asBottleOnlyModifiedProperties() const;
53 
54 protected:
55  std::string m_entity_type;
56  void changeName(std::string sName);
57 
58 public:
59  Entity();
60  Entity(const Entity &b);
61  Entity(yarp::os::Bottle &b);
62  virtual ~Entity() {}
63 
67  virtual bool isType(std::string _entityType) const
68  {
69  (void) _entityType; // to avoid unused parameter warning
70  return false;
71  }
72 
76  virtual yarp::os::Bottle asBottle() const;
77 
82  virtual bool fromBottle(const yarp::os::Bottle &b);
83 
87  virtual std::string toString() const;
88 
89  //Getters
93  std::string name() const {
94  return m_name.c_str();
95  }
96 
101  int opc_id() const {
102  return m_opc_id;
103  }
104 
109  std::string properties(const std::string& p) const {
110  if (m_properties.find(p)!=m_properties.end()) {
111  return m_properties.find(p)->second;
112  }
113  else {
114  return "NULL";
115  }
116  }
117 
121  std::string entity_type() const {
122  return m_entity_type;
123  }
124 
125 
126  bool operator==(const Entity &b) const;
127  bool operator<(const Entity &b) const;
128  bool operator>(const Entity &b) const;
129 };
130 
131 } //namespace
132 
133 #endif
134 
135 
int opc_id() const
Return the id of an entity (which has to be unique within the OPC) Typically, modules should employ t...
Definition: entity.h:101
virtual bool fromBottle(const yarp::os::Bottle &b)
Fill entity fields from a bottle representation.
Definition: entity.cpp:95
Represent any entity that can be stored within the OPC.
Definition: entity.h:40
virtual bool isType(std::string _entityType) const
Test if an entity is inheriting a given type.
Definition: entity.h:67
std::string properties(const std::string &p) const
Returns the name of an entity contained in a property, returns the string "NULL" if property is not s...
Definition: entity.h:109
virtual ~Entity()
Definition: entity.h:62
void changeName(std::string sName)
Definition: entity.cpp:149
bool operator==(const Entity &b) const
Definition: entity.cpp:131
An OPC client using the datastructures defined within the icub-client library.
Definition: opcClient.h:35
virtual std::string toString() const
Return a human readable description of the entity.
Definition: entity.cpp:116
std::string name() const
Return the name of an entity (which has to be unique within the OPC)
Definition: entity.h:93
virtual yarp::os::Bottle asBottle() const
Return the entity as a bottle.
Definition: entity.cpp:45
bool operator<(const Entity &b) const
Definition: entity.cpp:137
std::string m_entity_type
Definition: entity.h:55
std::string entity_type() const
Return the specific type of an entity.
Definition: entity.h:121
bool operator>(const Entity &b) const
Definition: entity.cpp:143