experiments/evorobot/include/abstracttest.h

00001 /********************************************************************************
00002  *  FARSA Experiments Library                                                   *
00003  *  Copyright (C) 2007-2012                                                     *
00004  *  Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it>                         *
00005  *  Stefano Nolfi <stefano.nolfi@istc.cnr.it>                                   *
00006  *  Onofrio Gigliotta <onofrio.gigliotta@istc.cnr.it>                           *
00007  *  Gianluca Massera <emmegian@yahoo.it>                                        *
00008  *                                                                              *
00009  *  This program is free software; you can redistribute it and/or modify        *
00010  *  it under the terms of the GNU General Public License as published by        *
00011  *  the Free Software Foundation; either version 2 of the License, or           *
00012  *  (at your option) any later version.                                         *
00013  *                                                                              *
00014  *  This program is distributed in the hope that it will be useful,             *
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00017  *  GNU General Public License for more details.                                *
00018  *                                                                              *
00019  *  You should have received a copy of the GNU General Public License           *
00020  *  along with this program; if not, write to the Free Software                 *
00021  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00022  ********************************************************************************/
00023 
00024 #ifndef ABSTRACT_TEST_H
00025 #define ABSTRACT_TEST_H
00026 
00027 #include "parametersettable.h"
00028 #include "configurationparameters.h"
00029 #include "evorobotcomponent.h"
00030 #include <iostream>
00031 #include <cstdlib>
00032 #include <QObject>
00033 #include <QString>
00034 #include <QMap>
00035 #include "logger.h"
00036 
00037 namespace farsa {
00038 
00050 class FARSA_EXPERIMENTS_TEMPLATE AbstractTest : public QObject, public ParameterSettableWithConfigureFunction
00051 {
00052     Q_OBJECT
00053 
00054 public:
00058     AbstractTest() :
00059         QObject(),
00060         ParameterSettableWithConfigureFunction(),
00061         m_component(NULL),
00062         m_menuText("Abstract Text"),
00063         m_tooltip("Abstract Text"),
00064         m_iconFilename(QString())
00065     {
00066     }
00067 
00071     virtual ~AbstractTest()
00072     {
00073     }
00074 
00085     virtual void configure(ConfigurationParameters& /*params*/, QString /*prefix*/)
00086     {
00087     }
00088 
00099     virtual void save(ConfigurationParameters& params, QString prefix)
00100     {
00101         params.startObjectParameters( prefix, "AbstractTest", this );
00102     }
00103 
00105     static void describe( QString type ) {
00106         Descriptor d = addTypeDescription( type, "Base class of all Tests" );
00107     }
00108 
00113     virtual void postConfigureInitialization()
00114     {
00115     }
00116 
00125     virtual void setComponent(EvoRobotComponent* component)
00126     {
00127         m_component = component;
00128     }
00129 
00137     EvoRobotComponent* component()
00138     {
00139         return m_component;
00140     }
00141     
00146     QString menuText() {
00147         return m_menuText;
00148     }
00149 
00154     QString tooltip() {
00155         return m_tooltip;
00156     }
00157 
00162     QString iconFilename() {
00163         return m_iconFilename;
00164     }
00165 
00166 public slots:
00170     virtual void runTest() = 0;
00171 protected:
00173     QString m_menuText;
00175     QString m_tooltip;
00177     QString m_iconFilename;
00178 private:
00183     EvoRobotComponent *m_component;
00184 };
00185 
00194 class FARSA_EXPERIMENTS_API AvailableTestList
00195 {
00196 public:
00203     static void addTest(QString name, AbstractTest *test);
00204 
00210     static QStringList getList();
00211 
00218     static AbstractTest* getTest(QString name);
00219 
00220 private:
00224     static QMap<QString, AbstractTest*> m_map;
00225 };
00226 
00227 } //end namespace farsa
00228 
00229 #endif