abstracttest.h
1 /********************************************************************************
2  * FARSA Experiments Library *
3  * Copyright (C) 2007-2012 *
4  * Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it> *
5  * Stefano Nolfi <stefano.nolfi@istc.cnr.it> *
6  * Onofrio Gigliotta <onofrio.gigliotta@istc.cnr.it> *
7  * Gianluca Massera <emmegian@yahoo.it> *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the Free Software *
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
22  ********************************************************************************/
23 
24 #ifndef ABSTRACT_TEST_H
25 #define ABSTRACT_TEST_H
26 
27 #include "parametersettable.h"
28 #include "configurationparameters.h"
29 #include "evorobotcomponent.h"
30 #include <iostream>
31 #include <cstdlib>
32 #include <QObject>
33 #include <QString>
34 #include <QMap>
35 #include "logger.h"
36 
37 namespace farsa {
38 
50 class FARSA_EXPERIMENTS_TEMPLATE AbstractTest : public QObject, public ParameterSettableWithConfigureFunction
51 {
52  Q_OBJECT
53 
54 public:
59  QObject(),
61  m_component(NULL),
62  m_menuText("Abstract Text"),
63  m_tooltip("Abstract Text"),
64  m_iconFilename(QString())
65  {
66  }
67 
71  virtual ~AbstractTest()
72  {
73  }
74 
85  virtual void configure(ConfigurationParameters& /*params*/, QString /*prefix*/)
86  {
87  }
88 
99  virtual void save(ConfigurationParameters& params, QString prefix)
100  {
101  params.startObjectParameters( prefix, "AbstractTest", this );
102  }
103 
105  static void describe( QString type ) {
106  Descriptor d = addTypeDescription( type, "Base class of all Tests" );
107  }
108 
113  virtual void postConfigureInitialization()
114  {
115  }
116 
125  virtual void setComponent(EvoRobotComponent* component)
126  {
127  m_component = component;
128  }
129 
137  EvoRobotComponent* component()
138  {
139  return m_component;
140  }
141 
146  QString menuText() {
147  return m_menuText;
148  }
149 
154  QString tooltip() {
155  return m_tooltip;
156  }
157 
162  QString iconFilename() {
163  return m_iconFilename;
164  }
165 
166 public slots:
170  virtual void runTest() = 0;
171 protected:
173  QString m_menuText;
175  QString m_tooltip;
177  QString m_iconFilename;
178 private:
183  EvoRobotComponent *m_component;
184 };
185 
194 class FARSA_EXPERIMENTS_API AvailableTestList
195 {
196 public:
203  static void addTest(QString name, AbstractTest *test);
204 
210  static QStringList getList();
211 
218  static AbstractTest* getTest(QString name);
219 
220 private:
224  static QMap<QString, AbstractTest*> m_map;
225 };
226 
227 } //end namespace farsa
228 
229 #endif