src/terralib/dataaccess/dataset/DataSetAdapter.cpp
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/DataSetAdapter.cpp
22 
23  \brief An adapter for DataSet.
24 */
25 
26 // TerraLib
27 #include "../../core/translator/Translator.h"
28 #include "../../datatype/Array.h"
29 #include "../../datatype/ByteArray.h"
30 #include "../../datatype/DataConverterManager.h"
31 #include "../../datatype/DateTime.h"
32 #include "../../datatype/Enums.h"
33 #include "../../datatype/Property.h"
34 #include "../../datatype/SimpleData.h"
35 #include "../../geometry/Geometry.h"
36 #include "../../geometry/GeometryProperty.h"
37 #include "../../geometry/Envelope.h"
38 #include "../../raster/Raster.h"
39 #include "../../srs/Config.h"
40 #include "../datasource/DataSourceCapabilities.h"
41 #include "../utils/Utils.h"
42 #include "../Exception.h"
43 #include "DataSetAdapter.h"
44 #include "DataSetType.h"
45 
46 // STL
47 #include <cassert>
48 #include <memory>
49 
51  : m_ds(dataset, isOwner)
52 {
53  assert(dataset);
54 }
55 
57 
59 {
60  return m_ds->getTraverseType();
61 }
62 
64 {
65  return m_ds->getAccessPolicy();
66 }
67 
68 std::unique_ptr<te::gm::Envelope> te::da::DataSetAdapter::getExtent(std::size_t i)
69 {
70  return m_ds->getExtent(i);
71 }
72 
74 {
75  return m_pnames.size();
76 }
77 
79 {
80  return m_datatypes[pos];
81 }
82 
83 std::string te::da::DataSetAdapter::getPropertyName(std::size_t pos) const
84 {
85  return m_pnames[pos];
86 }
87 
89  std::size_t /*pos*/) const
90 {
91  return "";
92 }
93 
95 {
96  return m_ds->isEmpty();
97 }
98 
100 {
101  return m_ds->isConnected();
102 }
103 
104 std::size_t te::da::DataSetAdapter::size() const
105 {
106  return m_ds->size();
107 }
108 
110 {
111  return m_ds->moveNext();
112 }
113 
115 {
116  return m_ds->movePrevious();
117 }
118 
120 {
121  return m_ds->moveBeforeFirst();
122 }
123 
125 {
126  return m_ds->moveFirst();
127 }
128 
130 {
131  return m_ds->moveLast();
132 }
133 
134 bool te::da::DataSetAdapter::move(std::size_t i)
135 {
136  return m_ds->move(i);
137 }
138 
140 {
141  return m_ds->isAtBegin();
142 }
143 
145 {
146  return m_ds->isBeforeBegin();
147 }
148 
150 {
151  return m_ds->isAtEnd();
152 }
153 
155 {
156  return m_ds->isAfterEnd();
157 }
158 
160 {
161  return m_ds->isPositionValid();
162 }
163 
164 char te::da::DataSetAdapter::getChar(std::size_t i) const
165 {
166  std::unique_ptr<te::dt::Char> data(static_cast<te::dt::Char*>(getAdaptedValue(i)));
167 
168  return data->getValue();
169 }
170 
171 unsigned char te::da::DataSetAdapter::getUChar(std::size_t i) const
172 {
173  std::unique_ptr<te::dt::UChar> data(static_cast<te::dt::UChar*>(getAdaptedValue(i)));
174 
175  return data->getValue();
176 }
177 
178 boost::int16_t te::da::DataSetAdapter::getInt16(std::size_t i) const
179 {
180  std::unique_ptr<te::dt::Int16> data(static_cast<te::dt::Int16*>(getAdaptedValue(i)));
181 
182  return data->getValue();
183 }
184 
185 boost::int32_t te::da::DataSetAdapter::getInt32(std::size_t i) const
186 {
187  std::unique_ptr<te::dt::Int32> data(static_cast<te::dt::Int32*>(getAdaptedValue(i)));
188 
189  return data->getValue();
190 }
191 
192 boost::int64_t te::da::DataSetAdapter::getInt64(std::size_t i) const
193 {
194  std::unique_ptr<te::dt::Int64> data(static_cast<te::dt::Int64*>(getAdaptedValue(i)));
195 
196  return data->getValue();
197 }
198 
199 bool te::da::DataSetAdapter::getBool(std::size_t i) const
200 {
201  std::unique_ptr<te::dt::Boolean> data(static_cast<te::dt::Boolean*>(getAdaptedValue(i)));
202 
203  return data->getValue();
204 }
205 
206 float te::da::DataSetAdapter::getFloat(std::size_t i) const
207 {
208  std::unique_ptr<te::dt::Float> data(static_cast<te::dt::Float*>(getAdaptedValue(i)));
209 
210  return data->getValue();
211 }
212 
213 double te::da::DataSetAdapter::getDouble(std::size_t i) const
214 {
215  std::unique_ptr<te::dt::Double> data(static_cast<te::dt::Double*>(getAdaptedValue(i)));
216 
217  return data->getValue();
218 }
219 
220 std::string te::da::DataSetAdapter::getNumeric(std::size_t i) const
221 {
222  std::unique_ptr<te::dt::Numeric> data(static_cast<te::dt::Numeric*>(getAdaptedValue(i)));
223 
224  return data->getValue();
225 }
226 
227 std::string te::da::DataSetAdapter::getString(std::size_t i) const
228 {
229  std::unique_ptr<te::dt::String> data(static_cast<te::dt::String*>(getAdaptedValue(i)));
230  return data->getValue();
231 }
232 
233 std::unique_ptr<te::dt::ByteArray> te::da::DataSetAdapter::getByteArray(std::size_t i) const
234 {
235  return std::unique_ptr<te::dt::ByteArray>(static_cast<te::dt::ByteArray*>(getAdaptedValue(i)));
236 }
237 
238 std::unique_ptr<te::gm::Geometry> te::da::DataSetAdapter::getGeometry(std::size_t i) const
239 {
240  return std::unique_ptr<te::gm::Geometry>(static_cast<te::gm::Geometry*>(getAdaptedValue(i)));
241 }
242 
243 std::unique_ptr<te::rst::Raster> te::da::DataSetAdapter::getRaster(std::size_t i) const
244 {
245  return std::unique_ptr<te::rst::Raster>(static_cast<te::rst::Raster*>(getAdaptedValue(i)));
246 }
247 
248 std::unique_ptr<te::dt::DateTime> te::da::DataSetAdapter::getDateTime(std::size_t i) const
249 {
250  return std::unique_ptr<te::dt::DateTime>(static_cast<te::dt::DateTime*>(getAdaptedValue(i)));
251 }
252 
253 std::unique_ptr<te::dt::Array> te::da::DataSetAdapter::getArray(std::size_t i) const
254 {
255  return std::unique_ptr<te::dt::Array>(static_cast<te::dt::Array*>(getAdaptedValue(i)));
256 }
257 
258 bool te::da::DataSetAdapter::isNull(std::size_t i) const
259 {
260  std::unique_ptr<te::dt::AbstractData> data(getAdaptedValue(i));
261 
262  return data.get() == nullptr;
263 }
264 
266 {
267  return m_ds.get();
268 }
269 
270 void te::da::DataSetAdapter::add(const std::string& newPropertyName,
271  int newPropertyType,
272  const std::vector<std::size_t>& adaptedPropertyPos,
273  AttributeConverter conv)
274 {
275  m_datatypes.push_back(newPropertyType);
276  m_pnames.push_back(newPropertyName);
277  m_propertyIndexes.push_back(adaptedPropertyPos);
278  m_converters.push_back(conv);
279 }
280 
282 {
284 
285  return data;
286 }
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not...
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
bool getBool(std::size_t i) const
Method for retrieving a boolean attribute value.
std::string getPropertyName(std::size_t pos) const
It returns the property name at position pos.
te::dt::AbstractData * getAdaptedValue(std::size_t i) const
te::common::TraverseType getTraverseType() const
It returns the traverse type associated to the dataset.
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
std::unique_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
te::common::Holder< DataSet > m_ds
A pointer to the DataSet that will be handled by adapter.
std::vector< std::vector< std::size_t > > m_propertyIndexes
A vector that stores the adapted property indexes.
std::vector< AttributeConverter > m_converters
A vector that stores the attribute converters functions.
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
std::vector< int > m_datatypes
The datatype for each property.
~DataSetAdapter()
Destructor.
bool isNull(std::size_t i) const
It checks if the attribute value is NULL.
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
int getPropertyDataType(std::size_t pos) const
It returns the underlying data type of the property at position pos.
std::string getDatasetNameOfProperty(std::size_t pos) const
It returns the underlying dataset name of the property at position pos.
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
bool isPositionValid() const
It tells if the dataset internal pointer is on a valid position.
te::da::DataSet * getAdaptee() const
This method returns the pointer to the DataSet that is handled by adapter.
char getChar(std::size_t i) const
Method for retrieving a signed character attribute value (1 byte long).
The type for variable-length multidimensional arrays.
Definition: Array.h:59
An abstract class for raster data strucutures.
An adapter for DataSet.
unsigned char getUChar(std::size_t i) const
Method for retrieving an unsigned character attribute value (1 byte long).
std::unique_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
boost::function3< te::dt::AbstractData *, DataSet *, const std::vector< std::size_t > &, int > AttributeConverter
The type of attribute converter functions.
float getFloat(std::size_t i) const
Method for retrieving a float attribute value.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
bool isEmpty() const
It returns true if the collection is empty.
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
void add(const std::string &newPropertyName, int newPropertyType, const std::vector< std::size_t > &adaptedPropertyPos, AttributeConverter conv)
bool isAfterEnd() const
It tells if the dataset internal pointer is on the sentinel position after the last element of the co...
std::string getString(std::size_t i) const
Method for retrieving a string value attribute.
A dataset is the unit of information manipulated by the data access module of TerraLib.
std::string getNumeric(std::size_t i) const
Method for retrieving a numeric attribute value.
std::unique_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
A class that models the description of a dataset.
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
bool moveNext()
It moves the internal pointer to the next item of the collection.
std::unique_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
bool moveFirst()
It moves the internal pointer to the first item in the collection.
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
double getDouble(std::size_t i) const
Method for retrieving a double attribute value.
std::vector< std::string > m_pnames
The name for each property.
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
std::size_t size() const
It returns the collection size, if it is known.
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.
boost::int64_t getInt64(std::size_t i) const
Method for retrieving a 64-bit integer attribute value (8 bytes long).
DataSetAdapter(DataSet *dataset, bool isOwner=false)
Constructor.
A class for representing binary data.
Definition: ByteArray.h:51
std::unique_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.