AbstractOperation.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21 \file terralib/vp/AbstractOperation.h
22 
23 \brief Abstract Class to represent an abstract vector operation.
24 */
25 
26 #ifndef __TERRALIB_VP_INTERNAL_ABSCTRACTOPERATION_H
27 #define __TERRALIB_VP_INTERNAL_ABSCTRACTOPERATION_H
28 
29 #include "Config.h"
30 
31 #include "../common/AbstractFactory.h"
32 #include "../geometry/Enums.h"
33 
34 // STL
35 #include <string>
36 #include <vector>
37 
38 namespace te
39 {
40  namespace da
41  {
42  class DataAccess;
43  class DataSetType;
44  }
45 
46  namespace vp
47  {
48  struct AbstractOperationImpl;
49  class Feature;
50  class FeatureSet;
51  class OperationReport;
52 
53  enum class OperationResult
54  {
56  };
57 
58  /*!
59  \class AbstractParameters
60 
61  \brief Abstract class used to define the input/ ouptut parameters for TerraAmazon Operations.
62 
63  \note Not all parameters must be defined, each operation will validate the necessary parameters.
64  */
66  {
67  public:
68 
69  /*! \brief Default constructor. */
71 
72  /*! \brief Virtual destructor. */
73  virtual ~AbstractParameters() = default;
74 
75  public:
76 
77  /*!
78  \brief It checks the parameters for the operation.
79 
80  \return True if the parameters is valid for this operation and false in other cases.
81  */
82  virtual bool isValid();
83 
84  /*!
85  \brief Get the error message if the parameters is not valid.
86 
87  \return String with the error message.
88  */
89  std::string getErrorMessage() const;
90 
91  /*!
92  \brief It reports each parameter used in the operation
93 
94  \param report Object used to report operation information.
95  */
96  void reportParams(OperationReport* report);
97 
98  /*!
99  \brief Adds an input data access to the params
100 
101  \param dataAccess The input dataAccess to be added
102  */
103  void addInputDataAccess(te::da::DataAccess* dataAccess);
104 
105  /*!
106  \brief Adds an output data access to the params. Note that if the dataSet does not exist, it will be created by the operation
107 
108  \param dataAccess The output dataAccess to be added
109  */
110  void addOutputDataAccess(te::da::DataAccess* dataAccess);
111 
112  //!< Returns the input dataAccess vector
113  const std::vector<te::da::DataAccess*>& getInputDataAccessVector() const;
114 
115  //!< Returns the output dataAccess vector
116  const std::vector<te::da::DataAccess*>& getOutputDataAccessVector() const;
117 
118  //!< Sets the input dataAccess vector
119  void setInputDataAccessVector(const std::vector<te::da::DataAccess*>& vecDataAccess);
120 
121  //!< Sets the output dataAccess vector
122  void setOutputDataAccessVector(const std::vector<te::da::DataAccess*>& vecDataAccess);
123 
124  //!< Enables or disables geometry subdivision
125  void setMaxCoordinates(std::size_t maxCoordinates);
126 
127  //!< Returns the current state of the geometry subdivision
128  std::size_t getMaxCoordinates() const;
129 
130  //!< Sets the input to be swapped. This is very usefull for operations between 2 dataSets. If TRUE, the input will be swapped. Default is FALSE
131  void setSwapInput(bool swap);
132 
133  //!< Returns TRUE if the input must be swaped. FALSE otherwise.
134  bool getSwapInput() const;
135 
136  //!< Gets the result of the operation
137  OperationResult getOperationResult() const;
138 
139  //!< Sets the result of the operation
140  void setOperationResult(OperationResult result);
141 
142  protected:
143 
144  /*!
145  \brief It reports each specific parameter used in the operation
146 
147  \param report Object used to report operation information.
148  */
149  virtual void reportSpecificParams(OperationReport* report);
150 
151  protected:
152 
153  std::vector<te::da::DataAccess*> m_inputDataVector; //!< Vector with input dataAccess
154  std::vector<te::da::DataAccess*> m_outputDataVector; //!< Vector with output dataAccess
155  std::string m_errorMessage; //!< String with error message information.
156  bool m_swapInput; //!< This is very usefull for operations between 2 dataSets. If TRUE, the input will be swapped. Default is FALSE
157  bool m_snapGeometries; //!< If TRUE, the geometries will be snapped before the operation is executed. Default is TRUE
158  OperationResult m_operationResult; //!< Stores the result of the operation
159  std::size_t m_maxCoordinates; //!< If higher than 0, geometries will be subdivided until all the parts have less vertexes that this value
160  };
161 
162  /*!
163  \class AbstractOperationCapabilities
164 
165  \brief Abstract class used to define the capabilities of the operation, inclusing number of inputs and outputs.
166  */
168  {
169  public:
170  AbstractOperationCapabilities(const std::string& operationName, std::size_t numberOfInputs, std::size_t numberOfOutputs, const std::string& dataHandlerName, bool snapGeometries = true);
171 
172  //!< Destructor
174 
175  //!< Returns the number of inputs of the operation
176  std::size_t getNumberOfInputs() const;
177 
178  //!< Returns the number of outputs of the operation
179  std::size_t getNumberOfOutputs() const;
180 
181  //!< Returns the name of the operation
182  const std::string& getName() const;
183 
184  //!< Returns TRUE if the operation supports the subdivision of the geometries. FALSE otherwise
185  const std::string& getDataHandlerName() const;
186 
187  //!< Checks if the geometries must be snapped to each other before the operation is executed
188  bool getSnapGeometries() const;
189 
190  //!< Creates the parameters for this operation. If the concrete operation has specific parameters, it must override this class and instantiate the correct parameters
191  std::unique_ptr<AbstractParameters> createParameters() const;
192 
193  protected:
194 
195  std::string m_operationName; //!< The name of the operation
196  std::size_t m_numberOfInputs; //!< The number of inputs of the operation
197  std::size_t m_numberOfOutputs; //!< The number of outputs of the operation
198  std::string m_dataHandlerName; //!< TRUE if the operation supports the subdivision of the geometries. FALSE otherwise
199  bool m_snapGeometries; //!< TRUE if the geometries must be snapped to each other before the operation is executed. FALSE otherwise. Default is TRUE
200  };
201 
202  /*!
203  \class AbstractOperation
204 
205  \brief Abstract class used to define an operation.
206  */
208  {
209  public:
210 
211  /*!
212  \brief Default constructor.
213 
214  \note This class will take the ownership of AbstractParameters pointer
215  */
216  AbstractOperation(const std::string& operationName);
217 
218  /*! \brief Virtual destructor. */
219  virtual ~AbstractOperation();
220 
221  //!< Initializes the operation input and output
222  virtual void initialize();
223 
224  /*!
225  \brief It executes the operation.
226 
227  \param input Input vector data to be processed.
228 
229  \pre The parameters must be valid (internal check)
230 
231  \exception Exception It throws an exception if something goes wrong during the execution.
232 
233  \Return The output memory data processed.
234  */
235  virtual std::vector<te::vp::FeatureSet> execute(const std::vector<te::vp::FeatureSet>& vecInput);
236 
237  /*!
238  \brief It creates the output feature based on the given output dataaccess index
239 
240  \param outputIndex The index of the output dataAccess.
241  */
242  virtual te::vp::Feature* createOutputFeature(std::size_t outputIndex);
243 
244  //!< Sets the parameters to be used by the operation
245  void setParameters(AbstractParameters* params);
246 
247  //!< Gets the operation current parameters
248  AbstractParameters* getParameters();
249 
250  //!< Gets the operation report
251  OperationReport* getReport();
252 
253  //!< Gets the operation name
254  const std::string& getName() const;
255 
256  //!< Gets the output geometry type
257  te::gm::GeomType getOutputGeometryType() const;
258 
259  //!< Aborts the execution of the operation
260  void abort();
261 
262  //!< Returns TRUE if the operation has been aborted. FALSE otherwise
263  bool isAborted() const;
264 
265  //!< Get the capabilities of the operation. Basically, operation will have 2 inputs, 1 output, and support subdivision. If it is not the case of the concrete class, this function should be overriden
266  virtual std::unique_ptr<te::vp::AbstractOperationCapabilities> getCapabilities() const;
267 
268  //!< Makes all the necessaries adaptations to the input dataAccess to avoid duplicate column names
269  bool prepareInputData();
270 
271  bool prepareOutputData();
272 
273  protected:
274 
275  //!< Creates the basic dataSetType for the output containing all the columns that are required
276  virtual te::da::DataSetType* createBasicOutputDataSetType(const std::string& dataSetName, int srid, te::gm::GeomType geometryType, const std::string& geometryColumnName) const;
277 
278  virtual void addOutputColumns(te::da::DataSetType* outputDataSetType);
279 
280  //!< Initializes the operation input
281  virtual bool initializeInput();
282 
283  //!< Initializes the operation output
284  virtual bool initializeOutput();
285 
286  //!< Function that effectivelly executes the operation. It must be implemented by the concrete classes
287  virtual std::vector<te::vp::FeatureSet> executeImpl(const std::vector<te::vp::FeatureSet>& vecInput) = 0;
288 
289  protected:
290 
291  AbstractOperationImpl* m_impl; //!< Holds all the attributes of the class
292  bool m_aborted; //!< Becames true if the abort function is called. Concrete classes must check for this value from time to time
293  };
294 
295  /*!
296  \class OperationFactory
297 
298  \brief Abstract factory used to create Operations.
299  */
300  class TEVPEXPORT OperationFactory : public te::common::AbstractFactory < te::vp::AbstractOperation, std::string >
301  {
302  protected:
303 
304  /*!
305  \brief Constructor.
306 
307  \param factoryKey The key that identifies the factory.
308  */
309  OperationFactory(const std::string& factoryKey);
310 
311  //!< Destructor
312  virtual ~OperationFactory();
313  };
314 
315  }
316 }
317 
318 #endif // __TERRALIB_VP_INTERNAL_ABSCTRACTOPERATION_H
This class defines the interface of abstract factories without initializing parameters.
#define TEVPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61
std::size_t m_numberOfOutputs
The number of outputs of the operation.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
Abstract class used to define the capabilities of the operation, inclusing number of inputs and outpu...
bool m_swapInput
This is very usefull for operations between 2 dataSets. If TRUE, the input will be swapped...
A class that models the description of a dataset.
Definition: DataSetType.h:72
bool m_aborted
Becames true if the abort function is called. Concrete classes must check for this value from time to...
std::string m_errorMessage
String with error message information.
std::vector< te::da::DataAccess * > m_outputDataVector
Vector with output dataAccess.
std::size_t m_maxCoordinates
If higher than 0, geometries will be subdivided until all the parts have less vertexes that this valu...
Abstract class used to define an operation.
std::string m_dataHandlerName
TRUE if the operation supports the subdivision of the geometries. FALSE otherwise.
std::string m_operationName
The name of the operation.
TerraLib.
std::vector< te::da::DataAccess * > m_inputDataVector
Vector with input dataAccess.
bool m_snapGeometries
If TRUE, the geometries will be snapped before the operation is executed. Default is TRUE...
Class used as a report logger for Operations.
OperationResult m_operationResult
Stores the result of the operation.
Abstract class used to define the input/ ouptut parameters for TerraAmazon Operations.
Abstract factory used to create Operations.
std::size_t m_numberOfInputs
The number of inputs of the operation.
AbstractOperationImpl * m_impl
Holds all the attributes of the class.
Configuration flags for the Terrralib Vector Processing module.
bool m_snapGeometries
TRUE if the geometries must be snapped to each other before the operation is executed. FALSE otherwise. Default is TRUE.
A feature is a composition of a geometry and its attributes.
Definition: Feature.h:69
Class used to centralize and control access to data in terralib. It aims to create a high-level inter...
Definition: DataAccess.h:73