libLAS API Reference  1.8.1
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 
52 namespace liblas {
53 
59 template <typename T>
61 {
62 public:
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 
86  reference operator*() const
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 
99  pointer operator->() const
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 
129 private:
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 
143 template <typename T>
145 {
146  return lhs.equal(rhs);
147 }
148 
150 template <typename T>
152 {
153  return (!(lhs == rhs));
154 }
155 
160 template <typename T>
162 {
163 public:
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 
182  writer_iterator& operator=(reference value)
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 
214 private:
215 
216  liblas::Writer* m_writer;
217 };
218 
219 template <typename T>
221 {
222 public:
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 
246  reference operator*() const
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 
259  pointer operator->() const
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 
289 private:
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
312 template class LAS_DLL reader_iterator<Point>;
313 template class LAS_DLL writer_iterator<Point>;
314 #endif
315 
316 } // namespace liblas
317 
318 #endif // LIBLAS_ITERATOR_HPP_INCLUDED
writer_iterator(liblas::Writer &writer)
Initialize iterator with given writer.
Definition: iterator.hpp:174
T const & reference
Definition: iterator.hpp:67
reference operator*() const
Dereference operator.
Definition: iterator.hpp:246
T value_type
Definition: iterator.hpp:225
bool operator!=(Classification const &lhs, Classification const &rhs)
Not-equal-to operator implemented in terms of Classification::equal.
Definition: classification.hpp:232
#define LAS_DLL
Definition: export.hpp:58
T const * pointer
Definition: iterator.hpp:66
void value_type
Definition: iterator.hpp:166
index_filter_iterator()
Initializes iterator pointing to pass-the-end.
Definition: iterator.hpp:231
ptrdiff_t difference_type
Definition: iterator.hpp:68
T const & reference
Definition: iterator.hpp:168
T const * pointer
Definition: iterator.hpp:226
writer_iterator operator++(int)
Post-increment operator.
Definition: iterator.hpp:208
Input iterator associated with liblas::LASReader.
Definition: iterator.hpp:60
std::output_iterator_tag iterator_category
Definition: iterator.hpp:165
pointer operator->() const
Pointer-to-member operator.
Definition: iterator.hpp:259
reader_iterator()
Initializes iterator pointing to pass-the-end.
Definition: iterator.hpp:71
Output iterator associated with liblas::LASWriter.
Definition: iterator.hpp:161
reader_iterator operator++(int)
Post-increment opertor.
Definition: iterator.hpp:115
Definition: iterator.hpp:220
reference operator*() const
Dereference operator.
Definition: iterator.hpp:86
T value_type
Definition: iterator.hpp:65
reader_iterator< Point > lasreader_iterator
Public specialization of LASReader input iterator for liblas::LASPoint type.
Definition: iterator.hpp:305
pointer operator->() const
Pointer-to-member operator.
Definition: iterator.hpp:99
index_filter_iterator operator++(int)
Post-increment operator.
Definition: iterator.hpp:275
Defines public interface to LAS reader implementation.
Definition: reader.hpp:66
reader_iterator & operator++()
Pre-increment opertor.
Definition: iterator.hpp:106
Definition: index.hpp:119
reader_iterator(liblas::Reader &reader)
Initializes iterator pointing to beginning of LAS file sequence.
Definition: iterator.hpp:77
bool operator==(Classification const &lhs, Classification const &rhs)
Equal-to operator implemented in terms of Classification::equal.
Definition: classification.hpp:226
Namespace grouping all elements of libLAS public interface.
Definition: bounds.hpp:60
bool equal(index_filter_iterator const &rhs) const
Compare passed iterator to this.
Definition: iterator.hpp:284
Defines public interface to LAS writer implementation.
Definition: writer.hpp:63
writer_iterator & operator*()
Dereference operator.
Definition: iterator.hpp:194
index_filter_iterator(liblas::Index &index)
Initializes iterator pointing to beginning of Index&#39;s filtered points sequence.
Definition: iterator.hpp:237
ptrdiff_t difference_type
Definition: iterator.hpp:228
void pointer
Definition: iterator.hpp:167
writer_iterator & operator=(reference value)
Dereference assignment operator.
Definition: iterator.hpp:182
T const & reference
Definition: iterator.hpp:227
bool equal(reader_iterator const &rhs) const
Compare passed iterator to this.
Definition: iterator.hpp:124
writer_iterator< Point > laswriter_iterator
Public specialization of LASWriter output iterator for liblas::LASPoint type.
Definition: iterator.hpp:308
writer_iterator & operator++()
Pre-increment operator.
Definition: iterator.hpp:201
std::input_iterator_tag iterator_category
Definition: iterator.hpp:224
Definition: schema.hpp:80
std::input_iterator_tag iterator_category
Definition: iterator.hpp:64
void difference_type
Definition: iterator.hpp:169
index_filter_iterator & operator++()
Pre-increment operator.
Definition: iterator.hpp:266