Loading...
Searching...
No Matches
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
37namespace 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 */
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
Definition of attribute converter and a set of them.
te::da::DataSourceCapabilities capabilities
An adapter for DataSet.
An converter for DataSetType.
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.
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...
DataSetTypeConverter & operator=(const DataSetTypeConverter &other)
std::vector< AttributeConverter > m_converters
A vector that stores the attribute converters functions.
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...
DataSetTypeConverter(const DataSetType *type)
Constructor.
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.
~DataSetTypeConverter()
Destructor.
te::core::EncodingType m_encondingType
The enconding type used.
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...
std::vector< std::string > m_functionsNames
A vector that stores the attribute converters functions names.
void remove(std::size_t propertyPos)
This method removes a property of DataSetTypeConverter.
DataSetTypeConverter(const DataSetTypeConverter &other)
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.
void setEncodingType(te::core::EncodingType et)
It changes all encoding types from m_converters property that are CharEncodingConverter type.
te::core::EncodingType getEncodingType()
It gets the encoding type used to convert.
std::vector< std::vector< std::size_t > > m_propertyIndexes
A vector that stores the converted property indexes.
DataSetType * getConvertee()
This method returns the pointer to the DataSetType that is handled by the converter.
void remove(const std::string &propertyName)
This method removes a property of DataSetTypeConverter.
DataSetType * getResult() const
std::string getConverterName(std::size_t propertyPos)
This method tells which Attribute Converter was used in the porperty position.
void getNonConvertedProperties(std::vector< std::size_t > &propertyPos) const
This method returns the position of the properties that have not yet been converted.
void getNonConvertedProperties(std::vector< std::string > &propertyNames) const
This method returns the name of the properties that have not yet been converted.
const std::vector< AttributeConverter > & getConverters() const
DataSetTypeConverter(const DataSetType *type, const DataSourceCapabilities &capabilities, te::core::EncodingType et=te::core::EncodingType::UTF8)
Constructor.
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.
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.
DataSetType * m_inDataSetType
A pointer to DataSetType that will be converted.
std::vector< std::size_t > m_convertedProperties
Internal vector to count the references to converted properties.
bool isConverted(std::size_t i) const
DataSetType * m_outDataSetType
The converted DataSetType.
const std::vector< std::vector< std::size_t > > & getConvertedPropertyIndexes() const
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.
A class that models the description of a dataset.
Definition: DataSetType.h:73
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
It models a property definition.
Definition: Property.h:60
EncodingType
Supported character encodings.
Definition: CharEncoding.h:51
boost::function3< te::dt::AbstractData *, DataSet *, const std::vector< std::size_t > &, int > AttributeConverter
The type of attribute converter functions.
TerraLib.
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97