Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sensormotorinfoable.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __SENSORMOTORINFOABLE_H
25 #define __SENSORMOTORINFOABLE_H
26 
27 #include <list>
28 #include <vector>
29 #include <functional>
30 
31 #include <selforg/sensormotorinfo.h>
32 
33 namespace lpzrobots {
34 
35  /** Abstract class for giving names to sensors and motors
36  */
38  public:
39  /// function that returns the name given the index
40  typedef std::function<std::string(int)> NamingFunction;
41 
43 
44  // sets the base name that is used to construct the names for each item with the nameing function
45  void setBaseName(const std::string& basename) {
46  this->baseinfo.name=basename;
47  }
48 
49  // sets the base information for sensor or motor (the name is considered as base name)
51  this->baseinfo=baseinfo;
52  }
53  // sets the base information for sensor or motor (the name is considered as base name)
55  return this->baseinfo;
56  }
57 
59  this->func=func;
60  }
61 
63  return this->func;
64  }
65 
66  /// set names explicitly (basename is anyway suffixed)
67  void setNames(const std::vector<std::string>& names){
68  this->func=[names](int index) {
69  if (index>=(int)names.size()) return names.back() + "Unknown";
70  else return names[index];
71  };
72  }
73 
74  /// returns the name of a single item. Typically called from within Sensor and Motor class.
75  std::string getName(int index) const {
76  return baseinfo.name + func(index);
77  }
78 
79  /** get all infos. Typically called from within Sensor and Motor class.
80  */
81  std::list<SensorMotorInfo> getInfos(int number) const {
82  std::list<SensorMotorInfo> l;
83  for(int i=0; i<number; i++){
85  info.name = getName(i);
86  info.index = i;
87  l.push_back(info);
88  }
89  return l;
90  }
91 
92 
93 
94  /// the default implementation is for index==0: basename, otherwise basename + (index+1)
95  static std::string defaultNameing(int index) {
96  if(index==0)
97  return "";
98  else
99  return std::to_string(index+1);
100  }
101 
102  protected:
105  };
106 }
107 
108 #endif
void setBaseInfo(const SensorMotorInfo &baseinfo)
Definition: sensormotorinfoable.h:50
void setNames(const std::vector< std::string > &names)
set names explicitly (basename is anyway suffixed)
Definition: sensormotorinfoable.h:67
NamingFunction func
Definition: sensormotorinfoable.h:103
std::function< std::string(int)> NamingFunction
function that returns the name given the index
Definition: sensormotorinfoable.h:40
SensorMotorInfoAble()
Definition: sensormotorinfoable.h:42
int index
Definition: sensormotorinfo.h:52
SensorMotorInfo getBaseInfo()
Definition: sensormotorinfoable.h:54
SensorMotorInfo baseinfo
Definition: sensormotorinfoable.h:104
Interface for objects, that can be stored and restored to/from a file stream (binary).
Definition: sensormotorinfo.h:33
NamingFunction getNamingFunc() const
Definition: sensormotorinfoable.h:62
static std::string defaultNameing(int index)
the default implementation is for index==0: basename, otherwise basename + (index+1) ...
Definition: sensormotorinfoable.h:95
void setBaseName(const std::string &basename)
Definition: sensormotorinfoable.h:45
std::string getName(int index) const
returns the name of a single item. Typically called from within Sensor and Motor class.
Definition: sensormotorinfoable.h:75
std::string name
Definition: sensormotorinfo.h:49
Abstract class for giving names to sensors and motors.
Definition: sensormotorinfoable.h:37
std::list< SensorMotorInfo > getInfos(int number) const
get all infos.
Definition: sensormotorinfoable.h:81
void setNamingFunc(const NamingFunction &func)
Definition: sensormotorinfoable.h:58