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  {
55  OP_NOT_STARTED, OP_SUCCESS, OP_CANCELLED, OP_ERROR
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(std::string& errorMessage);
83 
84  /*!
85  \brief It reports each parameter used in the operation
86 
87  \param report Object used to report operation information.
88  */
90 
91  /*!
92  \brief Adds an input data access to the params
93 
94  \param dataAccess The input dataAccess to be added
95  */
97 
98  /*!
99  \brief Adds an output data access to the params. Note that if the dataSet does not exist, it will be created by the operation
100 
101  \param dataAccess The output dataAccess to be added
102  */
104 
105  //!< Returns the input dataAccess vector
106  const std::vector<te::da::DataAccess*>& getInputDataAccessVector() const;
107 
108  //!< Returns the output dataAccess vector
109  const std::vector<te::da::DataAccess*>& getOutputDataAccessVector() const;
110 
111  //!< Sets the input dataAccess vector
112  void setInputDataAccessVector(const std::vector<te::da::DataAccess*>& vecDataAccess);
113 
114  //!< Sets the output dataAccess vector
115  void setOutputDataAccessVector(const std::vector<te::da::DataAccess*>& vecDataAccess);
116 
117  //!< Enables or disables geometry subdivision
118  void setMaxCoordinates(std::size_t maxCoordinates);
119 
120  //!< Returns the current state of the geometry subdivision
121  std::size_t getMaxCoordinates() const;
122 
123  //!< 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
124  void setSwapInput(bool swap);
125 
126  //!< Returns TRUE if the input must be swaped. FALSE otherwise.
127  bool getSwapInput() const;
128 
129  //!< Gets the result of the operation
131 
132  //!< Sets the result of the operation
134 
135  protected:
136 
137  /*!
138  \brief It reports each specific parameter used in the operation
139 
140  \param report Object used to report operation information.
141  */
142  virtual void reportSpecificParams(OperationReport* report);
143 
144  protected:
145 
146  std::vector<te::da::DataAccess*> m_inputDataVector; //!< Vector with input dataAccess
147  std::vector<te::da::DataAccess*> m_outputDataVector; //!< Vector with output dataAccess
148  bool m_swapInput; //!< This is very usefull for operations between 2 dataSets. If TRUE, the input will be swapped. Default is FALSE
149  bool m_snapGeometries; //!< If TRUE, the geometries will be snapped before the operation is executed. Default is TRUE
150  OperationResult m_operationResult; //!< Stores the result of the operation
151  std::size_t m_maxCoordinates; //!< If higher than 0, geometries will be subdivided until all the parts have less vertexes that this value
152  };
153 
154  /*!
155  \class AbstractOperationCapabilities
156 
157  \brief Abstract class used to define the capabilities of the operation, inclusing number of inputs and outputs.
158  */
160  {
161  public:
162  AbstractOperationCapabilities(const std::string& operationName, std::size_t numberOfInputs, std::size_t numberOfOutputs, const std::string& dataHandlerName, bool snapGeometries, bool allowCoordinateSubdivision);
163 
164  //!< Destructor
166 
167  //!< Returns the number of inputs of the operation
168  std::size_t getNumberOfInputs() const;
169 
170  //!< Returns the number of outputs of the operation
171  std::size_t getNumberOfOutputs() const;
172 
173  //!< Returns the name of the operation
174  const std::string& getName() const;
175 
176  //!< Returns TRUE if the operation supports the subdivision of the geometries. FALSE otherwise
177  const std::string& getDataHandlerName() const;
178 
179  //!< Checks if the geometries must be snapped to each other before the operation is executed
180  bool getSnapGeometries() const;
181 
182  //!< Checks if the operation has the capability to handle geometry coordinate subdivision
184 
185  //!< Creates the parameters for this operation. If the concrete operation has specific parameters, it must override this class and instantiate the correct parameters
186  virtual std::unique_ptr<AbstractParameters> createParameters() const;
187 
188  protected:
189 
190  std::string m_operationName; //!< The name of the operation
191  std::size_t m_numberOfInputs; //!< The number of inputs of the operation
192  std::size_t m_numberOfOutputs; //!< The number of outputs of the operation
193  std::string m_dataHandlerName; //!< TRUE if the operation supports the subdivision of the geometries. FALSE otherwise
194  bool m_snapGeometries; //!< TRUE if the geometries must be snapped to each other before the operation is executed. FALSE otherwise. Default is TRUE
195  bool m_allowCoordinateSubdivision; //!< TRUE if the operation has the capability to handle geometry coordinate subdivision
196  };
197 
198  /*!
199  \class AbstractOperation
200 
201  \brief Abstract class used to define an operation.
202  */
204  {
205  public:
206 
207  /*!
208  \brief Default constructor.
209 
210  \note This class will take the ownership of AbstractParameters pointer
211  */
212  AbstractOperation(const std::string& operationName);
213 
214  /*! \brief Virtual destructor. */
216 
217  //!< Initializes the operation input and output
218  virtual void initialize();
219 
220  /*!
221  \brief It executes the operation.
222 
223  \param input Input vector data to be processed.
224 
225  \pre The parameters must be valid (internal check)
226 
227  \exception Exception It throws an exception if something goes wrong during the execution.
228 
229  \Return The output memory data processed.
230  */
231  virtual std::vector<te::vp::FeatureSet> execute(const std::vector<te::vp::FeatureSet>& vecInput);
232 
233  /*!
234  \brief It creates the output feature based on the given output dataaccess index
235 
236  \param outputIndex The index of the output dataAccess.
237  */
238  virtual te::vp::Feature* createOutputFeature(std::size_t outputIndex);
239 
240  /*!
241  \brief Gets the dataSetType of the 'outputIndex-th' output
242 
243  \param outputIndex The index of the output dataAccess.
244  */
245  virtual const te::da::DataSetType* getDataSetType(std::size_t outputIndex);
246 
247  //!< Sets the parameters to be used by the operation
249 
250  //!< Gets the operation current parameters
252 
253  //!< Gets the operation report
255 
256  //!< Gets the operation name
257  const std::string& getName() const;
258 
259  //!< Gets the output geometry type
261 
262  //!< Aborts the execution of the operation
263  void abort();
264 
265  //!< Returns TRUE if the operation has been aborted. FALSE otherwise
266  bool isAborted() const;
267 
268  //!< 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
269  virtual std::unique_ptr<te::vp::AbstractOperationCapabilities> getCapabilities() const;
270 
271  //!< Makes all the necessaries adaptations to the input dataAccess to avoid duplicate column names
273 
275 
276  bool handleOutputPropertyNamesChanges(const te::da::DataSetType* baseOutputDataSetType, const te::da::DataSetType* actualOutputDataSetType);
277 
278  protected:
279 
280  //!< Creates the basic dataSetType for the output containing all the columns that are required
281  virtual te::da::DataSetType* createBasicOutputDataSetType(const std::string& dataSetName, int srid, te::gm::GeomType geometryType, const std::string& geometryColumnName) const;
282 
283  virtual void addOutputColumns(te::da::DataSetType* outputDataSetType);
284 
285  //!< Initializes the operation input
286  virtual bool initializeInput();
287 
288  //!< Initializes the operation output
289  virtual bool initializeOutput();
290 
291  //!< Function that effectivelly executes the operation. It must be implemented by the concrete classes
292  virtual std::vector<te::vp::FeatureSet> executeImpl(const std::vector<te::vp::FeatureSet>& vecInput) = 0;
293 
294  protected:
295 
296  AbstractOperationImpl* m_impl; //!< Holds all the attributes of the class
297  bool m_aborted; //!< Becames true if the abort function is called. Concrete classes must check for this value from time to time
298  };
299 
300  /*!
301  \class OperationFactory
302 
303  \brief Abstract factory used to create Operations.
304  */
305  class TEVPEXPORT OperationFactory : public te::common::AbstractFactory < te::vp::AbstractOperation, std::string >
306  {
307  protected:
308 
309  /*!
310  \brief Constructor.
311 
312  \param factoryKey The key that identifies the factory.
313  */
314  OperationFactory(const std::string& factoryKey);
315 
316  //!< Destructor
317  virtual ~OperationFactory();
318  };
319 
320  }
321 }
322 
323 #endif // __TERRALIB_VP_INTERNAL_ABSCTRACTOPERATION_H
te::vp::AbstractOperation::abort
void abort()
Returns TRUE if the operation has been aborted. FALSE otherwise.
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::vp::AbstractOperationCapabilities::getAllowCoordinateSubdivision
bool getAllowCoordinateSubdivision() const
Creates the parameters for this operation. If the concrete operation has specific parameters,...
te::common::AbstractFactory
This class defines the interface of abstract factories without initializing parameters.
Definition: AbstractFactory.h:70
te::vp::AbstractOperation::initialize
virtual void initialize()
te::vp::AbstractOperationCapabilities::m_numberOfOutputs
std::size_t m_numberOfOutputs
The number of outputs of the operation.
Definition: AbstractOperation.h:192
te::vp::AbstractOperationCapabilities::AbstractOperationCapabilities
AbstractOperationCapabilities(const std::string &operationName, std::size_t numberOfInputs, std::size_t numberOfOutputs, const std::string &dataHandlerName, bool snapGeometries, bool allowCoordinateSubdivision)
Destructor.
te::vp::OperationFactory::OperationFactory
OperationFactory(const std::string &factoryKey)
Constructor.
te::vp::AbstractParameters::AbstractParameters
AbstractParameters()
Default constructor.
te::vp::AbstractOperation::m_aborted
bool m_aborted
Becames true if the abort function is called. Concrete classes must check for this value from time to...
Definition: AbstractOperation.h:297
te::vp::AbstractParameters::setMaxCoordinates
void setMaxCoordinates(std::size_t maxCoordinates)
Returns the current state of the geometry subdivision.
te::vp::AbstractOperationCapabilities::getDataHandlerName
const std::string & getDataHandlerName() const
Checks if the geometries must be snapped to each other before the operation is executed.
te::vp::AbstractParameters::m_swapInput
bool m_swapInput
This is very usefull for operations between 2 dataSets. If TRUE, the input will be swapped....
Definition: AbstractOperation.h:148
te::vp::OperationFactory
Abstract factory used to create Operations.
Definition: AbstractOperation.h:306
te::vp::AbstractParameters
Abstract class used to define the input/ ouptut parameters for TerraAmazon Operations.
Definition: AbstractOperation.h:66
te::vp::AbstractParameters::getMaxCoordinates
std::size_t getMaxCoordinates() const
Sets the input to be swapped. This is very usefull for operations between 2 dataSets....
te::vp::AbstractParameters::m_snapGeometries
bool m_snapGeometries
If TRUE, the geometries will be snapped before the operation is executed. Default is TRUE.
Definition: AbstractOperation.h:149
te::vp::AbstractParameters::getOutputDataAccessVector
const std::vector< te::da::DataAccess * > & getOutputDataAccessVector() const
Sets the input dataAccess vector.
te::vp::AbstractParameters::addOutputDataAccess
void addOutputDataAccess(te::da::DataAccess *dataAccess)
Adds an output data access to the params. Note that if the dataSet does not exist,...
te::vp::AbstractParameters::setOperationResult
void setOperationResult(OperationResult result)
te::vp::AbstractOperation::executeImpl
virtual std::vector< te::vp::FeatureSet > executeImpl(const std::vector< te::vp::FeatureSet > &vecInput)=0
te::vp::AbstractParameters::m_outputDataVector
std::vector< te::da::DataAccess * > m_outputDataVector
Vector with output dataAccess.
Definition: AbstractOperation.h:147
te::vp::AbstractOperationCapabilities::getNumberOfInputs
std::size_t getNumberOfInputs() const
Returns the number of outputs of the operation.
te::vp::AbstractOperationCapabilities::~AbstractOperationCapabilities
virtual ~AbstractOperationCapabilities()
Returns the number of inputs of the operation.
te::vp::AbstractParameters::addInputDataAccess
void addInputDataAccess(te::da::DataAccess *dataAccess)
Adds an input data access to the params.
te::vp::OperationReport
Class used as a report logger for Operations.
Definition: OperationReport.h:48
te::vp::AbstractOperation::initializeOutput
virtual bool initializeOutput()
Function that effectivelly executes the operation. It must be implemented by the concrete classes.
te::vp::AbstractParameters::setSwapInput
void setSwapInput(bool swap)
Returns TRUE if the input must be swaped. FALSE otherwise.
te::vp::AbstractOperation::getOutputGeometryType
te::gm::GeomType getOutputGeometryType() const
Aborts the execution of the operation.
te::da::DataAccess
Class used to centralize and control access to data in terralib. It aims to create a high-level inter...
Definition: DataAccess.h:77
TEVPEXPORT
#define TEVPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61
te::vp::AbstractParameters::m_inputDataVector
std::vector< te::da::DataAccess * > m_inputDataVector
Vector with input dataAccess.
Definition: AbstractOperation.h:146
te::vp::AbstractOperationCapabilities::getNumberOfOutputs
std::size_t getNumberOfOutputs() const
Returns the name of the operation.
te::vp::AbstractOperationCapabilities::m_dataHandlerName
std::string m_dataHandlerName
TRUE if the operation supports the subdivision of the geometries. FALSE otherwise.
Definition: AbstractOperation.h:193
te::vp::AbstractOperation::createBasicOutputDataSetType
virtual te::da::DataSetType * createBasicOutputDataSetType(const std::string &dataSetName, int srid, te::gm::GeomType geometryType, const std::string &geometryColumnName) const
< Creates the basic dataSetType for the output containing all the columns that are required
te::vp::AbstractParameters::setInputDataAccessVector
void setInputDataAccessVector(const std::vector< te::da::DataAccess * > &vecDataAccess)
Sets the output dataAccess vector.
te::vp::AbstractOperation::execute
virtual std::vector< te::vp::FeatureSet > execute(const std::vector< te::vp::FeatureSet > &vecInput)
It executes the operation.
te::vp::AbstractOperationCapabilities::m_operationName
std::string m_operationName
The name of the operation.
Definition: AbstractOperation.h:190
te::vp::AbstractOperation::getCapabilities
virtual std::unique_ptr< te::vp::AbstractOperationCapabilities > getCapabilities() const
Makes all the necessaries adaptations to the input dataAccess to avoid duplicate column names.
te::vp::AbstractOperationCapabilities::getName
const std::string & getName() const
Returns TRUE if the operation supports the subdivision of the geometries. FALSE otherwise.
te::vp::AbstractOperation::getDataSetType
virtual const te::da::DataSetType * getDataSetType(std::size_t outputIndex)
Gets the dataSetType of the 'outputIndex-th' output.
te::vp::AbstractOperation::AbstractOperation
AbstractOperation(const std::string &operationName)
Default constructor.
te::vp::AbstractOperation::prepareOutputData
bool prepareOutputData()
te::vp::AbstractOperation::setParameters
void setParameters(AbstractParameters *params)
Gets the operation current parameters.
te::vp::AbstractOperation::handleOutputPropertyNamesChanges
bool handleOutputPropertyNamesChanges(const te::da::DataSetType *baseOutputDataSetType, const te::da::DataSetType *actualOutputDataSetType)
te::vp::AbstractOperation::initializeInput
virtual bool initializeInput()
Initializes the operation output.
te::vp::AbstractParameters::m_operationResult
OperationResult m_operationResult
Stores the result of the operation.
Definition: AbstractOperation.h:150
te::vp::AbstractOperation::getParameters
AbstractParameters * getParameters() const
Gets the operation report.
te::vp::AbstractParameters::reportSpecificParams
virtual void reportSpecificParams(OperationReport *report)
It reports each specific parameter used in the operation.
te::vp::AbstractParameters::setOutputDataAccessVector
void setOutputDataAccessVector(const std::vector< te::da::DataAccess * > &vecDataAccess)
Enables or disables geometry subdivision.
te::vp::AbstractParameters::getInputDataAccessVector
const std::vector< te::da::DataAccess * > & getInputDataAccessVector() const
Returns the output dataAccess vector.
te::vp::AbstractParameters::m_maxCoordinates
std::size_t m_maxCoordinates
If higher than 0, geometries will be subdivided until all the parts have less vertexes that this valu...
Definition: AbstractOperation.h:151
te::vp::OperationFactory::~OperationFactory
virtual ~OperationFactory()
te::vp::AbstractParameters::~AbstractParameters
virtual ~AbstractParameters()=default
Virtual destructor.
te::vp::AbstractOperationCapabilities
Abstract class used to define the capabilities of the operation, inclusing number of inputs and outpu...
Definition: AbstractOperation.h:160
te::vp::AbstractOperation::m_impl
AbstractOperationImpl * m_impl
Holds all the attributes of the class.
Definition: AbstractOperation.h:296
te::vp::AbstractOperationCapabilities::getSnapGeometries
bool getSnapGeometries() const
Checks if the operation has the capability to handle geometry coordinate subdivision.
te::vp::AbstractOperation::~AbstractOperation
virtual ~AbstractOperation()
Virtual destructor.
te::vp::AbstractOperation::prepareInputData
bool prepareInputData()
te::vp::AbstractParameters::getSwapInput
bool getSwapInput() const
Gets the result of the operation.
te::vp::AbstractParameters::getOperationResult
OperationResult getOperationResult() const
Sets the result of the operation.
te::vp::Feature
A feature is a composition of a geometry and its attributes.
Definition: Feature.h:70
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::vp::AbstractOperationCapabilities::m_numberOfInputs
std::size_t m_numberOfInputs
The number of inputs of the operation.
Definition: AbstractOperation.h:191
te::vp::AbstractOperation::isAborted
bool isAborted() const
Get the capabilities of the operation. Basically, operation will have 2 inputs, 1 output,...
te::vp::AbstractOperation::addOutputColumns
virtual void addOutputColumns(te::da::DataSetType *outputDataSetType)
Initializes the operation input.
te::vp::AbstractParameters::reportParams
void reportParams(OperationReport *report)
It reports each parameter used in the operation.
te::da::DataSetType
A class that models the description of a dataset.
Definition: DataSetType.h:73
te::vp::AbstractOperation::createOutputFeature
virtual te::vp::Feature * createOutputFeature(std::size_t outputIndex)
It creates the output feature based on the given output dataaccess index.
te::gm::GeomType
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:42
te::vp::AbstractOperation
Abstract class used to define an operation.
Definition: AbstractOperation.h:204
te::vp::AbstractOperation::getName
const std::string & getName() const
Gets the output geometry type.
te::vp::AbstractOperationCapabilities::m_allowCoordinateSubdivision
bool m_allowCoordinateSubdivision
TRUE if the operation has the capability to handle geometry coordinate subdivision.
Definition: AbstractOperation.h:195
te::vp::AbstractOperation::getReport
OperationReport * getReport() const
Gets the operation name.
te::vp::AbstractOperationCapabilities::m_snapGeometries
bool m_snapGeometries
TRUE if the geometries must be snapped to each other before the operation is executed....
Definition: AbstractOperation.h:194
te::vp::OperationResult
OperationResult
Definition: AbstractOperation.h:54
te::vp::OperationResult::OP_NOT_STARTED
@ OP_NOT_STARTED
te::vp::AbstractOperationCapabilities::createParameters
virtual std::unique_ptr< AbstractParameters > createParameters() const
te::vp::AbstractParameters::isValid
virtual bool isValid(std::string &errorMessage)
It checks the parameters for the operation.