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  */
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 = false);
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  DataSet(te::da::DataSet& rhs, const std::vector<std::size_t>& properties, std::size_t limit = 0);
127 
128  /*! \brief Destructor. */
129  ~DataSet();
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  */
177  void add(DataSetItem* item);
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  */
191  void remove(DataSetItem* item);
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  */
228  void update(te::dt::Property* prop);
229 
230  /*! \name DataSet inherited methods */
231  //@{
232  te::common::TraverseType getTraverseType() const;
233 
234  te::common::AccessPolicy getAccessPolicy() const;
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  te::common::CharEncoding getPropertyCharEncoding(std::size_t i) const;
247 
248  std::string getDatasetNameOfProperty(std::size_t pos) const;
249 
250  DataSetItem* getItem() const;
251 
252  bool isEmpty() const;
253 
254  bool isConnected() const;
255 
256  std::size_t size() const;
257 
258  std::auto_ptr<te::gm::Envelope> getExtent(std::size_t i);
259 
260  bool moveNext();
261 
262  bool movePrevious();
263 
264  bool moveBeforeFirst();
265 
266  bool moveFirst();
267 
268  bool moveLast();
269 
270  bool move(std::size_t i);
271 
272  bool isAtBegin() const;
273 
274  bool isBeforeBegin() const;
275 
276  bool isAtEnd() const;
277 
278  bool isAfterEnd() const;
279 
280  char getChar(std::size_t i) const;
281 
282  unsigned char getUChar(std::size_t i) const;
283 
284  boost::int16_t getInt16(std::size_t i) const;
285 
286  boost::int32_t getInt32(std::size_t i) const;
287 
288  boost::int64_t getInt64(std::size_t i) const;
289 
290  bool getBool(std::size_t i) const;
291 
292  float getFloat(std::size_t i) const;
293 
294  double getDouble(std::size_t i) const;
295 
296  std::string getNumeric(std::size_t i) const;
297 
298  std::string getString(std::size_t i) const;
299 
300  std::auto_ptr<te::dt::ByteArray> getByteArray(std::size_t i) const;
301 
302  std::auto_ptr<te::gm::Geometry> getGeometry(std::size_t i) const;
303 
304  std::auto_ptr<te::rst::Raster> getRaster(std::size_t i) const;
305 
306  std::auto_ptr<te::dt::DateTime> getDateTime(std::size_t i) const;
307 
308  std::auto_ptr<te::dt::Array> getArray(std::size_t i) const;
309 
310  std::auto_ptr<te::dt::AbstractData> getValue(std::size_t i) const;
311 
312  bool isNull(std::size_t i) const;
313  //@}
314 
315  /*! \name Methods to set values to the DataSet
316 
317  \Note These methods will take the ownership of the given pointers.
318  */
319  //@{
320  void setChar(std::size_t i, char value);
321 
322  void setChar(const std::string& name, char value);
323 
324  void setUChar(std::size_t i, unsigned char value);
325 
326  void setUChar(const std::string& name, unsigned char value);
327 
328  void setInt16(std::size_t i, boost::int16_t value);
329 
330  void setInt16(const std::string& name, boost::int16_t value);
331 
332  void setInt32(std::size_t i, boost::int32_t value);
333 
334  void setInt32(const std::string& name, boost::int32_t value);
335 
336  void setInt64(std::size_t i, boost::int64_t value);
337 
338  void setInt64(const std::string& name, boost::int64_t value);
339 
340  void setBool(std::size_t i, bool value);
341 
342  void setBool(const std::string& name, bool value);
343 
344  void setFloat(std::size_t i, float value);
345 
346  void setFloat(const std::string& name, float value);
347 
348  void setDouble(std::size_t i, double value);
349 
350  void setDouble(const std::string& name, double value);
351 
352  void setNumeric(std::size_t i, const std::string& value);
353 
354  void setNumeric(const std::string& name, const std::string& value);
355 
356  void setString(std::size_t i, const std::string& value);
357 
358  void setString(const std::string& name, const std::string& value);
359 
360  void setByteArray(std::size_t i, te::dt::ByteArray* value);
361 
362  void setByteArray(const std::string& name, te::dt::ByteArray* value);
363 
364  void setGeometry(std::size_t i, te::gm::Geometry* value);
365 
366  void setGeometry(const std::string& name, te::gm::Geometry* value);
367 
368  void setRaster(std::size_t i, te::rst::Raster* value);
369 
370  void setRaster(const std::string& name, te::rst::Raster* value);
371 
372  void setDateTime(std::size_t i, te::dt::DateTime* value);
373 
374  void setDateTime(const std::string& name, te::dt::DateTime* value);
375 
376  void setValue(std::size_t i, te::dt::AbstractData* value);
377 
378  void setValue(const std::string& name, te::dt::AbstractData* ad);
379 
380  //@}
381 
382  protected:
383 
384  boost::shared_ptr<boost::ptr_vector<DataSetItem> > m_items; //!< The list of dataset items.
385  std::vector<std::string> m_pnames; //!< The list of property names.
386  std::vector<int> m_ptypes; //!< The list of property types.
387  std::map<int, te::common::CharEncoding> m_encodings; //!< The list of string properties char-encoding.
388  int m_i; //!< The index of the current item.
389  };
390 
391  typedef boost::shared_ptr<DataSet> DataSetPtr;
392 
393  } // end namespace mem
394 } // end namespace te
395 
396 #endif // __TERRALIB_MEMORY_INTERNAL_DATASET_H
boost::shared_ptr< boost::ptr_vector< DataSetItem > > m_items
The list of dataset items.
Definition: DataSet.h:384
boost::shared_ptr< DataSet > DataSetPtr
Definition: DataSet.h:391
#define TEMEMORYEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:84
CharEncoding
Supported charsets (character encoding).
A class that models the description of a dataset.
Definition: DataSetType.h:72
Configuration flags for the TerraLib In-memory Data Access driver.
std::map< int, te::common::CharEncoding > m_encodings
The list of string properties char-encoding.
Definition: DataSet.h:387
It models a property definition.
Definition: Property.h:59
std::vector< int > m_ptypes
The list of property types.
Definition: DataSet.h:386
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
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
Definition: DataSet.h:65
An abstract class for raster data strucutures.
Definition: Raster.h:71
URI C++ Library.
std::vector< std::string > m_pnames
The list of property names.
Definition: DataSet.h:385
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
Definition: DataSetItem.h:56
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
int m_i
The index of the current item.
Definition: DataSet.h:388
A class for representing binary data.
Definition: ByteArray.h:51