DataSetTypeConverter.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/dataaccess/dataset/DataSetTypeConverter.h
22 
23  \brief An converter for DataSetType.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_DATASETTYPECONVERTER_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_DATASETTYPECONVERTER_H
28 
29 // TerraLib
30 #include "../Config.h"
31 #include "AttributeConverters.h"
32 #include "../../core/encoding/CharEncoding.h"
33 
34 // STL
35 #include <vector>
36 
37 namespace te
38 {
39 // Forward declaration
40  namespace dt
41  {
42  class Property;
43  }
44 
45  namespace da
46  {
47 // Forward declaration
48  class DataSetAdapter;
49  class DataSetType;
50  class DataSourceCapabilities;
51 
52  /*!
53  \class DataSetTypeConverter
54 
55  \brief An converter for DataSetType.
56 
57  \sa DataSetType
58  */
60  {
61  friend class DataSetAdapter;
62 
63  public:
64 
65  /** @name Constructor/Destructor
66  * Initilizer methods.
67  */
68  //@{
69 
70  /*!
71  \brief Constructor.
72 
73  \param type A pointer to the DataSetType that will be converted.
74 
75  \note Here no automatic property conversion will be made.
76  \note The method "add" can be used to do manual conversions.
77 
78  \note This class will NOT take the ownership of the given pointer.
79 
80  \sa DataSetType
81  */
83 
84  /*!
85  \brief Constructor.
86 
87  \param type A pointer to the DataSetType that will be converted.
88  \param capabilities A data source capabilities of the data source that the user intend use.
89  e.g. the data source where the given data set type will be saved.
90  \param ce The destintion character encoding.
91 
92  \note This method will try to create automatic property conversions based on the given capabilities.
93  Here we will look up the data type support of DataSourceCapabilities.
94  If there is not support for a given data type, the method "getHint" will be used in attempt to retrieve an appropriate data type.
95 
96  \note If the method "getHint" does not inform any hint, the specific property will not have a conversion.
97  \note The method "add" can be used to do manual conversions.
98  \note The method "getNonConvertedProperties" can be used to retrieve that properties that have no defined conversion.
99 
100  \sa DataSetType, DataSourceCapabilities DataTypeCapabilities
101  */
102  DataSetTypeConverter(const DataSetType* type, const DataSourceCapabilities& capabilities, te::core::EncodingType et = te::core::EncodingType::UTF8);
103 
104  /*! \brief Destructor. */
106 
107  private:
108 
110 
112  //@}
113 
114  public:
115 
116  /*!
117  \brief This method returns the pointer to the DataSetType that is handled by the converter.
118 
119  \return The pointer to the DataSetType that is handled by the converter.
120  */
122 
123  /*!
124  \brief This method returns the name of the properties that have not yet been converted.
125 
126  \param propertyNames A vector that will be filled with the name of the properties that have not yet been converted.
127  */
128  void getNonConvertedProperties(std::vector<std::string>& propertyNames) const;
129 
130  /*!
131  \brief This method returns the position of the properties that have not yet been converted.
132 
133  \param propertyPos A vector that will be filled with the position of the properties that have not yet been converted.
134  */
135  void getNonConvertedProperties(std::vector<std::size_t>& propertyPos) const;
136 
137  /*!
138  \brief This method tells which properties of the input data set type that have been converted based on the given property name.
139 
140  \param propertyName A property name of the DataSetTypeConverter.
141  \param convertedPropertyPos A vector that will be filled with the property positions of the input data set type have been converted.
142  */
143  void getConvertedProperties(const std::string& propertyName, std::vector<std::size_t>& convertedPropertyPos);
144 
145  /*!
146  \brief This method tells which properties of the input data set type that have been converted based on the given property name.
147 
148  \param propertyPos A property position of the DataSetTypeConverter.
149  \param convertedPropertyPos A vector that will be filled with the property positions of the input data set type have been converted.
150  */
151  void getConvertedProperties(std::size_t propertyPos, std::vector<std::size_t>& convertedPropertyPos);
152 
153  /*!
154  \brief This method tells which Attribute Converter was used in the porperty position.
155 
156  \param propertyPos A property position of the DataSetTypeConverter.
157 
158  \return Attribute Converter name.
159  */
160  std::string getConverterName(std::size_t propertyPos);
161 
162  /*!
163  \brief This method removes a property of DataSetTypeConverter.
164 
165  \param propertyName The property name of the DataSetTypeConverter that will be removed.
166  */
167  void remove(const std::string& propertyName);
168 
169  /*!
170  \brief This method removes a property of DataSetTypeConverter.
171 
172  \param propertyPos The property position of the DataSetTypeConverter that will be removed.
173  */
174  void remove(std::size_t propertyPos);
175 
176  /*!
177  \brief It adds a conversions to the given property of the input data set type.
178 
179  \param propertyName The property name that will be converted.
180  \param p The converted property.
181  \param attributeConverterName The function name that will be used to do the property values conversion.
182  */
183  void add(const std::string& propertyName, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
184 
185  /*!
186  \brief It adds a conversions to the given property of the input data set type.
187 
188  \param propertyPos The property position that will be converted.
189  \param p The converted property.
190  \param attributeConverterName The function name that will be used to do the property values conversion.
191  */
192  void add(std::size_t propertyPos, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
193 
194  /*!
195  \brief It adds a conversions to the given property of the input data set type.
196 
197  \param propertyPos The property position that will be converted.
198  \param p The converted property.
199  \param conv The function that will be used to do the property values conversion.
200  */
201  void add(std::size_t propertyPos, te::dt::Property* p, AttributeConverter conv);
202 
203  /*!
204  \brief It adds a conversion to the given properties of the input data set type.
205 
206  \param propertyNames The property names that will be converted.
207  \param p The converted property.
208  \param attributeConverterName The function name that will be used to do the property values conversion.
209  */
210  void add(const std::vector<std::string>& propertyNames, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
211 
212  /*!
213  \brief It adds a conversion to the given properties of the input data set type.
214 
215  \param propertyPos The property positions that will be converted.
216  \param p The converted property.
217  \param attributeConverterName The function name that will be used to do the property values conversion.
218  */
219  void add(const std::vector<std::size_t>& propertyPos, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
220 
221  /*!
222  \brief It adds a conversion to the given properties of the input data set type.
223 
224  \param propertyPos The property positions that will be converted.
225  \param p The converted property.
226  \param conv The function that will be used to do the property values conversion.
227  */
228  void add(const std::vector<std::size_t>& propertyPos, te::dt::Property* p, AttributeConverter conv);
229 
230  /*!
231  \brief It gets the encoding type used to convert.
232  \return The destintion character encoding.
233  */
235 
236  /*!
237  \brief It changes all encoding types from m_converters property that are CharEncodingConverter type.
238  \param et The destintion character encoding.
239  */
241 
242  /*!
243  \brief Static method that verifies if the given data set type need an converter based on given data source capabilities.
244 
245  \param type The data set type that will be verified.
246  \param capabilities The data source capabilities that will be used.
247 
248  \return Return true if the given data set type need a converter. Otherwise, return false.
249  */
251 
253 
254  const std::vector<std::vector<std::size_t> >& getConvertedPropertyIndexes() const;
255 
256  const std::vector<AttributeConverter>& getConverters() const;
257 
258  private:
259 
260  bool isConverted(std::size_t i) const;
261 
262  private:
263 
264  DataSetType* m_inDataSetType; //!< A pointer to DataSetType that will be converted.
265  DataSetType* m_outDataSetType; //!< The converted DataSetType.
266  te::core::EncodingType m_encondingType; //!< The enconding type used.
267  std::vector<std::vector<std::size_t> > m_propertyIndexes; //!< A vector that stores the converted property indexes.
268  std::vector<AttributeConverter> m_converters; //!< A vector that stores the attribute converters functions.
269  std::vector<std::string> m_functionsNames; //!< A vector that stores the attribute converters functions names.
270  std::vector<std::size_t> m_convertedProperties; //!< Internal vector to count the references to converted properties.
271  };
272 
273  } // end namespace da
274 } // end namespace te
275 
276 #endif // __TERRALIB_DATAACCESS_INTERNAL_DATASETTYPECONVERTER_H
te::da::DataSetTypeConverter::getNonConvertedProperties
void getNonConvertedProperties(std::vector< std::string > &propertyNames) const
This method returns the name of the properties that have not yet been converted.
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::da::DataSetTypeConverter::m_convertedProperties
std::vector< std::size_t > m_convertedProperties
Internal vector to count the references to converted properties.
Definition: DataSetTypeConverter.h:270
te::da::DataSetTypeConverter::add
void add(const std::vector< std::size_t > &propertyPos, te::dt::Property *p, AttributeConverter conv)
It adds a conversion to the given properties of the input data set type.
AttributeConverters.h
Definition of attribute converter and a set of them.
te::da::DataSetTypeConverter::add
void add(const std::vector< std::string > &propertyNames, te::dt::Property *p, const std::string &attributeConverterName="GenericAttributeConverter")
It adds a conversion to the given properties of the input data set type.
te::da::DataSetTypeConverter::add
void add(const std::string &propertyName, te::dt::Property *p, const std::string &attributeConverterName="GenericAttributeConverter")
It adds a conversions to the given property of the input data set type.
te::da::DataSetTypeConverter::DataSetTypeConverter
DataSetTypeConverter(const DataSetTypeConverter &other)
te::da::DataSetTypeConverter::operator=
DataSetTypeConverter & operator=(const DataSetTypeConverter &other)
te::da::DataSetTypeConverter::m_outDataSetType
DataSetType * m_outDataSetType
The converted DataSetType.
Definition: DataSetTypeConverter.h:265
te::da::DataSetTypeConverter::add
void add(std::size_t propertyPos, te::dt::Property *p, AttributeConverter conv)
It adds a conversions to the given property of the input data set type.
te::da::DataSetTypeConverter::m_encondingType
te::core::EncodingType m_encondingType
The enconding type used.
Definition: DataSetTypeConverter.h:266
te::da::DataSetTypeConverter::getConvertedProperties
void getConvertedProperties(const std::string &propertyName, std::vector< std::size_t > &convertedPropertyPos)
This method tells which properties of the input data set type that have been converted based on the g...
TEDATAACCESSEXPORT
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97
te::da::DataSetTypeConverter::getNonConvertedProperties
void getNonConvertedProperties(std::vector< std::size_t > &propertyPos) const
This method returns the position of the properties that have not yet been converted.
te::da::DataSetTypeConverter::add
void add(const std::vector< std::size_t > &propertyPos, te::dt::Property *p, const std::string &attributeConverterName="GenericAttributeConverter")
It adds a conversion to the given properties of the input data set type.
te::da::DataSetTypeConverter::getConverterName
std::string getConverterName(std::size_t propertyPos)
This method tells which Attribute Converter was used in the porperty position.
capabilities
te::da::DataSourceCapabilities capabilities
Definition: PostGISCapabilities.h:129
te::da::DataSetAdapter
An adapter for DataSet.
Definition: DataSetAdapter.h:53
te::da::DataSetTypeConverter::getConvertedPropertyIndexes
const std::vector< std::vector< std::size_t > > & getConvertedPropertyIndexes() const
te::da::DataSetTypeConverter::setEncodingType
void setEncodingType(te::core::EncodingType et)
It changes all encoding types from m_converters property that are CharEncodingConverter type.
te::da::DataSetTypeConverter::getConvertee
DataSetType * getConvertee()
This method returns the pointer to the DataSetType that is handled by the converter.
te::da::DataSetTypeConverter::~DataSetTypeConverter
~DataSetTypeConverter()
Destructor.
te::da::DataSetTypeConverter::m_converters
std::vector< AttributeConverter > m_converters
A vector that stores the attribute converters functions.
Definition: DataSetTypeConverter.h:268
te::da::DataSetTypeConverter::m_propertyIndexes
std::vector< std::vector< std::size_t > > m_propertyIndexes
A vector that stores the converted property indexes.
Definition: DataSetTypeConverter.h:267
te::da::DataSetTypeConverter::isConverted
bool isConverted(std::size_t i) const
te::da::DataSetTypeConverter::getEncodingType
te::core::EncodingType getEncodingType()
It gets the encoding type used to convert.
te::da::DataSetTypeConverter::getConverters
const std::vector< AttributeConverter > & getConverters() const
te::da::DataSetTypeConverter::DataSetTypeConverter
DataSetTypeConverter(const DataSetType *type)
Constructor.
te::da::DataSetTypeConverter::DataSetTypeConverter
DataSetTypeConverter(const DataSetType *type, const DataSourceCapabilities &capabilities, te::core::EncodingType et=te::core::EncodingType::UTF8)
Constructor.
te::da::DataSetTypeConverter::getConvertedProperties
void getConvertedProperties(std::size_t propertyPos, std::vector< std::size_t > &convertedPropertyPos)
This method tells which properties of the input data set type that have been converted based on the g...
te::da::DataSetTypeConverter::getResult
DataSetType * getResult() const
te::da::DataSourceCapabilities
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
Definition: DataSourceCapabilities.h:56
te::da::DataSetTypeConverter::m_functionsNames
std::vector< std::string > m_functionsNames
A vector that stores the attribute converters functions names.
Definition: DataSetTypeConverter.h:269
te::da::DataSetTypeConverter::add
void add(std::size_t propertyPos, te::dt::Property *p, const std::string &attributeConverterName="GenericAttributeConverter")
It adds a conversions to the given property of the input data set type.
te::dt::Property
It models a property definition.
Definition: Property.h:60
te::core::EncodingType
EncodingType
Supported character encodings.
Definition: CharEncoding.h:51
te::da::DataSetTypeConverter::needConverter
static bool needConverter(DataSetType *type, const DataSourceCapabilities &capabilities)
Static method that verifies if the given data set type need an converter based on given data source c...
te::da::DataSetType
A class that models the description of a dataset.
Definition: DataSetType.h:73
te::da::DataSetTypeConverter::m_inDataSetType
DataSetType * m_inDataSetType
A pointer to DataSetType that will be converted.
Definition: DataSetTypeConverter.h:264
te::da::AttributeConverter
boost::function3< te::dt::AbstractData *, DataSet *, const std::vector< std::size_t > &, int > AttributeConverter
The type of attribute converter functions.
Definition: AttributeConverters.h:51
te::da::DataSetTypeConverter::remove
void remove(const std::string &propertyName)
This method removes a property of DataSetTypeConverter.
te::da::DataSetTypeConverter
An converter for DataSetType.
Definition: DataSetTypeConverter.h:60
te::da::DataSetTypeConverter::remove
void remove(std::size_t propertyPos)
This method removes a property of DataSetTypeConverter.