Loading...
Searching...
No Matches
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
41namespace 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
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
A class that models the description of a dataset.
Definition: DataSetType.h:73
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:114
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:56
A class for representing binary data.
Definition: ByteArray.h:52
It models a property definition.
Definition: Property.h:60
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver.
Definition: DataSetItem.h:55
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver.
Definition: DataSet.h:66
std::string getString(std::size_t i) const
Method for retrieving a string value attribute.
std::string getPropertyName(std::size_t pos) const
It returns the property name at position pos.
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
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.
void setPropertyName(const std::string &name, std::size_t pos)
void setInt32(const std::string &name, boost::int32_t value)
std::string getDatasetNameOfProperty(std::size_t pos) const
It returns the underlying dataset name of the property at position pos.
DataSet(const te::da::DataSetType *const dt)
It constructs an empty dataset having the schema dt.
bool isNull(std::size_t i) const
It checks if the attribute value is NULL.
void setInt16(std::size_t i, boost::int16_t value)
bool moveFirst()
It moves the internal pointer to the first item in the collection.
std::unique_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
void setInt16(const std::string &name, boost::int16_t value)
void setChar(std::size_t i, char value)
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
boost::shared_ptr< boost::ptr_vector< te::mem::DataSetItem > > m_items
The list of dataset items.
Definition: DataSet.h:382
void setString(std::size_t i, const std::string &value)
std::unique_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
std::vector< int > m_ptypes
The list of property types.
Definition: DataSet.h:384
void setUChar(std::size_t i, unsigned char value)
std::vector< std::string > m_pnames
The list of property names.
Definition: DataSet.h:383
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
void setBool(std::size_t i, bool value)
void remove(te::mem::DataSetItem *item)
It removes a specific dataset item.
void setBool(const std::string &name, bool value)
void setChar(const std::string &name, char value)
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.
boost::int64_t getInt64(std::size_t i) const
Method for retrieving a 64-bit integer attribute value (8 bytes long).
void setPropertyDataType(int dt, std::size_t pos)
bool isEmpty() const
It returns true if the collection is empty.
void setInt64(std::size_t i, boost::int64_t value)
std::unique_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
DataSet(const DataSet &rhs, const bool deepCopy)
It creates a new In-Memory dataset with the items from the rhs dataset.
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).
void setFloat(std::size_t i, float value)
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not.
void setValue(std::size_t i, te::dt::AbstractData *value)
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
bool moveNext()
It moves the internal pointer to the next item of the collection.
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
DataSet(te::da::DataSet &rhs)
Regular copy constructor.
std::unique_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
bool isAfterEnd() const
It tells if the dataset internal pointer is on the sentinel position after the last element of the co...
void setInt64(const std::string &name, boost::int64_t value)
void setNumeric(std::size_t i, const std::string &value)
DataSet(te::da::DataSet &rhs, const std::vector< std::size_t > &properties, std::size_t limit)
Copy constructor with property restriction.
unsigned char getUChar(std::size_t i) const
Method for retrieving an unsigned character attribute value (1 byte long).
bool isPositionValid() const
It tells if the dataset internal pointer is on a valid position.
void setRaster(const std::string &name, te::rst::Raster *value)
void setGeometry(std::size_t i, te::gm::Geometry *value)
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
void update(te::dt::Property *prop)
It update a property from the dataset.
void setDateTime(const std::string &name, te::dt::DateTime *value)
void drop(std::size_t pos)
It drops a property from the dataset.
std::string getNumeric(std::size_t i) const
Method for retrieving a numeric attribute value.
void remove()
It removes the current dataset item.
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
void setGeometry(const std::string &name, te::gm::Geometry *value)
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
void setDouble(std::size_t i, double value)
void clear()
It clears all the dataset items.
void setByteArray(const std::string &name, te::dt::ByteArray *value)
void setInt32(std::size_t i, boost::int32_t value)
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.
std::unique_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
int m_i
The index of the current item.
Definition: DataSet.h:385
void setUChar(const std::string &name, unsigned char value)
~DataSet()
Destructor.
void copy(te::da::DataSet &src, std::size_t limit=0)
It copies up to limit items from the source dataset.
void setDateTime(std::size_t i, te::dt::DateTime *value)
bool getBool(std::size_t i) const
Method for retrieving a boolean attribute value.
void setRaster(std::size_t i, te::rst::Raster *value)
void add(te::mem::DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
double getDouble(std::size_t i) const
Method for retrieving a double attribute value.
void setFloat(const std::string &name, float value)
void setByteArray(std::size_t i, te::dt::ByteArray *value)
int getPropertyDataType(std::size_t pos) const
It returns the underlying data type of the property at position pos.
void setNumeric(const std::string &name, const std::string &value)
std::size_t size() const
It returns the collection size, if it is known.
te::common::TraverseType getTraverseType() const
It returns the traverse type associated to the dataset.
void setValue(const std::string &name, te::dt::AbstractData *ad)
char getChar(std::size_t i) const
Method for retrieving a signed character attribute value (1 byte long).
float getFloat(std::size_t i) const
Method for retrieving a float attribute value.
void setDouble(const std::string &name, double value)
void setString(const std::string &name, const std::string &value)
An abstract class for raster data strucutures.
Definition: Raster.h:72
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:54
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
boost::shared_ptr< DataSet > DataSetPtr
Definition: DataSet.h:388
TerraLib.
#define TEMEMORYEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:84
Proxy configuration file for TerraView (see terraview_config.h).