~ubuntu-branches/ubuntu/trusty/liblas/trusty-proposed

« back to all changes in this revision

Viewing changes to include/liblas/iterator.hpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2014-01-05 17:00:29 UTC
  • mfrom: (7.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140105170029-ddtp0j63x5jvck2u
Tags: 1.7.0+dfsg-2
Fixed missing linking of system boost component.
(closes: #733282)

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#ifndef LIBLAS_ITERATOR_HPP_INCLUDED
43
43
#define LIBLAS_ITERATOR_HPP_INCLUDED
44
44
 
45
 
#include <liblas/lasreader.hpp>
46
 
#include <liblas/laswriter.hpp>
 
45
#include <liblas/reader.hpp>
 
46
#include <liblas/writer.hpp>
 
47
#include <liblas/index.hpp>
 
48
#include <liblas/export.hpp>
47
49
#include <iterator>
48
50
#include <cassert>
49
51
 
55
57
/// \sa About Input Iterator at http://www.sgi.com/tech/stl/InputIterator.html
56
58
///
57
59
template <typename T>
58
 
class reader_iterator
 
60
class LAS_DLL reader_iterator
59
61
{
60
62
public:
61
63
 
72
74
 
73
75
    /// Initializes iterator pointing to beginning of LAS file sequence.
74
76
    /// No ownership transfer of reader object occurs.
75
 
    reader_iterator(liblas::LASReader& reader)
 
77
    reader_iterator(liblas::Reader& reader)
76
78
        : m_reader(&reader)
77
79
    {
78
80
        assert(0 != m_reader);
84
86
    reference operator*() const
85
87
    {
86
88
        assert(0 != m_reader);
87
 
        return m_reader->GetPoint();
 
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");
88
95
    }
89
96
 
90
97
    /// Pointer-to-member operator.
129
136
        }
130
137
    }
131
138
 
132
 
    liblas::LASReader* m_reader;
 
139
    liblas::Reader* m_reader;
133
140
};
134
141
 
135
142
/// Equality operator implemented in terms of reader_iterator::equal
151
158
/// \sa About Output Iterator at http://www.sgi.com/tech/stl/OutputIterator.html
152
159
///
153
160
template <typename T>
154
 
class writer_iterator
 
161
class LAS_DLL writer_iterator
155
162
{
156
163
public:
157
164
 
164
171
    /// Initialize iterator with given writer.
165
172
    /// The writer position is not changed.
166
173
    /// No ownership transfer of writer object occurs.
167
 
    writer_iterator(liblas::LASWriter& writer)
 
174
    writer_iterator(liblas::Writer& writer)
168
175
        : m_writer(&writer)
169
176
    {
170
177
        assert(0 != m_writer);
176
183
    {
177
184
        assert(0 != m_writer);
178
185
 
179
 
        bool const ret = m_writer->WritePoint(value);
180
 
        assert(ret); // TODO: Low-level debugging
 
186
        bool ret = false;
 
187
        ret = m_writer->WritePoint(value);
 
188
        assert(ret);
181
189
 
182
190
        return (*this);
183
191
    }
205
213
 
206
214
private:
207
215
 
208
 
    liblas::LASWriter* m_writer;
 
216
    liblas::Writer* m_writer;
 
217
};
 
218
 
 
219
template <typename T>
 
220
class index_filter_iterator
 
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
 
 
230
    /// Initializes iterator pointing to pass-the-end.
 
231
    index_filter_iterator()
 
232
        : m_index(0)
 
233
    {}
 
234
 
 
235
    /// Initializes iterator pointing to beginning of Index's filtered points sequence.
 
236
    /// No ownership transfer of index object occurs.
 
237
    index_filter_iterator(liblas::Index& index)
 
238
        : m_index(&index)
 
239
    {
 
240
        assert(0 != m_index);
 
241
        getval();
 
242
    }
 
243
 
 
244
    /// Dereference operator.
 
245
    /// It is implemented in terms of Index::GetNextID function.
 
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
 
 
257
    /// Pointer-to-member operator.
 
258
    /// It is implemented in terms of Index::GetPoint function.
 
259
    pointer operator->() const
 
260
    {
 
261
        return &(operator*());
 
262
    }
 
263
 
 
264
    /// Pre-increment operator.
 
265
    /// Moves iterator to next record by calling Index::GetNextID.
 
266
    index_filter_iterator& operator++()
 
267
    {
 
268
        assert(0 != m_index);
 
269
        getval();
 
270
        return (*this);
 
271
    }
 
272
 
 
273
    /// Post-increment operator.
 
274
    /// Moves iterator to next record by calling Index::FindNextID.
 
275
    index_filter_iterator operator++(int)
 
276
    {
 
277
        index_filter_iterator tmp(*this);
 
278
        ++(*this);
 
279
        return tmp;
 
280
    }
 
281
 
 
282
    /// Compare passed iterator to this.
 
283
    /// Determine if both iterators apply to the same instance of liblas::Index class.
 
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;
209
300
};
210
301
 
211
302
// Declare specializations for user's convenience
212
303
 
213
304
/// Public specialization of LASReader input iterator for liblas::LASPoint type.
214
 
typedef reader_iterator<LASPoint> lasreader_iterator;
 
305
typedef reader_iterator<Point> lasreader_iterator;
215
306
 
216
307
/// Public specialization of LASWriter output iterator for liblas::LASPoint type.
217
 
typedef writer_iterator<LASPoint> laswriter_iterator;
 
308
typedef writer_iterator<Point> laswriter_iterator;
 
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
218
315
 
219
316
} // namespace liblas
220
317