Gaia
applier.h
1 /*
2  * Copyright (C) 2006-2013 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Gaia
5  *
6  * Gaia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef GAIA_APPLIER_H
21 #define GAIA_APPLIER_H
22 
23 #include "dataset.h"
24 #include "factory.h"
25 #include "transformation.h"
26 #include "pointlayout.h"
27 #include "textprogress.h"
28 
29 namespace gaia2 {
30 
44 class Applier {
45  public:
46 
47  Applier(const Transformation& transfo) : _transfo(transfo) {}
48 
49  virtual ~Applier() {};
50 
57  void checkLayout(const PointLayout& layout) const;
58 
66  void checkLayout(const DataSet* dataset) const;
67 
71  virtual Point* mapPoint(const Point* p) const = 0;
72 
77  virtual DataSet* mapDataSet(const DataSet* dataset) const;
78 
79  protected:
84  void transferHistory(const DataSet* original, DataSet* destination) const;
85 
91  void addPointsNoLayoutCheck(DataSet* dataset, const QVector<Point*>& points) const;
92 
93  Transformation _transfo;
94 
95 };
96 
98 
99 void registerAppliers();
100 
101 } // namespace gaia2
102 
103 
105 #define MAPDATASET_PREPARE \
106  checkLayout(dataset); \
107  DataSet* result = new DataSet; \
108  result->setName(dataset->name()); \
109  \
110  TextProgress info(dataset->size(), \
111  QString("Applying '") + _transfo.analyzerName \
112  + "' transformation [%1/%2] (%3% done)", \
113  UpdateOnPercent); \
114  info.setSilent(!gaia2::verbose); \
115  int npoint = 0;
116 
118 #define MAPDATASET_LOOP_POINT \
119  QVector<Point*> v(dataset->size()); \
120  for (int i=0; i<dataset->size(); i++) { \
121  info.update(++npoint); \
122  const Point* p = dataset->at(i);
123 
125 #define MAPDATASET_END_LOOP_NO_RETURN \
126  v[i] = newp; \
127  } \
128  addPointsNoLayoutCheck(result, v); \
129  transferHistory(dataset, result);
130 
131 
133 #define MAPDATASET_END_LOOP \
134  MAPDATASET_END_LOOP_NO_RETURN; \
135  return result;
136 
137 
138 #endif // GAIA_APPLIER_H
A basic implementation of a generic factory class.
Definition: factory.h:41
Class containing all info pertaining to a specific transformation, ie: the name of the analyzer class...
Definition: transformation.h:41
void addPointsNoLayoutCheck(DataSet *dataset, const QVector< Point * > &points) const
Adds the given points to a DataSet without checking for the layout to be correct. ...
Definition: applier.cpp:84
This class represents a dataset and all related information.
Definition: dataset.h:91
This class describes the layout of a point.
Definition: pointlayout.h:60
virtual DataSet * mapDataSet(const DataSet *dataset) const
Provides a default function that maps a whole dataset but which can be overriden in derived classes t...
Definition: applier.cpp:58
Main Gaia namespace, which contains all the library functions.
Definition: addfield.cpp:22
void transferHistory(const DataSet *original, DataSet *destination) const
This method tranfers the transformation history from the original dataset to the one being created...
Definition: applier.cpp:78
The Applier abstract base class.
Definition: applier.h:44
void checkLayout(const PointLayout &layout) const
Check that the given layout is the same as the one that was used during the analysis part of this tra...
Definition: applier.cpp:66
virtual Point * mapPoint(const Point *p) const =0
Ownership of resulting point is handed to caller of this function.
Definition: point.h:106