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