All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataSetTypeConverter.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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 
33 // STL
34 #include <vector>
35 
36 namespace te
37 {
38 // Forward declaration
39  namespace dt
40  {
41  class Property;
42  }
43 
44  namespace da
45  {
46 // Forward declaration
47  class DataSetAdapter;
48  class DataSetType;
49  class DataSourceCapabilities;
50 
51  /*!
52  \class DataSetTypeConverter
53 
54  \brief An converter for DataSetType.
55 
56  \sa DataSetType
57  */
59  {
60  friend class DataSetAdapter;
61 
62  public:
63 
64  /** @name Constructor/Destructor
65  * Initilizer methods.
66  */
67  //@{
68 
69  /*!
70  \brief Constructor.
71 
72  \param type A pointer to the DataSetType that will be converted.
73 
74  \note Here no automatic property conversion will be made.
75  \note The method "add" can be used to do manual conversions.
76 
77  \note This class will NOT take the ownership of the given pointer.
78 
79  \sa DataSetType
80  */
82 
83  /*!
84  \brief Constructor.
85 
86  \param type A pointer to the DataSetType that will be converted.
87  \param capabilities A data source capabilities of the data source that the user intend use.
88  e.g. the data source where the given data set type will be saved.
89 
90  \note This method will try to create automatic property conversions based on the given capabilities.
91  Here we will look up the data type support of DataSourceCapabilities.
92  If there is not support for a given data type, the method "getHint" will be used in attempt to retrieve an appropriate data type.
93 
94  \note If the method "getHint" does not inform any hint, the specific property will not have a conversion.
95  \note The method "add" can be used to do manual conversions.
96  \note The method "getNonConvertedProperties" can be used to retrieve that properties that have no defined conversion.
97 
98  \sa DataSetType, DataSourceCapabilities DataTypeCapabilities
99  */
101 
102  /*! \brief Destructor. */
104 
105  //@}
106 
107  /*!
108  \brief This method returns the pointer to the DataSetType that is handled by the converter.
109 
110  \return The pointer to the DataSetType that is handled by the converter.
111  */
112  DataSetType* getConvertee();
113 
114  /*!
115  \brief This method returns the name of the properties that have not yet been converted.
116 
117  \param propertyNames A vector that will be filled with the name of the properties that have not yet been converted.
118  */
119  void getNonConvertedProperties(std::vector<std::string>& propertyNames) const;
120 
121  /*!
122  \brief This method returns the position of the properties that have not yet been converted.
123 
124  \param propertyPos A vector that will be filled with the position of the properties that have not yet been converted.
125  */
126  void getNonConvertedProperties(std::vector<std::size_t>& propertyPos) const;
127 
128  /*!
129  \brief This method tells which properties of the input data set type that have been converted based on the given property name.
130 
131  \param propertyName A property name of the DataSetTypeConverter.
132  \param convertedPropertyPos A vector that will be filled with the property positions of the input data set type have been converted.
133  */
134  void getConvertedProperties(const std::string& propertyName, std::vector<std::size_t>& convertedPropertyPos);
135 
136  /*!
137  \brief This method tells which properties of the input data set type that have been converted based on the given property name.
138 
139  \param propertyPos A property position of the DataSetTypeConverter.
140  \param convertedPropertyPos A vector that will be filled with the property positions of the input data set type have been converted.
141  */
142  void getConvertedProperties(std::size_t propertyPos, std::vector<std::size_t>& convertedPropertyPos);
143 
144  /*!
145  \brief This method tells which Attribute Converter was used in the porperty position.
146 
147  \param propertyPos A property position of the DataSetTypeConverter.
148 
149  \return Attribute Converter name.
150  */
151  std::string getConverterName(std::size_t propertyPos);
152 
153  /*!
154  \brief This method removes a property of DataSetTypeConverter.
155 
156  \param propertyName The property name of the DataSetTypeConverter that will be removed.
157  */
158  void remove(const std::string& propertyName);
159 
160  /*!
161  \brief This method removes a property of DataSetTypeConverter.
162 
163  \param propertyPos The property position of the DataSetTypeConverter that will be removed.
164  */
165  void remove(std::size_t propertyPos);
166 
167  /*!
168  \brief It adds a conversions to the given property of the input data set type.
169 
170  \param propertyName The property name that will be converted.
171  \param p The converted property.
172  \param attributeConverterName The function name that will be used to do the property values conversion.
173  */
174  void add(const std::string& propertyName, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
175 
176  /*!
177  \brief It adds a conversions to the given property of the input data set type.
178 
179  \param propertyPos The property position 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(std::size_t propertyPos, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
184 
185  /*!
186  \brief It adds a conversion to the given properties of the input data set type.
187 
188  \param propertyNames The property names 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(const std::vector<std::string>& propertyNames, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
193 
194  /*!
195  \brief It adds a conversion to the given properties of the input data set type.
196 
197  \param propertyPos The property positions that will be converted.
198  \param p The converted property.
199  \param attributeConverterName The function name that will be used to do the property values conversion.
200  */
201  void add(const std::vector<std::size_t>& propertyPos, te::dt::Property* p, const std::string& attributeConverterName = "GenericAttributeConverter");
202 
203  /*!
204  \brief Static method that verifies if the given data set type need an converter based on given data source capabilities.
205 
206  \param type The data set type that will be verified.
207  \param capabilities The data source capabilities that will be used.
208 
209  \return Return true if the given data set type need a converter. Otherwise, return false.
210  */
211  static bool needConverter(DataSetType* type, const DataSourceCapabilities& capabilities);
212 
213  DataSetType* getResult() const;
214 
215  const std::vector<std::vector<std::size_t> >& getConvertedPropertyIndexes() const;
216 
217  const std::vector<AttributeConverter>& getConverters() const;
218 
219  private:
220 
221  bool isConverted(std::size_t i) const;
222 
223  private:
224 
225  DataSetType* m_inDataSetType; //!< A pointer to DataSetType that will be converted.
226  DataSetType* m_outDataSetType; //!< The converted DataSetType.
227  std::vector<std::vector<std::size_t> > m_propertyIndexes; //!< A vector that stores the converted property indexes.
228  std::vector<AttributeConverter> m_converters; //!< A vector that stores the attribute converters functions.
229  std::vector<std::string> m_functionsNames; //!< A vector that stores the attribute converters functions names.
230  std::vector<std::size_t> m_convertedProperties; //!< Internal vector to count the references to converted properties.
231  };
232 
233  } // end namespace da
234 } // end namespace te
235 
236 #endif // __TERRALIB_DATAACCESS_INTERNAL_DATASETTYPECONVERTER_H
std::vector< std::size_t > m_convertedProperties
Internal vector to count the references to converted properties.
An converter for DataSetType.
DataSetType * m_outDataSetType
The converted DataSetType.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:135
std::vector< std::string > m_functionsNames
A vector that stores the attribute converters functions names.
Definition of attribute converter and a set of them.
DataSetType * m_inDataSetType
A pointer to DataSetType that will be converted.
A class that models the description of a dataset.
Definition: DataSetType.h:72
It models a property definition.
Definition: Property.h:59
std::vector< AttributeConverter > m_converters
A vector that stores the attribute converters functions.
std::vector< std::vector< std::size_t > > m_propertyIndexes
A vector that stores the converted property indexes.
te::da::DataSourceCapabilities capabilities
An adapter for DataSet.