All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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(-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(i);
82 }
83 
84 std::string te::da::FilteredDataSet::getPropertyName(std::size_t i) const
85 {
86  return m_ds->getPropertyName(i);
87 }
88 
90 {
91  return m_ds->getPropertyCharEncoding(i);
92 }
93 
94 std::string te::da::FilteredDataSet::getDatasetNameOfProperty(std::size_t i) const
95 {
96  return m_ds->getDatasetNameOfProperty(i);
97 }
98 
100 {
101  return m_positions.empty();
102 }
103 
105 {
106  return m_ds->isConnected();
107 }
108 
109 std::size_t te::da::FilteredDataSet::size() const
110 {
111  return m_positions.size();
112 }
113 
115 {
116  int oldPos = m_i;
117 
118  m_i++;
119 
120  if(m_i == size())
121  return false;
122 
123  if(m_capabilites.supportsEfficientMove() || oldPos == -1)
124  return move(static_cast<std::size_t>(m_i));
125 
126  assert(m_positions[oldPos] < m_positions[m_i]);
127 
128  // Read forward and skip features by the difference of the new and old positions
129  for(std::size_t i = m_positions[oldPos]; i < m_positions[m_i]; ++i)
130  {
131  if(!m_ds->moveNext())
132  return false;
133  }
134 
135  return true;
136 }
137 
139 {
140  m_i--;
141 
142  if(m_i < 0)
143  return false;
144 
145  return move(static_cast<std::size_t>(m_i));
146 }
147 
149 {
150  m_i = -1;
151  return true;
152 }
153 
155 {
156  m_i = 0;
157  return move(m_i);
158 }
159 
161 {
162  m_i = size() - 1;
163  return move(m_i);
164 }
165 
166 bool te::da::FilteredDataSet::move(std::size_t i)
167 {
168  assert(i < size());
169 
170  return m_ds->move(m_positions[i]);
171 }
172 
174 {
175  return m_i == 0;
176 }
177 
179 {
180  return m_i == -1;
181 }
182 
184 {
185  return m_i == size() - 1;
186 }
187 
189 {
190  return m_i == size();
191 }
192 
193 char te::da::FilteredDataSet::getChar(std::size_t i) const
194 {
195  return m_ds->getChar(i);
196 }
197 
198 unsigned char te::da::FilteredDataSet::getUChar(std::size_t i) const
199 {
200  return m_ds->getUChar(i);
201 }
202 
203 boost::int16_t te::da::FilteredDataSet::getInt16(std::size_t i) const
204 {
205  return m_ds->getInt16(i);
206 }
207 
208 boost::int32_t te::da::FilteredDataSet::getInt32(std::size_t i) const
209 {
210  return m_ds->getInt32(i);
211 }
212 
213 boost::int64_t te::da::FilteredDataSet::getInt64(std::size_t i) const
214 {
215  return m_ds->getInt64(i);
216 }
217 
218 bool te::da::FilteredDataSet::getBool(std::size_t i) const
219 {
220  return m_ds->getBool(i);
221 }
222 
223 float te::da::FilteredDataSet::getFloat(std::size_t i) const
224 {
225  return m_ds->getFloat(i);
226 }
227 
228 double te::da::FilteredDataSet::getDouble(std::size_t i) const
229 {
230  return m_ds->getDouble(i);
231 }
232 
233 std::string te::da::FilteredDataSet::getNumeric(std::size_t i) const
234 {
235  return m_ds->getNumeric(i);
236 }
237 
238 std::string te::da::FilteredDataSet::getString(std::size_t i) const
239 {
240  return m_ds->getString(i);
241 }
242 
243 std::auto_ptr<te::dt::ByteArray> te::da::FilteredDataSet::getByteArray(std::size_t i) const
244 {
245  return m_ds->getByteArray(i);
246 }
247 
248 std::auto_ptr<te::gm::Geometry> te::da::FilteredDataSet::getGeometry(std::size_t i) const
249 {
250  return m_ds->getGeometry(i);
251 }
252 
253 std::auto_ptr<te::rst::Raster> te::da::FilteredDataSet::getRaster(std::size_t i) const
254 {
255  return m_ds->getRaster(i);
256 }
257 
258 std::auto_ptr<te::dt::DateTime> te::da::FilteredDataSet::getDateTime(std::size_t i) const
259 {
260  return m_ds->getDateTime(i);
261 }
262 
263 std::auto_ptr<te::dt::Array> te::da::FilteredDataSet::getArray(std::size_t i) const
264 {
265  return m_ds->getArray(i);
266 }
267 
268 bool te::da::FilteredDataSet::isNull(std::size_t i) const
269 {
270  return m_ds->isNull(i);
271 }
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 ...
CharEncoding
Supported charsets (character encoding).
std::auto_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
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.
std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
~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).
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.
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).
Definition: Enums.h:40
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
bool moveNext()
It moves the internal pointer to the next item of the collection.
std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
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::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric 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.
te::common::CharEncoding getPropertyCharEncoding(std::size_t i) const
It returns the property character encoding at position pos.
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
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...
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::auto_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
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.
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.
This class represents a filtered data set.
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.