All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSet.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/DataSet.cpp
22 
23  \brief A dataset is the unit of information manipulated by the data access module of TerraLib.
24 */
25 
26 // TerraLib
27 #include "../../common/HexUtils.h"
28 #include "../../common/StringUtils.h"
29 #include "../../datatype/AbstractData.h"
30 #include "../../datatype/Array.h"
31 #include "../../datatype/ByteArray.h"
32 #include "../../datatype/DateTime.h"
33 #include "../../datatype/Property.h"
34 #include "../../datatype/SimpleData.h"
35 #include "../../raster/Raster.h"
36 #include "../utils/Utils.h"
37 #include "DataSet.h"
38 #include "DataSetType.h"
39 
40 // STL
41 #include <memory>
42 
43 // Boost
44 #include <boost/lexical_cast.hpp>
45 
46 char te::da::DataSet::getChar(const std::string& name) const
47 {
48  std::size_t i = GetPropertyPos(this, name);
49 
50  return getChar(i);
51 }
52 
53 unsigned char te::da::DataSet::getUChar(const std::string& name) const
54 {
55  std::size_t i = GetPropertyPos(this, name);
56 
57  return getUChar(i);
58 }
59 
60 boost::int16_t te::da::DataSet::getInt16(const std::string& name) const
61 {
62  std::size_t i = GetPropertyPos(this, name);
63 
64  return getInt16(i);
65 }
66 
67 boost::int32_t te::da::DataSet::getInt32(const std::string& name) const
68 {
69  std::size_t i = GetPropertyPos(this, name);
70 
71  return getInt32(i);
72 }
73 
74 boost::int64_t te::da::DataSet::getInt64(const std::string& name) const
75 {
76  std::size_t i = GetPropertyPos(this, name);
77 
78  return getInt64(i);
79 }
80 
81 bool te::da::DataSet::getBool(const std::string& name) const
82 {
83  std::size_t i = GetPropertyPos(this, name);
84 
85  return getBool(i);
86 }
87 
88 float te::da::DataSet::getFloat(const std::string& name) const
89 {
90  std::size_t i = GetPropertyPos(this, name);
91 
92  return getFloat(i);
93 }
94 
95 double te::da::DataSet::getDouble(const std::string& name) const
96 {
97  std::size_t i = GetPropertyPos(this, name);
98 
99  return getDouble(i);
100 }
101 
102 std::string te::da::DataSet::getNumeric(const std::string& name) const
103 {
104  std::size_t i = GetPropertyPos(this, name);
105 
106  return getNumeric(i);
107 }
108 
109 std::string te::da::DataSet::getString(const std::string& name) const
110 {
111  std::size_t i = GetPropertyPos(this, name);
112 
113  return getString(i);
114 }
115 
116 std::auto_ptr<te::dt::ByteArray> te::da::DataSet::getByteArray(const std::string& name) const
117 {
118  std::size_t i = GetPropertyPos(this, name);
119 
120  return getByteArray(i);
121 }
122 
123 std::auto_ptr<te::gm::Geometry> te::da::DataSet::getGeometry(const std::string& name) const
124 {
125  std::size_t i = GetPropertyPos(this, name);
126 
127  return getGeometry(i);
128 }
129 
130 std::auto_ptr<te::rst::Raster> te::da::DataSet::getRaster(const std::string& name) const
131 {
132  std::size_t i = GetPropertyPos(this, name);
133 
134  return getRaster(i);
135 }
136 
137 std::auto_ptr<te::dt::DateTime> te::da::DataSet::getDateTime(const std::string& name) const
138 {
139  std::size_t i = GetPropertyPos(this, name);
140 
141  return getDateTime(i);
142 }
143 
144 std::auto_ptr<te::dt::Array> te::da::DataSet::getArray(const std::string& name) const
145 {
146  std::size_t i = GetPropertyPos(this, name);
147 
148  return getArray(i);
149 }
150 
151 std::auto_ptr<te::dt::AbstractData> te::da::DataSet::getValue(std::size_t i) const
152 {
153  switch(getPropertyDataType(i))
154  {
155  case te::dt::CHAR_TYPE:
156  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Char(getChar(i)));
157 
158  case te::dt::UCHAR_TYPE:
159  return std::auto_ptr<te::dt::AbstractData>(new te::dt::UChar(getUChar(i)));
160 
161  case te::dt::INT16_TYPE:
162  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Int16(getInt16(i)));
163 
164  case te::dt::UINT16_TYPE:
165  return std::auto_ptr<te::dt::AbstractData>(new te::dt::UInt16(getInt16(i)));
166 
167  case te::dt::INT32_TYPE:
168  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Int32(getInt32(i)));
169 
170  case te::dt::UINT32_TYPE:
171  return std::auto_ptr<te::dt::AbstractData>(new te::dt::UInt32(getInt32(i)));
172 
173  case te::dt::INT64_TYPE:
174  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Int64(getInt64(i)));
175 
176  case te::dt::UINT64_TYPE:
177  return std::auto_ptr<te::dt::AbstractData>(new te::dt::UInt64(getInt64(i)));
178 
180  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Boolean(getBool(i)));
181 
182  case te::dt::FLOAT_TYPE:
183  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Float(getFloat(i)));
184 
185  case te::dt::DOUBLE_TYPE:
186  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Double(getDouble(i)));
187 
189  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Numeric(getNumeric(i)));
190 
191  case te::dt::STRING_TYPE:
192  return std::auto_ptr<te::dt::AbstractData>(new te::dt::String(getString(i)));
193 
195  return std::auto_ptr<te::dt::AbstractData>(getByteArray(i));
196 
198  return std::auto_ptr<te::dt::AbstractData>(getGeometry(i));
199 
201  return std::auto_ptr<te::dt::AbstractData>(getDateTime(i));
202 
203  case te::dt::RASTER_TYPE:
204  return std::auto_ptr<te::dt::AbstractData>(getRaster(i));
205 
206  default:
207  return std::auto_ptr<te::dt::AbstractData>(0);
208  }
209 }
210 
211 std::auto_ptr<te::dt::AbstractData> te::da::DataSet::getValue(const std::string& name) const
212 {
213  std::size_t i = GetPropertyPos(this, name);
214 
215  return getValue(i);
216 }
217 
218 std::string te::da::DataSet::getAsString(std::size_t i, int precision) const
219 {
220  std::string value;
221 
222  switch(getPropertyDataType(i))
223  {
224  case te::dt::CHAR_TYPE:
225  value = getChar(i);
226  break;
227 
228  case te::dt::UCHAR_TYPE:
229  value = getUChar(i);
230  break;
231 
232  case te::dt::INT16_TYPE:
233  value = boost::lexical_cast<std::string>(getInt16(i));
234  break;
235 
236  case te::dt::INT32_TYPE:
237  value = boost::lexical_cast<std::string>(getInt32(i));
238  break;
239 
240  case te::dt::INT64_TYPE:
241  value = boost::lexical_cast<std::string>(getInt64(i));
242  break;
243 
245  value = boost::lexical_cast<std::string>(getBool(i));
246  break;
247 
248  case te::dt::FLOAT_TYPE:
249  value = boost::lexical_cast<std::string>(getFloat(i));
250  break;
251 
252  case te::dt::DOUBLE_TYPE:
253  value = te::common::Convert2String(getDouble(i), precision);
254  break;
255 
257  value = getNumeric(i);
258  break;
259 
260  case te::dt::STRING_TYPE:
261  value = getString(i);
262  break;
263 
265  {
266  std::auto_ptr<te::dt::AbstractData> b(getByteArray(i));
267  value = b->toString();
268  }
269  break;
270 
272  {
273  std::auto_ptr<te::dt::AbstractData> g(getGeometry(i));
274  value = g->toString();
275  }
276  break;
277 
279  {
280  std::auto_ptr<te::dt::AbstractData> dTime(getDateTime(i));
281  value = dTime->toString();
282  }
283  break;
284 
285  case te::dt::ARRAY_TYPE:
286  {
287  std::auto_ptr<te::dt::Array> a(getArray(i));
288  value = a->toString();
289  }
290  break;
291 
292  case te::dt::RASTER_TYPE:
293  {
294  std::auto_ptr<te::dt::AbstractData> r(getRaster(i));
295  value = r->toString();
296  }
297  break;
298 
299  default:
300  break;
301  }
302 
303  return value;
304 }
305 
306 std::string te::da::DataSet::getAsString(const std::string& name, int precision) const
307 {
308  std::size_t i = GetPropertyPos(this, name);
309 
310  return getAsString(i, precision);
311 }
312 
313 bool te::da::DataSet::isNull(const std::string& name) const
314 {
315  std::size_t i = GetPropertyPos(this, name);
316 
317  return isNull(i);
318 }
319 
virtual std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const =0
Method for retrieving a date and time attribute value.
SimpleData< std::string, STRING_TYPE > String
Definition: SimpleData.h:229
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
SimpleData< unsigned char, UCHAR_TYPE > UChar
Definition: SimpleData.h:218
virtual char getChar(std::size_t i) const =0
Method for retrieving a signed character attribute value (1 byte long).
virtual bool getBool(std::size_t i) const =0
Method for retrieving a boolean attribute value.
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
double getDouble(const std::string &value, std::vector< std::string > &sVector)
Definition: Utils.cpp:179
SimpleData< boost::int64_t, INT64_TYPE > Int64
Definition: SimpleData.h:223
SimpleData< boost::int32_t, INT32_TYPE > Int32
Definition: SimpleData.h:221
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
Definition: Utils.cpp:500
virtual std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const =0
Method for retrieving a byte array.
virtual std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const =0
Method for retrieving a raster attribute value.
SimpleData< float, FLOAT_TYPE > Float
Definition: SimpleData.h:226
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
SimpleData< std::string, NUMERIC_TYPE > Numeric
Definition: SimpleData.h:228
virtual float getFloat(std::size_t i) const =0
Method for retrieving a float attribute value.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
SimpleData< boost::uint64_t, UINT64_TYPE > UInt64
Definition: SimpleData.h:224
virtual std::string getAsString(std::size_t i, int precision=0) const
Method for retrieving a data value as a string plain representation.
Definition: DataSet.cpp:218
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
SimpleData< bool, BOOLEAN_TYPE > Boolean
Definition: SimpleData.h:225
virtual std::auto_ptr< te::dt::Array > getArray(std::size_t i) const =0
Method for retrieving an array.
A class that models the description of a dataset.
SimpleData< double, DOUBLE_TYPE > Double
Definition: SimpleData.h:227
SimpleData< char, CHAR_TYPE > Char
Definition: SimpleData.h:217
SimpleData< boost::uint16_t, UINT16_TYPE > UInt16
Definition: SimpleData.h:220
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:51
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual unsigned char getUChar(std::size_t i) const =0
Method for retrieving an unsigned character attribute value (1 byte long).
SimpleData< boost::int16_t, INT16_TYPE > Int16
Definition: SimpleData.h:219
SimpleData< boost::uint32_t, UINT32_TYPE > UInt32
Definition: SimpleData.h:222
virtual std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
Definition: DataSet.cpp:151