All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../../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 
91 {
92  return te::common::UNKNOWN_CHAR_ENCODING; // TODO!
93 }
94 
95 std::string te::da::DataSetAdapter::getDatasetNameOfProperty(std::size_t pos) const
96 {
97  return "";
98 }
99 
101 {
102  return m_ds->isEmpty();
103 }
104 
106 {
107  return m_ds->isConnected();
108 }
109 
110 std::size_t te::da::DataSetAdapter::size() const
111 {
112  return m_ds->size();
113 }
114 
116 {
117  return m_ds->moveNext();
118 }
119 
121 {
122  return m_ds->movePrevious();
123 }
124 
126 {
127  return m_ds->moveBeforeFirst();
128 }
129 
131 {
132  return m_ds->moveFirst();
133 }
134 
136 {
137  return m_ds->moveLast();
138 }
139 
140 bool te::da::DataSetAdapter::move(std::size_t i)
141 {
142  return m_ds->move(i);
143 }
144 
146 {
147  return m_ds->isAtBegin();
148 }
149 
151 {
152  return m_ds->isBeforeBegin();
153 }
154 
156 {
157  return m_ds->isAtEnd();
158 }
159 
161 {
162  return m_ds->isAfterEnd();
163 }
164 
165 char te::da::DataSetAdapter::getChar(std::size_t i) const
166 {
167  std::auto_ptr<te::dt::Char> data(static_cast<te::dt::Char*>(getAdaptedValue(i)));
168 
169  return data->getValue();
170 }
171 
172 unsigned char te::da::DataSetAdapter::getUChar(std::size_t i) const
173 {
174  std::auto_ptr<te::dt::UChar> data(static_cast<te::dt::UChar*>(getAdaptedValue(i)));
175 
176  return data->getValue();
177 }
178 
179 boost::int16_t te::da::DataSetAdapter::getInt16(std::size_t i) const
180 {
181  std::auto_ptr<te::dt::Int16> data(static_cast<te::dt::Int16*>(getAdaptedValue(i)));
182 
183  return data->getValue();
184 }
185 
186 boost::int32_t te::da::DataSetAdapter::getInt32(std::size_t i) const
187 {
188  std::auto_ptr<te::dt::Int32> data(static_cast<te::dt::Int32*>(getAdaptedValue(i)));
189 
190  return data->getValue();
191 }
192 
193 boost::int64_t te::da::DataSetAdapter::getInt64(std::size_t i) const
194 {
195  std::auto_ptr<te::dt::Int64> data(static_cast<te::dt::Int64*>(getAdaptedValue(i)));
196 
197  return data->getValue();
198 }
199 
200 bool te::da::DataSetAdapter::getBool(std::size_t i) const
201 {
202  std::auto_ptr<te::dt::Boolean> data(static_cast<te::dt::Boolean*>(getAdaptedValue(i)));
203 
204  return data->getValue();
205 }
206 
207 float te::da::DataSetAdapter::getFloat(std::size_t i) const
208 {
209  std::auto_ptr<te::dt::Float> data(static_cast<te::dt::Float*>(getAdaptedValue(i)));
210 
211  return data->getValue();
212 }
213 
214 double te::da::DataSetAdapter::getDouble(std::size_t i) const
215 {
216  std::auto_ptr<te::dt::Double> data(static_cast<te::dt::Double*>(getAdaptedValue(i)));
217 
218  return data->getValue();
219 }
220 
221 std::string te::da::DataSetAdapter::getNumeric(std::size_t i) const
222 {
223  std::auto_ptr<te::dt::Numeric> data(static_cast<te::dt::Numeric*>(getAdaptedValue(i)));
224 
225  return data->getValue();
226 }
227 
228 std::string te::da::DataSetAdapter::getString(std::size_t i) const
229 {
230  std::auto_ptr<te::dt::String> data(static_cast<te::dt::String*>(getAdaptedValue(i)));
231  return data->getValue();
232 }
233 
234 std::auto_ptr<te::dt::ByteArray> te::da::DataSetAdapter::getByteArray(std::size_t i) const
235 {
236  return std::auto_ptr<te::dt::ByteArray>(static_cast<te::dt::ByteArray*>(getAdaptedValue(i)));
237 }
238 
239 std::auto_ptr<te::gm::Geometry> te::da::DataSetAdapter::getGeometry(std::size_t i) const
240 {
241  return std::auto_ptr<te::gm::Geometry>(static_cast<te::gm::Geometry*>(getAdaptedValue(i)));
242 }
243 
244 std::auto_ptr<te::rst::Raster> te::da::DataSetAdapter::getRaster(std::size_t i) const
245 {
246  return std::auto_ptr<te::rst::Raster>(static_cast<te::rst::Raster*>(getAdaptedValue(i)));
247 }
248 
249 std::auto_ptr<te::dt::DateTime> te::da::DataSetAdapter::getDateTime(std::size_t i) const
250 {
251  return std::auto_ptr<te::dt::DateTime>(static_cast<te::dt::DateTime*>(getAdaptedValue(i)));
252 }
253 
254 std::auto_ptr<te::dt::Array> te::da::DataSetAdapter::getArray(std::size_t i) const
255 {
256  return std::auto_ptr<te::dt::Array>(static_cast<te::dt::Array*>(getAdaptedValue(i)));
257 }
258 
259 bool te::da::DataSetAdapter::isNull(std::size_t i) const
260 {
261  std::auto_ptr<te::dt::AbstractData> data(getAdaptedValue(i));
262 
263  return data.get() == 0;
264 }
265 
267 {
268  m_srid = srid;
269 }
270 
272 {
273  return m_ds.get();
274 }
275 
276 void te::da::DataSetAdapter::add(const std::string& newPropertyName,
277  int newPropertyType,
278  const std::vector<std::size_t>& adaptedPropertyPos,
279  AttributeConverter conv)
280 {
281  m_datatypes.push_back(newPropertyType);
282  m_pnames.push_back(newPropertyName);
283  m_propertyIndexes.push_back(adaptedPropertyPos);
284  m_converters.push_back(conv);
285 }
286 
288 {
289  te::dt::AbstractData* data = m_converters[i](m_ds.get(), m_propertyIndexes[i], m_datatypes[i]);
290 
291  if(data && data->getTypeCode() == te::dt::GEOMETRY_TYPE)
292  {
293  te::gm::Geometry* geom = dynamic_cast<te::gm::Geometry*>(data);
294 
295  if(geom)
296  geom->setSRID(m_srid);
297  }
298 
299  return data;
300 }
std::auto_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
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...
void setSRID(int srid)
It sets the Spatial Reference System ID associated to the DataSet.
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
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
CharEncoding
Supported charsets (character encoding).
te::common::TraverseType getTraverseType() const
It returns the traverse type associated to the dataset.
std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
virtual int getTypeCode() const =0
It returns the data type code associated to the data value.
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
~DataSetAdapter()
Destructor.
std::auto_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
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).
Definition: Enums.h:40
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
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.
Definition: Raster.h:71
An adapter for DataSet.
std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
unsigned char getUChar(std::size_t i) const
Method for retrieving an unsigned character attribute value (1 byte long).
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.
Definition: Geometry.h:73
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.
Definition: DataSet.h:112
std::string getNumeric(std::size_t i) const
Method for retrieving a numeric attribute value.
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.
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.
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
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).
int m_srid
The identifier of the layer spatial reference system.
te::common::CharEncoding getPropertyCharEncoding(std::size_t i) const
It returns the property character encoding at position pos.
DataSetAdapter(DataSet *dataset, bool isOwner=false)
Constructor.
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...
A class for representing binary data.
Definition: ByteArray.h:51