iCub-main
Loading...
Searching...
No Matches
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
19
20using namespace std;
21using namespace yarp::os;
22using namespace iCub::perception;
23
24
25/************************************************************************/
30
31
32/************************************************************************/
34{
35 name="";
36}
37
38
39/************************************************************************/
41{
42 sensors[sensor.getName()]=&sensor;
43}
44
45
46/************************************************************************/
48{
49 callbacks[callback.getName()]=&callback;
50}
51
52
53/************************************************************************/
55{
56 neighbors[node.getName()]=&node;
57}
58
59
60/************************************************************************/
61bool 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/************************************************************************/
75Node* 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::map< std::string, EventCallback * > callbacks
Definition nodes.h:99
std::map< std::string, Node * > neighbors
Definition nodes.h:100
std::map< std::string, Sensor * > sensors
Definition nodes.h:98
void addNeighbor(Node &node)
Add a node as a neighbor for the process of building the architecture.
Definition nodes.cpp:54
bool removeNeighbor(const std::string &name)
Remove a node previously added as neighbor.
Definition nodes.cpp:61
void attachCallback(EventCallback &callback)
Attach an event callback to the node.
Definition nodes.cpp:47
void attachSensor(Sensor &sensor)
Attach a sensor object to the node.
Definition nodes.cpp:40
std::string name
Definition nodes.h:96
Node * getNeighbor(const std::string &name) const
Retrieve a neighbor node by its name.
Definition nodes.cpp:75
std::string getName() const
Retrieve the node name.
Definition nodes.h:112
Node()
Constructor.
Definition nodes.cpp:33
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