iCub-main
nodes.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Department of Robotics Brain and Cognitive Sciences - Istituto Italiano di Tecnologia
3  * Author: Ugo Pattacini
4  * email: ugo.pattacini@iit.it
5  * Permission is granted to copy, distribute, and/or modify this program
6  * under the terms of the GNU General Public License, version 2 or any
7  * later version published by the Free Software Foundation.
8  *
9  * A copy of the license can be found at
10  * http://www.robotcub.org/icub/license/gpl.txt
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details
16 */
17 
18 #include <iCub/perception/nodes.h>
19 
20 using namespace std;
21 using namespace yarp::os;
22 using namespace iCub::perception;
23 
24 
25 /************************************************************************/
26 EventCallback::EventCallback()
27 {
28  name="";
29 }
30 
31 
32 /************************************************************************/
33 Node::Node()
34 {
35  name="";
36 }
37 
38 
39 /************************************************************************/
40 void Node::attachSensor(Sensor &sensor)
41 {
42  sensors[sensor.getName()]=&sensor;
43 }
44 
45 
46 /************************************************************************/
47 void Node::attachCallback(EventCallback &callback)
48 {
49  callbacks[callback.getName()]=&callback;
50 }
51 
52 
53 /************************************************************************/
54 void Node::addNeighbor(Node &node)
55 {
56  neighbors[node.getName()]=&node;
57 }
58 
59 
60 /************************************************************************/
61 bool Node::removeNeighbor(const string &name)
62 {
63  map<string,Node*>::iterator it=neighbors.find(name);
64  if (it!=neighbors.end())
65  {
66  neighbors.erase(it);
67  return true;
68  }
69  else
70  return false;
71 }
72 
73 
74 /************************************************************************/
75 Node* Node::getNeighbor(const string &name) const
76 {
77  map<string,Node*>::const_iterator it=neighbors.find(name);
78  return (it!=neighbors.end()?it->second:NULL);
79 }
80 
81 
82 
An abstract class that provides basic events handling.
Definition: nodes.h:60
std::string getName() const
Retrieve the node name.
Definition: nodes.h:74
An abstract class that exposes the basic methods for the handling of data acquired through the attach...
Definition: nodes.h:94
std::string getName() const
Retrieve the node name.
Definition: nodes.h:112
An abstract class that exposes the basic methods for sensors handling.
Definition: sensors.h:116
std::string getName() const
Retrieve the sensor name.
Definition: sensors.h:132