All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSetItem.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/memory/DataSetItem.cpp
22 
23  \brief An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "../dataaccess/dataset/DataSetType.h"
29 #include "../dataaccess/utils/Utils.h"
30 #include "../datatype/AbstractData.h"
31 #include "../datatype/ByteArray.h"
32 #include "../datatype/DateTime.h"
33 #include "../datatype/Property.h"
34 #include "../datatype/SimpleData.h"
35 #include "../geometry/Geometry.h"
36 #include "../raster/Grid.h"
37 #include "../raster/RasterProperty.h"
38 #include "DataSet.h"
39 #include "DataSetItem.h"
40 #include "Exception.h"
41 #include "Raster.h"
42 
43 // STL
44 #include <cassert>
45 
47  : m_parent(parent)
48 {
49  if(parent == 0)
50  return;
51 
52  std::size_t nproperties = parent->getNumProperties();
53 
54  m_data.resize(nproperties, 0);
55 }
56 
57 te::mem::DataSetItem::DataSetItem(const std::size_t& nproperties)
58  : m_parent(0)
59 {
60  m_data.resize(nproperties, 0);
61 }
62 
64  : m_parent(rhs.m_parent)
65 {
66  m_data.reserve(rhs.getNumProperties());
67 
68  for(std::size_t i = 0; i < rhs.getNumProperties(); ++i)
69  {
70  if(rhs.isNull(i) == false)
71  m_data.push_back(rhs.getValue(i));
72  else
73  m_data.push_back(0);
74  }
75 }
76 
78 {
79 }
80 
82 {
83  assert(getNumProperties() == rhs.getNumProperties());
84 
85  if(this != &rhs)
86  {
87  m_parent = rhs.m_parent;
88  m_data = rhs.m_data;
89  }
90 
91  return *this;
92 }
93 
94 std::auto_ptr<te::mem::DataSetItem> te::mem::DataSetItem::clone() const
95 {
96  return std::auto_ptr<te::mem::DataSetItem>(new DataSetItem(*this));
97 }
98 
100 {
101  return const_cast<te::da::DataSet*>(m_parent);
102 }
103 
105 {
106  return m_parent->getNumProperties();
107 }
108 
110 {
111  return m_parent->getPropertyDataType(pos);
112 }
113 
114 std::string te::mem::DataSetItem::getPropertyName(std::size_t pos) const
115 {
116  return m_parent->getPropertyName(pos);
117 }
118 
119 char te::mem::DataSetItem::getChar(std::size_t i) const
120 {
121  return static_cast<const te::dt::Char*>(&m_data[i])->getValue();
122 }
123 
124 void te::mem::DataSetItem::setChar(std::size_t i, char value)
125 {
126  m_data.replace(i, new te::dt::Char(value));
127 }
128 
129 void te::mem::DataSetItem::setChar(const std::string& name, char value)
130 {
131  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
132  setChar(pos, value);
133 }
134 
135 unsigned char te::mem::DataSetItem::getUChar(std::size_t i) const
136 {
137  return static_cast<const te::dt::UChar*>(&m_data[i])->getValue();
138 }
139 
140 void te::mem::DataSetItem::setUChar(std::size_t i, unsigned char value)
141 {
142  m_data.replace(i, new te::dt::UChar(value));
143 }
144 
145 void te::mem::DataSetItem::setUChar(const std::string& name, unsigned char value)
146 {
147  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
148  setUChar(pos, value);
149 }
150 
151 boost::int16_t te::mem::DataSetItem::getInt16(std::size_t i) const
152 {
153  return static_cast<const te::dt::Int16*>(&m_data[i])->getValue();
154 }
155 
156 void te::mem::DataSetItem::setInt16(std::size_t i, boost::int16_t value)
157 {
158  m_data.replace(i, new te::dt::Int16(value));
159 }
160 
161 void te::mem::DataSetItem::setInt16(const std::string& name, boost::int16_t value)
162 {
163  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
164  setInt16(pos, value);
165 }
166 
167 boost::int32_t te::mem::DataSetItem::getInt32(std::size_t i) const
168 {
169  return static_cast<const te::dt::Int32*>(&m_data[i])->getValue();
170 }
171 
172 void te::mem::DataSetItem::setInt32(std::size_t i, boost::int32_t value)
173 {
174  m_data.replace(i, new te::dt::Int32(value));
175 }
176 
177 void te::mem::DataSetItem::setInt32(const std::string& name, boost::int32_t value)
178 {
179  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
180  setInt32(pos, value);
181 }
182 
183 boost::int64_t te::mem::DataSetItem::getInt64(std::size_t i) const
184 {
185  return static_cast<const te::dt::Int64*>(&m_data[i])->getValue();
186 }
187 
188 void te::mem::DataSetItem::setInt64(std::size_t i, boost::int64_t value)
189 {
190  m_data.replace(i, new te::dt::Int64(value));
191 }
192 
193 void te::mem::DataSetItem::setInt64(const std::string& name, boost::int64_t value)
194 {
195  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
196  setInt64(pos, value);
197 }
198 
199 bool te::mem::DataSetItem::getBool(std::size_t i) const
200 {
201  return static_cast<const te::dt::Boolean*>(&m_data[i])->getValue();
202 }
203 
204 void te::mem::DataSetItem::setBool(std::size_t i, bool value)
205 {
206  m_data.replace(i, new te::dt::Boolean(value));
207 }
208 
209 void te::mem::DataSetItem::setBool(const std::string& name, bool value)
210 {
211  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
212  setBool(pos, value);
213 }
214 
215 float te::mem::DataSetItem::getFloat(std::size_t i) const
216 {
217  return static_cast<const te::dt::Float*>(&m_data[i])->getValue();
218 }
219 
220 void te::mem::DataSetItem::setFloat(std::size_t i, float value)
221 {
222  m_data.replace(i, new te::dt::Float(value));
223 }
224 
225 void te::mem::DataSetItem::setFloat(const std::string& name, float value)
226 {
227  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
228  setFloat(pos, value);
229 }
230 
231 double te::mem::DataSetItem::getDouble(std::size_t i) const
232 {
233  return static_cast<const te::dt::Double*>(&m_data[i])->getValue();
234 }
235 
236 void te::mem::DataSetItem::setDouble(std::size_t i, double value)
237 {
238  m_data.replace(i, new te::dt::Double(value));
239 }
240 
241 void te::mem::DataSetItem::setDouble(const std::string& name, double value)
242 {
243  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
244  setDouble(pos, value);
245 }
246 
247 std::string te::mem::DataSetItem::getNumeric(std::size_t i) const
248 {
249  return static_cast<const te::dt::Numeric*>(&m_data[i])->getValue();
250 }
251 
252 void te::mem::DataSetItem::setNumeric(std::size_t i, const std::string& value)
253 {
254  m_data.replace(i, new te::dt::Numeric(value));
255 }
256 
257 void te::mem::DataSetItem::setNumeric(const std::string& name, const std::string& value)
258 {
259  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
260  setNumeric(pos, value);
261 }
262 
263 std::string te::mem::DataSetItem::getString(std::size_t i) const
264 {
265  return static_cast<const te::dt::String*>(&m_data[i])->getValue();
266 }
267 
268 void te::mem::DataSetItem::setString(std::size_t i, const std::string& value)
269 {
270  m_data.replace(i, new te::dt::String(value));
271 }
272 
273 void te::mem::DataSetItem::setString(const std::string& name, const std::string& value)
274 {
275  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
276  setString(pos, value);
277 }
278 
279 std::auto_ptr<te::dt::ByteArray> te::mem::DataSetItem::getByteArray(std::size_t i) const
280 {
281  te::dt::ByteArray* b = new te::dt::ByteArray(*static_cast<const te::dt::ByteArray*>(&m_data[i]));
282  return std::auto_ptr<te::dt::ByteArray>(b);
283 }
284 
286 {
287  m_data.replace(i, value);
288 }
289 
290 void te::mem::DataSetItem::setByteArray(const std::string& name, te::dt::ByteArray* value)
291 {
292  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
293  setByteArray(pos, value);
294 }
295 
296 std::auto_ptr<te::gm::Geometry> te::mem::DataSetItem::getGeometry(std::size_t i) const
297 {
298  return std::auto_ptr<te::gm::Geometry>(static_cast<te::gm::Geometry*>(m_data[i].clone()));
299 }
300 
302 {
303  m_data.replace(i, value);
304 }
305 
306 void te::mem::DataSetItem::setGeometry(const std::string& name, te::gm::Geometry* value)
307 {
308  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
309  setGeometry(pos, value);
310 }
311 
312 std::auto_ptr<te::rst::Raster> te::mem::DataSetItem::getRaster(std::size_t i) const
313 {
314  return std::auto_ptr<te::rst::Raster>(static_cast<te::rst::Raster*>(m_data[i].clone()));
315 }
316 
318 {
319  m_data.replace(i, value);
320 }
321 
322 void te::mem::DataSetItem::setRaster(const std::string& name, te::rst::Raster* value)
323 {
324  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
325  setRaster(pos, value);
326 }
327 
328 std::auto_ptr<te::dt::DateTime> te::mem::DataSetItem::getDateTime(std::size_t i) const
329 {
330  return std::auto_ptr<te::dt::DateTime>(static_cast<te::dt::DateTime*>(m_data[i].clone()));
331 }
332 
334 {
335  m_data.replace(i, value);
336 }
337 
338 void te::mem::DataSetItem::setDateTime(const std::string& name, te::dt::DateTime* value)
339 {
340  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
341  setDateTime(pos, value);
342 }
343 
344 std::auto_ptr<te::dt::AbstractData> te::mem::DataSetItem::getValue(std::size_t i) const
345 {
346  switch(getPropertyDataType(i))
347  {
348  case te::dt::CHAR_TYPE:
349  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Char(getChar(i)));
350 
351  case te::dt::UCHAR_TYPE:
352  return std::auto_ptr<te::dt::AbstractData>(new te::dt::UChar(getUChar(i)));
353 
354  case te::dt::INT16_TYPE:
355  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Int16(getInt16(i)));
356 
357  case te::dt::UINT16_TYPE:
358  return std::auto_ptr<te::dt::AbstractData>(new te::dt::UInt16(getInt16(i)));
359 
360  case te::dt::INT32_TYPE:
361  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Int32(getInt32(i)));
362 
363  case te::dt::UINT32_TYPE:
364  return std::auto_ptr<te::dt::AbstractData>(new te::dt::UInt32(getInt32(i)));
365 
366  case te::dt::INT64_TYPE:
367  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Int64(getInt64(i)));
368 
369  case te::dt::UINT64_TYPE:
370  return std::auto_ptr<te::dt::AbstractData>(new te::dt::UInt64(getInt64(i)));
371 
373  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Boolean(getBool(i)));
374 
375  case te::dt::FLOAT_TYPE:
376  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Float(getFloat(i)));
377 
378  case te::dt::DOUBLE_TYPE:
379  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Double(getDouble(i)));
380 
382  return std::auto_ptr<te::dt::AbstractData>(new te::dt::Numeric(getNumeric(i)));
383 
384  case te::dt::STRING_TYPE:
385  return std::auto_ptr<te::dt::AbstractData>(new te::dt::String(getString(i)));
386 
388  return std::auto_ptr<te::dt::AbstractData>(getByteArray(i).release());
389 
391  return std::auto_ptr<te::dt::AbstractData>(getGeometry(i).release());
392 
394  return std::auto_ptr<te::dt::AbstractData>(getDateTime(i).release());
395 
396  case te::dt::RASTER_TYPE:
397  return std::auto_ptr<te::dt::AbstractData>(getRaster(i).release());
398 
399  default:
400  return std::auto_ptr<te::dt::AbstractData>(0);
401  }
402 }
403 
405 {
406  m_data.replace(i, value);
407 }
408 
409 void te::mem::DataSetItem::setValue(const std::string& name, te::dt::AbstractData* value)
410 {
411  std::size_t pos = te::da::GetPropertyPos(m_parent, name);
412  setValue(pos, value);
413 }
414 
415 bool te::mem::DataSetItem::isNull(std::size_t i) const
416 {
417  return boost::is_null(m_data.begin() + i);
418 }
void setFloat(std::size_t i, float value)
It sets the value of the i-th property.
std::string getNumeric(std::size_t i) const
It returns the value of the i-th property.
std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
It returns the value of the i-th property.
SimpleData< std::string, STRING_TYPE > String
Definition: SimpleData.h:229
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
void setUChar(std::size_t i, unsigned char value)
It sets the value of the i-th property.
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
std::string getPropertyName(std::size_t pos) const
It returns the name of the pos-th property.
DataSetItem & operator=(const DataSetItem &rhs)
Assignment operator.
Definition: DataSetItem.cpp:81
SimpleData< unsigned char, UCHAR_TYPE > UChar
Definition: SimpleData.h:218
const te::da::DataSet * m_parent
The parent dataset, if the item is associated to one.
Definition: DataSetItem.h:373
int getPropertyDataType(std::size_t pos) const
It returns the type of the pos-th property.
float getFloat(std::size_t i) const
It returns the value of the i-th property.
bool isNull(std::size_t i) const
double getDouble(const std::string &value, std::vector< std::string > &sVector)
Definition: Utils.cpp:179
std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
It returns the value of the i-th property.
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
char getChar(std::size_t i) const
It returns the value of the i-th property.
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
bool getBool(std::size_t i) const
It returns the value of the i-th property.
boost::int64_t getInt64(std::size_t i) const
It returns the value of the i-th property.
SimpleData< float, FLOAT_TYPE > Float
Definition: SimpleData.h:226
void setByteArray(const std::string &name, te::dt::ByteArray *value)
It sets the value of the property, indicating its name.
boost::int16_t getInt16(std::size_t i) const
It returns the value of the i-th property.
void setInt16(std::size_t i, boost::int16_t value)
It sets the value of the i-th property.
void setChar(std::size_t i, char value)
It sets the value of the i-th property.
An exception class for the TerraLib In-Memory Data Access driver.
std::size_t getNumProperties() const
It returns the number of properties.
void setNumeric(std::size_t i, const std::string &value)
It sets the value of the i-th property.
std::auto_ptr< DataSetItem > clone() const
It returns a clone of the DataSetItem.
Definition: DataSetItem.cpp:94
SimpleData< std::string, NUMERIC_TYPE > Numeric
Definition: SimpleData.h:228
boost::int32_t getInt32(std::size_t i) const
It returns the value of the i-th property.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
std::string getString(std::size_t i) const
It returns the value of the i-th property.
std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
It returns the value of the i-th property.
void setRaster(std::size_t i, te::rst::Raster *value)
It sets the value of the i-th property.
void setDateTime(std::size_t i, te::dt::DateTime *value)
It sets the value of the i-th property.
An abstract class for raster data strucutures.
Definition: Raster.h:71
boost::ptr_vector< boost::nullable< te::dt::AbstractData > > m_data
The data values of the dataset item.
Definition: DataSetItem.h:374
void setDouble(const std::string &name, double value)
It sets the value of the property, indicating its name.
A raster class for memory.
double getDouble(std::size_t i) const
It returns the value of the i-th property.
SimpleData< boost::uint64_t, UINT64_TYPE > UInt64
Definition: SimpleData.h:224
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
unsigned char getUChar(std::size_t i) const
It returns the value of the i-th property.
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
te::da::DataSet * getParent() const
It returns its parent.
Definition: DataSetItem.cpp:99
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
Definition: DataSetItem.h:56
void setByteArray(std::size_t i, te::dt::ByteArray *value)
It sets the value of the i-th property.
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
SimpleData< bool, BOOLEAN_TYPE > Boolean
Definition: SimpleData.h:225
DataSetItem(const te::da::DataSet *parent)
It creates a new item having the same schema as the parent dataset.
Definition: DataSetItem.cpp:46
SimpleData< double, DOUBLE_TYPE > Double
Definition: SimpleData.h:227
SimpleData< char, CHAR_TYPE > Char
Definition: SimpleData.h:217
void setBool(std::size_t i, bool value)
It sets the value of the i-th property.
virtual ~DataSetItem()
Destructor.
Definition: DataSetItem.cpp:77
SimpleData< boost::uint16_t, UINT16_TYPE > UInt16
Definition: SimpleData.h:220
std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
It returns the value of the i-th property.
A template for atomic data types (integers, floats, strings and others).
Definition: SimpleData.h:59
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
void setInt64(std::size_t i, boost::int64_t value)
It sets the value of the i-th property.
SimpleData< boost::int16_t, INT16_TYPE > Int16
Definition: SimpleData.h:219
std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const
It returns the value of the i-th property.
SimpleData< boost::uint32_t, UINT32_TYPE > UInt32
Definition: SimpleData.h:222
A class for representing binary data.
Definition: ByteArray.h:51