libLAS API Reference (svn-trunk)
iterator.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * $Id$
3 *
4 * Project: libLAS - http://liblas.org - A BSD library for LAS format data.
5 * Purpose: Reader and writer iterator implementation
6 * Author: Mateusz Loskot, mateusz@loskot.net
7 *
8 ******************************************************************************
9 * Copyright (c) 2008, Mateusz Loskot
10 *
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * * Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * * Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided
22 * with the distribution.
23 * * Neither the name of the Martin Isenburg or Iowa Department
24 * of Natural Resources nor the names of its contributors may be
25 * used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
35 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
36 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
38 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
39 * OF SUCH DAMAGE.
40 ****************************************************************************/
41
42#ifndef LIBLAS_ITERATOR_HPP_INCLUDED
43#define LIBLAS_ITERATOR_HPP_INCLUDED
44
45#include <liblas/reader.hpp>
46#include <liblas/writer.hpp>
47#include <liblas/index.hpp>
48#include <liblas/export.hpp>
49#include <iterator>
50#include <cassert>
51
52namespace liblas {
53
59template <typename T>
61{
62public:
63
64 typedef std::input_iterator_tag iterator_category;
65 typedef T value_type;
66 typedef T const* pointer;
67 typedef T const& reference;
68 typedef ptrdiff_t difference_type;
69
72 : m_reader(0)
73 {}
74
78 : m_reader(&reader)
79 {
80 assert(0 != m_reader);
81 getval();
82 }
83
87 {
88 assert(0 != m_reader);
89 if (0 != m_reader)
90 {
91 return m_reader->GetPoint();
92 }
93
94 throw std::runtime_error("reader is null and iterator not dereferencable");
95 }
96
100 {
101 return &(operator*());
102 }
103
107 {
108 assert(0 != m_reader);
109 getval();
110 return (*this);
111 }
112
116 {
117 reader_iterator tmp(*this);
118 ++(*this);
119 return tmp;
120 }
121
124 bool equal(reader_iterator const& rhs) const
125 {
126 return m_reader == rhs.m_reader;
127 }
128
129private:
130
131 void getval()
132 {
133 if (0 != m_reader && !(m_reader->ReadNextPoint()))
134 {
135 m_reader = 0;
136 }
137 }
138
139 liblas::Reader* m_reader;
140};
141
143template <typename T>
145{
146 return lhs.equal(rhs);
147}
148
150template <typename T>
152{
153 return (!(lhs == rhs));
154}
155
160template <typename T>
162{
163public:
164
165 typedef std::output_iterator_tag iterator_category;
166 typedef void value_type;
167 typedef void pointer;
168 typedef T const& reference;
169 typedef void difference_type;
170
175 : m_writer(&writer)
176 {
177 assert(0 != m_writer);
178 }
179
183 {
184 assert(0 != m_writer);
185
186 bool ret = false;
187 ret = m_writer->WritePoint(value);
188 assert(ret);
189
190 return (*this);
191 }
192
195 {
196 // pretend to return designated value
197 return (*this);
198 }
199
202 {
203 // pretend to preincrement
204 return (*this);
205 }
206
209 {
210 // pretend to postincrement
211 return (*this);
212 }
213
214private:
215
216 liblas::Writer* m_writer;
217};
218
219template <typename T>
221{
222public:
223
224 typedef std::input_iterator_tag iterator_category;
225 typedef T value_type;
226 typedef T const* pointer;
227 typedef T const& reference;
228 typedef ptrdiff_t difference_type;
229
232 : m_index(0)
233 {}
234
238 : m_index(&index)
239 {
240 assert(0 != m_index);
241 getval();
242 }
243
247 {
248 assert(0 != m_index);
249 if (0 != m_index)
250 {
251 // return m_index->GetNextID();
252 }
253
254 throw std::runtime_error("index is null and iterator not dereferencable");
255 }
256
260 {
261 return &(operator*());
262 }
263
267 {
268 assert(0 != m_index);
269 getval();
270 return (*this);
271 }
272
276 {
277 index_filter_iterator tmp(*this);
278 ++(*this);
279 return tmp;
280 }
281
284 bool equal(index_filter_iterator const& rhs) const
285 {
286 return m_index == rhs.m_index;
287 }
288
289private:
290
291 void getval()
292 {
293 // if (0 != m_index && !(m_index->FindNextID()))
294 // {
295 // m_index = 0;
296 // }
297 }
298
299 liblas::Index* m_index;
300};
301
302// Declare specializations for user's convenience
303
306
309
310// Needed for C++ DLL exports
311#ifdef _MSC_VER
312template class LAS_DLL reader_iterator<Point>;
313template class LAS_DLL writer_iterator<Point>;
314#endif
315
316} // namespace liblas
317
318#endif // LIBLAS_ITERATOR_HPP_INCLUDED
Definition index.hpp:120
Defines public interface to LAS reader implementation.
Definition reader.hpp:67
Defines public interface to LAS writer implementation.
Definition writer.hpp:64
T value_type
Definition iterator.hpp:225
reference operator*() const
Dereference operator.
Definition iterator.hpp:246
std::input_iterator_tag iterator_category
Definition iterator.hpp:224
pointer operator->() const
Pointer-to-member operator.
Definition iterator.hpp:259
index_filter_iterator operator++(int)
Post-increment operator.
Definition iterator.hpp:275
T const * pointer
Definition iterator.hpp:226
ptrdiff_t difference_type
Definition iterator.hpp:228
bool equal(index_filter_iterator const &rhs) const
Compare passed iterator to this.
Definition iterator.hpp:284
index_filter_iterator(liblas::Index &index)
Initializes iterator pointing to beginning of Index's filtered points sequence.
Definition iterator.hpp:237
index_filter_iterator & operator++()
Pre-increment operator.
Definition iterator.hpp:266
T const & reference
Definition iterator.hpp:227
index_filter_iterator()
Initializes iterator pointing to pass-the-end.
Definition iterator.hpp:231
Input iterator associated with liblas::LASReader.
Definition iterator.hpp:61
reader_iterator(liblas::Reader &reader)
Initializes iterator pointing to beginning of LAS file sequence.
Definition iterator.hpp:77
pointer operator->() const
Pointer-to-member operator.
Definition iterator.hpp:99
reference operator*() const
Dereference operator.
Definition iterator.hpp:86
reader_iterator()
Initializes iterator pointing to pass-the-end.
Definition iterator.hpp:71
reader_iterator operator++(int)
Post-increment opertor.
Definition iterator.hpp:115
std::input_iterator_tag iterator_category
Definition iterator.hpp:64
T const * pointer
Definition iterator.hpp:66
T const & reference
Definition iterator.hpp:67
bool equal(reader_iterator const &rhs) const
Compare passed iterator to this.
Definition iterator.hpp:124
ptrdiff_t difference_type
Definition iterator.hpp:68
T value_type
Definition iterator.hpp:65
reader_iterator & operator++()
Pre-increment opertor.
Definition iterator.hpp:106
Output iterator associated with liblas::LASWriter.
Definition iterator.hpp:162
writer_iterator operator++(int)
Post-increment operator.
Definition iterator.hpp:208
void value_type
Definition iterator.hpp:166
writer_iterator(liblas::Writer &writer)
Initialize iterator with given writer.
Definition iterator.hpp:174
std::output_iterator_tag iterator_category
Definition iterator.hpp:165
void difference_type
Definition iterator.hpp:169
writer_iterator & operator++()
Pre-increment operator.
Definition iterator.hpp:201
void pointer
Definition iterator.hpp:167
T const & reference
Definition iterator.hpp:168
writer_iterator & operator=(reference value)
Dereference assignment operator.
Definition iterator.hpp:182
writer_iterator & operator*()
Dereference operator.
Definition iterator.hpp:194
#define LAS_DLL
Definition export.hpp:58
Namespace grouping all elements of libLAS public interface.
Definition bounds.hpp:60
reader_iterator< Point > lasreader_iterator
Public specialization of LASReader input iterator for liblas::LASPoint type.
Definition iterator.hpp:305
bool operator!=(Classification const &lhs, Classification const &rhs)
Not-equal-to operator implemented in terms of Classification::equal.
Definition classification.hpp:232
bool operator==(Classification const &lhs, Classification const &rhs)
Equal-to operator implemented in terms of Classification::equal.
Definition classification.hpp:226
writer_iterator< Point > laswriter_iterator
Public specialization of LASWriter output iterator for liblas::LASPoint type.
Definition iterator.hpp:308
Definition schema.hpp:80