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