DataSet.h
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/DataSet.h
22 
23  \brief Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver.
24 */
25 
26 #ifndef __TERRALIB_MEMORY_INTERNAL_DATASET_H
27 #define __TERRALIB_MEMORY_INTERNAL_DATASET_H
28 
29 // TerraLib
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "Config.h"
32 
33 // STL
34 #include <map>
35 #include <memory>
36 
37 // Boost
38 #include <boost/ptr_container/ptr_vector.hpp>
39 #include <boost/shared_ptr.hpp>
40 
41 namespace te
42 {
43  namespace da
44  {
45  class DataSetType;
46  }
47 
48  namespace dt
49  {
50  class Property;
51  }
52 
53  namespace mem
54  {
55 // Forward declarations
56  class DataSetItem;
57 
58  /*!
59  \class DataSet
60 
61  \brief Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver.
62 
63  \sa te::da::DataSet
64  */
66  {
67  public:
68 
69  /*!
70  \brief It constructs an empty dataset having the schema dt.
71 
72  \param dt The DataSetType associated to the dataset.
73 
74  \note The dataset will NOT take the ownership of the given DataSetType.
75  */
76  explicit DataSet(const te::da::DataSetType* const dt);
77 
78  /*!
79  \brief Regular copy constructor.
80 
81  It creates a new In-Memory dataset with the items from the rhs dataset.
82 
83  \param rhs The dataset which will provide the items.
84 
85  \pre You must assure that rhs is in a valid item to be read.
86 
87  \note This constructor will use the method "moveNext()" of the source dataset (rhs)
88  in order to read its dataset items. It will start reading the given
89  dataset in the current position. So, the caller is responsible for
90  informing the dataset in the right position to start processing it.
91 
92  \note The new dataset will not have a transactor associated to it.
93  */
94  explicit DataSet(te::da::DataSet& rhs);
95 
96  /*!
97  \brief It creates a new In-Memory dataset with the items from the rhs dataset.
98 
99  \param rhs The dataset which will provide the items to copy from.
100  \param deepCopy If true the new dataset instance will clone all dataset items from the source dataset (rhs), otherwise it will share all items.
101 
102  \note The new dataset will not have a transactor associated to it.
103  */
104  explicit DataSet(const DataSet& rhs, const bool deepCopy );
105 
106  /*!
107  \brief Copy constructor with property restriction.
108 
109  It creates a new memory data set with items from a source dataset (rhs)
110  considering just some properties.
111 
112  \param rhs The data set whose data set items will be copied.
113  \param properties The list of properties which will be considered in the copy.
114  \param limit The number of items to be copied. Use 0 to copy all items.
115 
116  \pre The properties in the property vector must come from the source dataset (rhs) schema. In other
117  words, they must be valid pointers in the rhs dataset type.
118 
119  \note This constructor will use the method "moveNext()" of the given data set
120  in order to read its dataset items. It will start reading the given
121  dataset in the current position. So, the caller is responsible for
122  informing the dataset in the right position to start processing it.
123 
124  \note The dataset will NOT take the ownership of the given properties, internally it will clone them.
125  */
126  explicit DataSet(te::da::DataSet& rhs, const std::vector<std::size_t>& properties, std::size_t limit );
127 
128  /*! \brief Destructor. */
130 
131  /*! \brief It clears all the dataset items. */
132  void clear();
133 
134  /*!
135  \brief It copies up to limit items from the source dataset.
136 
137  \param src The source dataset with the items that will be copied.
138  \param limit The number of items to be copied. Use 0 to copy all items.
139 
140  \note This method will call moveNext() for the source dataset
141  in order to read its items. It will start reading the given
142  dataset in the current position. So, the caller is responsible for
143  informing the dataset in the right position to start processing it.
144 
145  \note In-Memory driver extended method.
146  */
147  void copy(te::da::DataSet& src, std::size_t limit = 0);
148 
149  /*!
150  \brief It copies up to limit items from the source dataset (src).
151 
152  \param src The source dataset with the items that will be copied.
153  \param properties The list of properties which will be considered in the copy.
154  \param limit The number of items to be copied. Use 0 to copy all items.
155 
156  \pre The properties in the property vector must come from the source dataset (rhs) schema. In other
157  words, they must be valid pointers in the rhs dataset type.
158 
159  \note This method will call moveNext() for the source dataset
160  in order to read its items. It will start reading the given
161  dataset in the current position. So, the caller is responsible for
162  informing the dataset in the right position to start processing it.
163 
164  \note In-Memory driver extended method.
165  */
166  void copy(te::da::DataSet& src, const std::vector<std::size_t>& properties, std::size_t limit = 0);
167 
168  /*!
169  \brief It adds a new item to the dataset and takes its ownership.
170 
171  \param item The item to be added to the dataset.
172 
173  \pre The item schema must be compatible with the dataset items.
174 
175  \note In-Memory driver extended method.
176  */
178 
179  /*!
180  \brief It removes the current dataset item.
181 
182  \note In-Memory driver extended method.
183  */
184  void remove();
185 
186  /*!
187  \brief It removes a specific dataset item.
188 
189  \note In-Memory driver extended method.
190  */
192 
193  /*!
194  \brief It adds a new property to the dataset schema and fills this new property with a default value.
195 
196  \param prop The new property that will be created. The dataset will take its ownership.
197  \param defaultValue The default value that will be used to fill the new property values. May be a NULL value.
198 
199  \note The DataSet will NOT take the ownership of the informed default value.
200 
201  \note In-Memory driver extended method.
202  */
203  void add(const std::string& propertyName, std::size_t propertyType, const te::dt::AbstractData* defaultValue = 0);
204 
205  /*!
206  \brief It drops a property from the dataset.
207 
208  \param prop The property that will be dropped.
209 
210  \note The Property will be destroyed.
211 
212  \note In-Memory driver extended method.
213  */
214  void drop(std::size_t pos);
215 
216  /*!
217  \brief It update a property from the dataset.
218 
219  \param prop The property that will be updated.
220 
221  \note For now, for all items, the value will be changed to 0.
222 
223  \todo Update the method to perform the necessary conversions
224  when the type change
225 
226  \note In-Memory driver extended method.
227  */
229 
230  /*! \name DataSet inherited methods */
231  //@{
233 
235 
236  std::size_t getNumProperties() const;
237 
238  int getPropertyDataType(std::size_t pos) const;
239 
240  void setPropertyDataType(int dt, std::size_t pos);
241 
242  std::string getPropertyName(std::size_t pos) const;
243 
244  void setPropertyName(const std::string& name, std::size_t pos);
245 
246  std::string getDatasetNameOfProperty(std::size_t pos) const;
247 
248  bool isEmpty() const;
249 
250  bool isConnected() const;
251 
252  std::size_t size() const;
253 
254  std::unique_ptr<te::gm::Envelope> getExtent(std::size_t i);
255 
256  bool moveNext();
257 
258  bool movePrevious();
259 
261 
262  bool moveFirst();
263 
264  bool moveLast();
265 
266  bool move(std::size_t i);
267 
268  bool isAtBegin() const;
269 
270  bool isBeforeBegin() const;
271 
272  bool isAtEnd() const;
273 
274  bool isAfterEnd() const;
275 
276  bool isPositionValid() const;
277 
278  char getChar(std::size_t i) const;
279 
280  unsigned char getUChar(std::size_t i) const;
281 
282  boost::int16_t getInt16(std::size_t i) const;
283 
284  boost::int32_t getInt32(std::size_t i) const;
285 
286  boost::int64_t getInt64(std::size_t i) const;
287 
288  bool getBool(std::size_t i) const;
289 
290  float getFloat(std::size_t i) const;
291 
292  double getDouble(std::size_t i) const;
293 
294  std::string getNumeric(std::size_t i) const;
295 
296  std::string getString(std::size_t i) const;
297 
298  std::unique_ptr<te::dt::ByteArray> getByteArray(std::size_t i) const;
299 
300  std::unique_ptr<te::gm::Geometry> getGeometry(std::size_t i) const;
301 
302  std::unique_ptr<te::rst::Raster> getRaster(std::size_t i) const;
303 
304  std::unique_ptr<te::dt::DateTime> getDateTime(std::size_t i) const;
305 
306  std::unique_ptr<te::dt::Array> getArray(std::size_t i) const;
307 
308  std::unique_ptr<te::dt::AbstractData> getValue(std::size_t i) const;
309 
310  bool isNull(std::size_t i) const;
311  //@}
312 
313  /*! \name Methods to set values to the DataSet
314 
315  \Note These methods will take the ownership of the given pointers.
316  */
317  //@{
318  void setChar(std::size_t i, char value);
319 
320  void setChar(const std::string& name, char value);
321 
322  void setUChar(std::size_t i, unsigned char value);
323 
324  void setUChar(const std::string& name, unsigned char value);
325 
326  void setInt16(std::size_t i, boost::int16_t value);
327 
328  void setInt16(const std::string& name, boost::int16_t value);
329 
330  void setInt32(std::size_t i, boost::int32_t value);
331 
332  void setInt32(const std::string& name, boost::int32_t value);
333 
334  void setInt64(std::size_t i, boost::int64_t value);
335 
336  void setInt64(const std::string& name, boost::int64_t value);
337 
338  void setBool(std::size_t i, bool value);
339 
340  void setBool(const std::string& name, bool value);
341 
342  void setFloat(std::size_t i, float value);
343 
344  void setFloat(const std::string& name, float value);
345 
346  void setDouble(std::size_t i, double value);
347 
348  void setDouble(const std::string& name, double value);
349 
350  void setNumeric(std::size_t i, const std::string& value);
351 
352  void setNumeric(const std::string& name, const std::string& value);
353 
354  void setString(std::size_t i, const std::string& value);
355 
356  void setString(const std::string& name, const std::string& value);
357 
358  void setByteArray(std::size_t i, te::dt::ByteArray* value);
359 
360  void setByteArray(const std::string& name, te::dt::ByteArray* value);
361 
362  void setGeometry(std::size_t i, te::gm::Geometry* value);
363 
364  void setGeometry(const std::string& name, te::gm::Geometry* value);
365 
366  void setRaster(std::size_t i, te::rst::Raster* value);
367 
368  void setRaster(const std::string& name, te::rst::Raster* value);
369 
370  void setDateTime(std::size_t i, te::dt::DateTime* value);
371 
372  void setDateTime(const std::string& name, te::dt::DateTime* value);
373 
374  void setValue(std::size_t i, te::dt::AbstractData* value);
375 
376  void setValue(const std::string& name, te::dt::AbstractData* ad);
377 
378  //@}
379 
380  protected:
381 
382  boost::shared_ptr<boost::ptr_vector<te::mem::DataSetItem> > m_items; //!< The list of dataset items.
383  std::vector<std::string> m_pnames; //!< The list of property names.
384  std::vector<int> m_ptypes; //!< The list of property types.
385  int m_i; //!< The index of the current item.
386  };
387 
388  typedef boost::shared_ptr<DataSet> DataSetPtr;
389 
390  } // end namespace mem
391 } // end namespace te
392 
393 #endif // __TERRALIB_MEMORY_INTERNAL_DATASET_H
te::mem::DataSet::getTraverseType
te::common::TraverseType getTraverseType() const
It returns the traverse type associated to the dataset.
te::mem::DataSet::moveNext
bool moveNext()
It moves the internal pointer to the next item of the collection.
te::mem::DataSet::getNumProperties
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
te::dt::ByteArray
A class for representing binary data.
Definition: ByteArray.h:52
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::mem::DataSet::setString
void setString(const std::string &name, const std::string &value)
te::mem::DataSet::setDouble
void setDouble(const std::string &name, double value)
te::mem::DataSet::setInt32
void setInt32(std::size_t i, boost::int32_t value)
te::mem::DataSet::getInt16
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
te::mem::DataSet::setInt16
void setInt16(const std::string &name, boost::int16_t value)
te::mem::DataSet::setValue
void setValue(std::size_t i, te::dt::AbstractData *value)
te::mem::DataSet::getInt64
boost::int64_t getInt64(std::size_t i) const
Method for retrieving a 64-bit integer attribute value (8 bytes long).
te::mem::DataSet::getAccessPolicy
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
te::mem::DataSet::size
std::size_t size() const
It returns the collection size, if it is known.
te::rst::Raster
An abstract class for raster data strucutures.
Definition: Raster.h:72
te::mem::DataSet::getDateTime
std::unique_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
te::dt::DateTime
Definition: DateTime.h:56
te::mem::DataSet::getString
std::string getString(std::size_t i) const
Method for retrieving a string value attribute.
te::mem::DataSet::remove
void remove(te::mem::DataSetItem *item)
It removes a specific dataset item.
te::mem::DataSet::m_i
int m_i
The index of the current item.
Definition: DataSet.h:385
te::mem::DataSet::setDateTime
void setDateTime(const std::string &name, te::dt::DateTime *value)
te::mem::DataSet::clear
void clear()
It clears all the dataset items.
te::mem::DataSet::moveLast
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.
te::mem::DataSet::add
void add(te::mem::DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
te::common::TraverseType
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:54
te::mem::DataSet::setFloat
void setFloat(std::size_t i, float value)
te::mem::DataSet::setNumeric
void setNumeric(std::size_t i, const std::string &value)
te::mem::DataSet::isConnected
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
te::mem::DataSet::getChar
char getChar(std::size_t i) const
Method for retrieving a signed character attribute value (1 byte long).
te::mem::DataSet::movePrevious
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
te::mem::DataSet::setFloat
void setFloat(const std::string &name, float value)
te::mem::DataSet::m_items
boost::shared_ptr< boost::ptr_vector< te::mem::DataSetItem > > m_items
The list of dataset items.
Definition: DataSet.h:382
te::mem::DataSet::setDouble
void setDouble(std::size_t i, double value)
te::mem::DataSet::move
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
te::mem::DataSet::setPropertyName
void setPropertyName(const std::string &name, std::size_t pos)
te::mem::DataSet::getArray
std::unique_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
te::mem::DataSet::getNumeric
std::string getNumeric(std::size_t i) const
Method for retrieving a numeric attribute value.
te::mem::DataSet::isPositionValid
bool isPositionValid() const
It tells if the dataset internal pointer is on a valid position.
te::mem::DataSet::setGeometry
void setGeometry(const std::string &name, te::gm::Geometry *value)
te::mem::DataSet::m_pnames
std::vector< std::string > m_pnames
The list of property names.
Definition: DataSet.h:383
te::mem::DataSet::setChar
void setChar(std::size_t i, char value)
te::mem::DataSet::setInt16
void setInt16(std::size_t i, boost::int16_t value)
te::mem::DataSet::getUChar
unsigned char getUChar(std::size_t i) const
Method for retrieving an unsigned character attribute value (1 byte long).
te::mem::DataSet::getDouble
double getDouble(std::size_t i) const
Method for retrieving a double attribute value.
te::mem::DataSet::setRaster
void setRaster(const std::string &name, te::rst::Raster *value)
te::mem::DataSet::isEmpty
bool isEmpty() const
It returns true if the collection is empty.
te::mem::DataSet::setString
void setString(std::size_t i, const std::string &value)
te::mem::DataSet::setUChar
void setUChar(std::size_t i, unsigned char value)
te::mem::DataSet::setValue
void setValue(const std::string &name, te::dt::AbstractData *ad)
te::mem::DataSet::setNumeric
void setNumeric(const std::string &name, const std::string &value)
te::mem::DataSet::getValue
std::unique_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
te::mem::DataSet::setDateTime
void setDateTime(std::size_t i, te::dt::DateTime *value)
te::mem::DataSet::getPropertyDataType
int getPropertyDataType(std::size_t pos) const
It returns the underlying data type of the property at position pos.
te::mem::DataSet::update
void update(te::dt::Property *prop)
It update a property from the dataset.
te::mem::DataSet::setPropertyDataType
void setPropertyDataType(int dt, std::size_t pos)
te::mem::DataSetItem
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver.
Definition: DataSetItem.h:55
te::mem::DataSet::add
void add(const std::string &propertyName, std::size_t propertyType, const te::dt::AbstractData *defaultValue=0)
It adds a new property to the dataset schema and fills this new property with a default value.
te::mem::DataSet::isAfterEnd
bool isAfterEnd() const
It tells if the dataset internal pointer is on the sentinel position after the last element of the co...
te::mem::DataSet::setUChar
void setUChar(const std::string &name, unsigned char value)
te::mem::DataSet::remove
void remove()
It removes the current dataset item.
te::mem::DataSet::copy
void copy(te::da::DataSet &src, const std::vector< std::size_t > &properties, std::size_t limit=0)
It copies up to limit items from the source dataset (src).
te::mem::DataSet::DataSet
DataSet(const DataSet &rhs, const bool deepCopy)
It creates a new In-Memory dataset with the items from the rhs dataset.
te::mem::DataSet::setBool
void setBool(std::size_t i, bool value)
te::mem::DataSet::drop
void drop(std::size_t pos)
It drops a property from the dataset.
te::mem::DataSet::~DataSet
~DataSet()
Destructor.
te::mem::DataSet::setInt64
void setInt64(std::size_t i, boost::int64_t value)
te::mem::DataSet::setByteArray
void setByteArray(std::size_t i, te::dt::ByteArray *value)
te::mem::DataSet::isBeforeBegin
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
te::dt::AbstractData
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:56
te::mem::DataSet::m_ptypes
std::vector< int > m_ptypes
The list of property types.
Definition: DataSet.h:384
TEMEMORYEXPORT
#define TEMEMORYEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:84
te::mem::DataSet::DataSet
DataSet(const te::da::DataSetType *const dt)
It constructs an empty dataset having the schema dt.
te::mem::DataSet::getInt32
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
te::mem::DataSet::getRaster
std::unique_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
te::mem::DataSet::moveFirst
bool moveFirst()
It moves the internal pointer to the first item in the collection.
te::mem::DataSet::getBool
bool getBool(std::size_t i) const
Method for retrieving a boolean attribute value.
te::mem::DataSet::setInt64
void setInt64(const std::string &name, boost::int64_t value)
te::dt::Property
It models a property definition.
Definition: Property.h:60
te::da::DataSet
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:114
te::mem::DataSetPtr
boost::shared_ptr< DataSet > DataSetPtr
Definition: DataSet.h:388
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::mem::DataSet::isAtBegin
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not.
te::mem::DataSet::isNull
bool isNull(std::size_t i) const
It checks if the attribute value is NULL.
te::da::DataSetType
A class that models the description of a dataset.
Definition: DataSetType.h:73
te::mem::DataSet::DataSet
DataSet(te::da::DataSet &rhs, const std::vector< std::size_t > &properties, std::size_t limit)
Copy constructor with property restriction.
te::mem::DataSet::copy
void copy(te::da::DataSet &src, std::size_t limit=0)
It copies up to limit items from the source dataset.
te::mem::DataSet::setByteArray
void setByteArray(const std::string &name, te::dt::ByteArray *value)
te::mem::DataSet::setGeometry
void setGeometry(std::size_t i, te::gm::Geometry *value)
te::mem::DataSet::getDatasetNameOfProperty
std::string getDatasetNameOfProperty(std::size_t pos) const
It returns the underlying dataset name of the property at position pos.
te::mem::DataSet::isAtEnd
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
te::gm::Geometry
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
te::mem::DataSet::getByteArray
std::unique_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
te::mem::DataSet::setChar
void setChar(const std::string &name, char value)
te::mem::DataSet::getExtent
std::unique_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
te::mem::DataSet::getFloat
float getFloat(std::size_t i) const
Method for retrieving a float attribute value.
te::mem::DataSet::setBool
void setBool(const std::string &name, bool value)
te::mem::DataSet::getGeometry
std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
te::mem::DataSet::getPropertyName
std::string getPropertyName(std::size_t pos) const
It returns the property name at position pos.
te::mem::DataSet::moveBeforeFirst
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
te::common::AccessPolicy
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
te::mem::DataSet
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver.
Definition: DataSet.h:66
te::mem::DataSet::setRaster
void setRaster(std::size_t i, te::rst::Raster *value)
te::mem::DataSet::setInt32
void setInt32(const std::string &name, boost::int32_t value)
te::mem::DataSet::DataSet
DataSet(te::da::DataSet &rhs)
Regular copy constructor.