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