iCub-main
ITransformer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2011 RobotCub Consortium, European Commission FP6 Project IST-004370
3  * author: Arjan Gijsberts
4  * email: arjan.gijsberts@iit.it
5  * website: www.robotcub.org
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * http://www.robotcub.org/icub/license/gpl.txt
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17  */
18 
19 #ifndef LM_ITRANSFORMER__
20 #define LM_ITRANSFORMER__
21 
22 #include <sstream>
23 #include <string>
24 
25 #include <yarp/os/IConfig.h>
26 #include <yarp/os/Portable.h>
27 #include <yarp/os/Bottle.h>
28 #include <yarp/sig/Vector.h>
29 
30 namespace iCub {
31 namespace learningmachine {
32 
58 class ITransformer : public yarp::os::IConfig, public yarp::os::Portable {
59 protected:
63  std::string name;
64 
69 
77  virtual void writeBottle(yarp::os::Bottle& bot) const = 0;
78 
86  virtual void readBottle(yarp::os::Bottle& bot) = 0;
87 
88 public:
92  ITransformer() : name(""), sampleCount(0) { }
93 
97  virtual ~ITransformer() { }
98 
105  virtual yarp::sig::Vector transform(const yarp::sig::Vector& input) {
106  this->sampleCount++;
107  return yarp::sig::Vector();
108  }
109 
116  virtual std::string getInfo() {
117  std::ostringstream buffer;
118  buffer << "Type: " << this->getName() << ", ";
119  buffer << "Sample Count: " << this->sampleCount << std::endl;
120  return buffer.str();
121  }
122 
126  virtual void reset() {
127  this->sampleCount = 0;
128  }
129 
135  std::string getName() const {
136  return this->name;
137  }
138 
144  void setName(std::string name) {
145  this->name = name;
146  }
147 
154  virtual std::string getConfigHelp() {
155  return std::string("Transformer configuration options for '") +
156  this->getName() + "'\n";
157  }
158 
164  virtual ITransformer* clone() = 0;
165 
166  /*
167  * Inherited from IConfig.
168  */
169  virtual bool configure(yarp::os::Searchable& config) { return true; }
170 
171  /*
172  * Inherited from Portable.
173  */
174  bool write(yarp::os::ConnectionWriter& connection) const {
175  yarp::os::Bottle model;
176  this->writeBottle(model);
177  return model.write(connection);
178  }
179 
180  /*
181  * Inherited from Portable.
182  */
183  bool read(yarp::os::ConnectionReader& connection) {
184  yarp::os::Bottle model;
185  model.read(connection);
186  this->readBottle(model);
187  return true;
188  }
189 
195  virtual std::string toString() {
196  yarp::os::Bottle model;
197  this->writeBottle(model);
198  return model.toString().c_str();
199  }
200 
206  virtual bool fromString(const std::string& str) {
207  yarp::os::Bottle model(str.c_str());
208  this->readBottle(model);
209  return true;
210  }
211 
212 };
213 
214 } // learningmachine
215 } // iCub
216 
217 #endif
A class that provides a preprocessing interface, which can be used to preprocess the data samples tha...
Definition: ITransformer.h:58
virtual ~ITransformer()
Destructor (empty).
Definition: ITransformer.h:97
bool write(yarp::os::ConnectionWriter &connection) const
Definition: ITransformer.h:174
virtual std::string getConfigHelp()
Asks the transformer to return a string containing the list of configuration options that it supports...
Definition: ITransformer.h:154
virtual bool configure(yarp::os::Searchable &config)
Definition: ITransformer.h:169
bool read(yarp::os::ConnectionReader &connection)
Definition: ITransformer.h:183
int sampleCount
Number of samples transformed since initialization.
Definition: ITransformer.h:68
virtual yarp::sig::Vector transform(const yarp::sig::Vector &input)
Transforms an input vector.
Definition: ITransformer.h:105
virtual void reset()
Forget everything and start over.
Definition: ITransformer.h:126
virtual ITransformer * clone()=0
Asks the transformer to return a new object of its type.
virtual std::string toString()
Asks the transformer to return a string serialization.
Definition: ITransformer.h:195
virtual void readBottle(yarp::os::Bottle &bot)=0
Unserializes a transformer from a bottle.
std::string name
The name of this type of transformer.
Definition: ITransformer.h:63
virtual bool fromString(const std::string &str)
Asks the transformer to initialize from a string serialization.
Definition: ITransformer.h:206
virtual std::string getInfo()
Asks the transformer to return a string containing statistics on its operation so far.
Definition: ITransformer.h:116
virtual void writeBottle(yarp::os::Bottle &bot) const =0
Writes a serialization of the transformer into a bottle.
std::string getName() const
Retrieve the name of this transformer.
Definition: ITransformer.h:135
void setName(std::string name)
Set the name of this transformer.
Definition: ITransformer.h:144
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.