iCub-main
Loading...
Searching...
No Matches
models.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 <cstdio>
19#include <cstdarg>
20
21#include <yarp/os/Log.h>
22
25
26using namespace std;
27using namespace yarp::os;
28using namespace iCub::perception;
29
30
31/************************************************************************/
33{
34 name="";
35}
36
37
38/************************************************************************/
39void Model::printMessage(const int logtype, const int level,
40 const char *format, ...) const
41{
42 if (verbosity>=level)
43 {
44 string str;
45 str="*** "+name+": ";
46
47 va_list arg;
48 char buf[512];
49 va_start(arg,format);
50 vsnprintf(buf,sizeof(buf),format,arg);
51 va_end(arg);
52
53 str+=buf;
54 switch (logtype)
55 {
56 case log::error:
57 yError("%s",str.c_str());
58 break;
59 case log::warning:
60 yWarning("%s",str.c_str());
61 break;
62 case log::info:
63 yInfo("%s",str.c_str());
64 break;
65 default:
66 printf("%s\n",str.c_str());
67 }
68 }
69}
70
71
72/************************************************************************/
74{
75 nodes[node.getName()]=&node;
76}
77
78
79/************************************************************************/
80Node* Model::getNode(const string &name) const
81{
82 map<string,Node*>::const_iterator it=nodes.find(name);
83 return (it!=nodes.end()?it->second:NULL);
84}
85
86
virtual void printMessage(const int logtype, const int level, const char *format,...) const
Definition models.cpp:39
Node * getNode(const std::string &name) const
Retrieve an attached node by its name.
Definition models.cpp:80
void attachNode(Node &node)
Attach a node object to the model.
Definition models.cpp:73
std::map< std::string, Node * > nodes
Definition models.h:67
std::string name
Definition models.h:64
Model()
Constructor.
Definition models.cpp:32
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