iCub-main
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 
24 #include <iCub/perception/models.h>
25 
26 using namespace std;
27 using namespace yarp::os;
28 using namespace iCub::perception;
29 
30 
31 /************************************************************************/
32 Model::Model()
33 {
34  name="";
35 }
36 
37 
38 /************************************************************************/
39 void 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 /************************************************************************/
73 void Model::attachNode(Node &node)
74 {
75  nodes[node.getName()]=&node;
76 }
77 
78 
79 /************************************************************************/
80 Node* 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 
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
int verbosity
Definition: main.cpp:17