All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FilteredDataSet.cpp
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/dataaccess/dataset/FilteredDataSet.cpp
22 
23  \brief This class represents a filtered data set.
24 */
25 
26 // TerraLib
27 #include "../../geometry/Envelope.h"
28 #include "FilteredDataSet.h"
29 
30 // STL
31 #include <cassert>
32 
33 te::da::FilteredDataSet::FilteredDataSet(DataSet* dataset, const std::vector<std::size_t>& positions, bool isOwner)
34  : m_ds(dataset, isOwner),
35  m_positions(positions),
36  m_i(-1)
37 {
38  assert(dataset);
39 
40  std::sort(m_positions.begin(), m_positions.end());
41 }
42 
44  const std::vector<std::size_t>& positions, bool isOwner)
45  : m_ds(dataset, isOwner),
46  m_capabilites(capabilities),
47  m_positions(positions),
48  m_i(-1)
49 {
50  assert(dataset);
51 
52  std::sort(m_positions.begin(), m_positions.end());
53 }
54 
56 {
57 }
58 
60 {
61  return m_ds->getTraverseType();
62 }
63 
65 {
66  return m_ds->getAccessPolicy();
67 }
68 
69 std::auto_ptr<te::gm::Envelope> te::da::FilteredDataSet::getExtent(std::size_t i)
70 {
71  return m_ds->getExtent(i);
72 }
73 
75 {
76  return m_ds->getNumProperties();
77 }
78 
80 {
81  return m_ds->getPropertyDataType(pos);
82 }
83 
84 std::string te::da::FilteredDataSet::getPropertyName(std::size_t pos) const
85 {
86  return m_ds->getPropertyName(pos);
87 }
88 
89 std::string te::da::FilteredDataSet::getDatasetNameOfProperty(std::size_t pos) const
90 {
91  return m_ds->getDatasetNameOfProperty(pos);
92 }
93 
95 {
96  return m_positions.empty();
97 }
98 
100 {
101  return m_ds->isConnected();
102 }
103 
104 std::size_t te::da::FilteredDataSet::size() const
105 {
106  return m_positions.size();
107 }
108 
110 {
111  int oldPos = m_i;
112 
113  m_i++;
114 
115  if(m_i == size())
116  return false;
117 
118  if(m_capabilites.supportsEfficientMove() || oldPos == -1)
119  return move(static_cast<std::size_t>(m_i));
120 
121  assert(m_positions[oldPos] < m_positions[m_i]);
122 
123  // Read forward and skip features by the difference of the new and old positions
124  for(std::size_t i = m_positions[oldPos]; i < m_positions[m_i]; ++i)
125  {
126  if(!m_ds->moveNext())
127  return false;
128  }
129 
130  return true;
131 }
132 
134 {
135  m_i--;
136 
137  if(m_i < 0)
138  return false;
139 
140  return move(static_cast<std::size_t>(m_i));
141 }
142 
144 {
145  m_i = -1;
146  return true;
147 }
148 
150 {
151  m_i = 0;
152  return move(m_i);
153 }
154 
156 {
157  m_i = size() - 1;
158  return move(m_i);
159 }
160 
161 bool te::da::FilteredDataSet::move(std::size_t i)
162 {
163  assert(i < size());
164 
165  return m_ds->move(m_positions[i]);
166 }
167 
169 {
170  return m_i == 0;
171 }
172 
174 {
175  return m_i == -1;
176 }
177 
179 {
180  return m_i == size() - 1;
181 }
182 
184 {
185  return m_i == size();
186 }
187 
188 char te::da::FilteredDataSet::getChar(std::size_t i) const
189 {
190  return m_ds->getChar(i);
191 }
192 
193 unsigned char te::da::FilteredDataSet::getUChar(std::size_t i) const
194 {
195  return m_ds->getUChar(i);
196 }
197 
198 boost::int16_t te::da::FilteredDataSet::getInt16(std::size_t i) const
199 {
200  return m_ds->getInt16(i);
201 }
202 
203 boost::int32_t te::da::FilteredDataSet::getInt32(std::size_t i) const
204 {
205  return m_ds->getInt32(i);
206 }
207 
208 boost::int64_t te::da::FilteredDataSet::getInt64(std::size_t i) const
209 {
210  return m_ds->getInt64(i);
211 }
212 
213 bool te::da::FilteredDataSet::getBool(std::size_t i) const
214 {
215  return m_ds->getBool(i);
216 }
217 
218 float te::da::FilteredDataSet::getFloat(std::size_t i) const
219 {
220  return m_ds->getFloat(i);
221 }
222 
223 double te::da::FilteredDataSet::getDouble(std::size_t i) const
224 {
225  return m_ds->getDouble(i);
226 }
227 
228 std::string te::da::FilteredDataSet::getNumeric(std::size_t i) const
229 {
230  return m_ds->getNumeric(i);
231 }
232 
233 std::string te::da::FilteredDataSet::getString(std::size_t i) const
234 {
235  return m_ds->getString(i);
236 }
237 
238 std::auto_ptr<te::dt::ByteArray> te::da::FilteredDataSet::getByteArray(std::size_t i) const
239 {
240  return m_ds->getByteArray(i);
241 }
242 
243 std::auto_ptr<te::gm::Geometry> te::da::FilteredDataSet::getGeometry(std::size_t i) const
244 {
245  return m_ds->getGeometry(i);
246 }
247 
248 std::auto_ptr<te::rst::Raster> te::da::FilteredDataSet::getRaster(std::size_t i) const
249 {
250  return m_ds->getRaster(i);
251 }
252 
253 std::auto_ptr<te::dt::DateTime> te::da::FilteredDataSet::getDateTime(std::size_t i) const
254 {
255  return m_ds->getDateTime(i);
256 }
257 
258 std::auto_ptr<te::dt::Array> te::da::FilteredDataSet::getArray(std::size_t i) const
259 {
260  return m_ds->getArray(i);
261 }
262 
263 bool te::da::FilteredDataSet::isNull(std::size_t i) const
264 {
265  return m_ds->isNull(i);
266 }
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
bool moveFirst()
It moves the internal pointer to the first item in the collection.
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
char getChar(std::size_t i) const
Method for retrieving a signed character attribute value (1 byte long).
This class represents a filtered data set.
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
std::auto_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
FilteredDataSet(DataSet *dataset, const std::vector< std::size_t > &positions, bool isOwner=false)
Constructor.
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.
bool getBool(std::size_t i) const
Method for retrieving a boolean attribute value.
int getPropertyDataType(std::size_t pos) const
It returns the underlying data type of the property at position pos.
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
double getDouble(std::size_t i) const
Method for retrieving a double attribute value.
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
std::string getString(std::size_t i) const
Method for retrieving a string value attribute.
std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
std::string getPropertyName(std::size_t pos) const
It returns the property name at position pos.
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not...
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
bool isEmpty() const
It returns true if the collection is empty.
std::vector< std::size_t > m_positions
The data set positions that actually will be accessed.
A class that informs what the dataset implementation of a given data source can perform.
bool moveNext()
It moves the internal pointer to the next item of the collection.
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
bool isNull(std::size_t i) const
It checks if the attribute value is NULL.
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
std::string getDatasetNameOfProperty(std::size_t pos) const
It returns the underlying dataset name of the property at position pos.
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
float getFloat(std::size_t i) const
Method for retrieving a float attribute value.
~FilteredDataSet()
Destructor.
te::common::TraverseType getTraverseType() const
It returns the traverse type associated to the dataset.
bool isAfterEnd() const
It tells if the dataset internal pointer is on the sentinel position after the last element of the co...
std::size_t size() const
It returns the collection size, if it is known.
unsigned char getUChar(std::size_t i) const
Method for retrieving an unsigned character attribute value (1 byte long).
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
std::string getNumeric(std::size_t i) const
Method for retrieving a numeric attribute value.
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:111
te::da::DataSourceCapabilities capabilities
std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
boost::int64_t getInt64(std::size_t i) const
Method for retrieving a 64-bit integer attribute value (8 bytes long).
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
std::auto_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.