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  */
103 
104  /*! \brief Destructor. */
106 
107  //@}
108 
109  /*!
110  \brief This method returns the pointer to the DataSetType that is handled by the converter.
111 
112  \return The pointer to the DataSetType that is handled by the converter.
113  */
114  DataSetType* getConvertee();
115 
116  /*!
117  \brief This method returns the name of the properties that have not yet been converted.
118 
119  \param propertyNames A vector that will be filled with the name of the properties that have not yet been converted.
120  */
121  void getNonConvertedProperties(std::vector<std::string>& propertyNames) const;
122 
123  /*!
124  \brief This method returns the position of the properties that have not yet been converted.
125 
126  \param propertyPos A vector that will be filled with the position of the properties that have not yet been converted.
127  */
128  void getNonConvertedProperties(std::vector<std::size_t>& propertyPos) const;
129 
130  /*!
131  \brief This method tells which properties of the input data set type that have been converted based on the given property name.
132 
133  \param propertyName A property name of the DataSetTypeConverter.
134  \param convertedPropertyPos A vector that will be filled with the property positions of the input data set type have been converted.
135  */
136  void getConvertedProperties(const std::string& propertyName, std::vector<std::size_t>& convertedPropertyPos);
137 
138  /*!
139  \brief This method tells which properties of the input data set type that have been converted based on the given property name.
140 
141  \param propertyPos A property position of the DataSetTypeConverter.
142  \param convertedPropertyPos A vector that will be filled with the property positions of the input data set type have been converted.
143  */
144  void getConvertedProperties(std::size_t propertyPos, std::vector<std::size_t>& convertedPropertyPos);
145 
146  /*!
147  \brief This method tells which Attribute Converter was used in the porperty position.
148 
149  \param propertyPos A property position of the DataSetTypeConverter.
150 
151  \return Attribute Converter name.
152  */
153  std::string getConverterName(std::size_t propertyPos);
154 
155  /*!
156  \brief This method removes a property of DataSetTypeConverter.
157 
158  \param propertyName The property name of the DataSetTypeConverter that will be removed.
159  */
160  void remove(const std::string& propertyName);
161 
162  /*!
163  \brief This method removes a property of DataSetTypeConverter.
164 
165  \param propertyPos The property position of the DataSetTypeConverter that will be removed.
166  */
167  void remove(std::size_t propertyPos);
168 
169  /*!
170  \brief It adds a conversions to the given property of the input data set type.
171 
172  \param propertyName The property name that will be converted.
173  \param p The converted property.
174  \param attributeConverterName The function name that will be used to do the property values conversion.
175  */
176  void add(const std::string& propertyName, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
177 
178  /*!
179  \brief It adds a conversions to the given property of the input data set type.
180 
181  \param propertyPos The property position that will be converted.
182  \param p The converted property.
183  \param attributeConverterName The function name that will be used to do the property values conversion.
184  */
185  void add(std::size_t propertyPos, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
186 
187  /*!
188  \brief It adds a conversions to the given property of the input data set type.
189 
190  \param propertyPos The property position that will be converted.
191  \param p The converted property.
192  \param conv The function that will be used to do the property values conversion.
193  */
194  void add(std::size_t propertyPos, te::dt::Property* p, AttributeConverter conv);
195 
196  /*!
197  \brief It adds a conversion to the given properties of the input data set type.
198 
199  \param propertyNames The property names that will be converted.
200  \param p The converted property.
201  \param attributeConverterName The function name that will be used to do the property values conversion.
202  */
203  void add(const std::vector<std::string>& propertyNames, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
204 
205  /*!
206  \brief It adds a conversion to the given properties of the input data set type.
207 
208  \param propertyPos The property positions that will be converted.
209  \param p The converted property.
210  \param attributeConverterName The function name that will be used to do the property values conversion.
211  */
212  void add(const std::vector<std::size_t>& propertyPos, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
213 
214  /*!
215  \brief It adds a conversion to the given properties of the input data set type.
216 
217  \param propertyPos The property positions that will be converted.
218  \param p The converted property.
219  \param conv The function that will be used to do the property values conversion.
220  */
221  void add(const std::vector<std::size_t>& propertyPos, te::dt::Property* p, AttributeConverter conv);
222 
223  /*!
224  \brief Static method that verifies if the given data set type need an converter based on given data source capabilities.
225 
226  \param type The data set type that will be verified.
227  \param capabilities The data source capabilities that will be used.
228 
229  \return Return true if the given data set type need a converter. Otherwise, return false.
230  */
231  static bool needConverter(DataSetType* type, const DataSourceCapabilities& capabilities);
232 
233  DataSetType* getResult() const;
234 
235  const std::vector<std::vector<std::size_t> >& getConvertedPropertyIndexes() const;
236 
237  const std::vector<AttributeConverter>& getConverters() const;
238 
239  private:
240 
241  bool isConverted(std::size_t i) const;
242 
243  private:
244 
245  DataSetType* m_inDataSetType; //!< A pointer to DataSetType that will be converted.
246  DataSetType* m_outDataSetType; //!< The converted DataSetType.
247  std::vector<std::vector<std::size_t> > m_propertyIndexes; //!< A vector that stores the converted property indexes.
248  std::vector<AttributeConverter> m_converters; //!< A vector that stores the attribute converters functions.
249  std::vector<std::string> m_functionsNames; //!< A vector that stores the attribute converters functions names.
250  std::vector<std::size_t> m_convertedProperties; //!< Internal vector to count the references to converted properties.
251  };
252 
253  } // end namespace da
254 } // end namespace te
255 
256 #endif // __TERRALIB_DATAACCESS_INTERNAL_DATASETTYPECONVERTER_H
DataSetType * m_outDataSetType
The converted DataSetType.
A class that models the description of a dataset.
Definition: DataSetType.h:72
std::vector< std::vector< std::size_t > > m_propertyIndexes
A vector that stores the converted property indexes.
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:59
EncodingType
Supported character encodings.
Definition: CharEncoding.h:50
An converter for DataSetType.
te::da::DataSourceCapabilities capabilities
URI C++ Library.
boost::function3< te::dt::AbstractData *, DataSet *, const std::vector< std::size_t > &, int > AttributeConverter
The type of attribute converter functions.
Definition of attribute converter and a set of them.
std::vector< std::size_t > m_convertedProperties
Internal vector to count the references to converted properties.
std::vector< AttributeConverter > m_converters
A vector that stores the attribute converters functions.
DataSetType * m_inDataSetType
A pointer to DataSetType that will be converted.
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97
An adapter for DataSet.
std::vector< std::string > m_functionsNames
A vector that stores the attribute converters functions names.