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

« back to all changes in this revision

Viewing changes to src/reader.cpp

  • 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:
 
1
/******************************************************************************
 
2
 * $Id$
 
3
 *
 
4
 * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
 
5
 * Purpose:  LAS reader class 
 
6
 * Author:   Mateusz Loskot, mateusz@loskot.net
 
7
 *
 
8
 ******************************************************************************
 
9
 * Copyright (c) 2008, Mateusz Loskot
 
10
 * Copyright (c) 2008, Phil Vachon
 
11
 *
 
12
 * All rights reserved.
 
13
 * 
 
14
 * Redistribution and use in source and binary forms, with or without 
 
15
 * modification, are permitted provided that the following 
 
16
 * conditions are met:
 
17
 * 
 
18
 *     * Redistributions of source code must retain the above copyright 
 
19
 *       notice, this list of conditions and the following disclaimer.
 
20
 *     * Redistributions in binary form must reproduce the above copyright 
 
21
 *       notice, this list of conditions and the following disclaimer in 
 
22
 *       the documentation and/or other materials provided 
 
23
 *       with the distribution.
 
24
 *     * Neither the name of the Martin Isenburg or Iowa Department 
 
25
 *       of Natural Resources nor the names of its contributors may be 
 
26
 *       used to endorse or promote products derived from this software 
 
27
 *       without specific prior written permission.
 
28
 * 
 
29
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 
30
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 
31
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 
32
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 
33
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 
34
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 
35
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
 
36
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 
37
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
 
38
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
 
39
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
 
40
 * OF SUCH DAMAGE.
 
41
 ****************************************************************************/
 
42
 
 
43
#include <liblas/version.hpp>
 
44
#include <liblas/reader.hpp>
 
45
#include <liblas/detail/reader/reader.hpp>
 
46
#include <liblas/detail/reader/cachedreader.hpp>
 
47
#include <liblas/utility.hpp>
 
48
 
 
49
// boost
 
50
#include <boost/cstdint.hpp>
 
51
 
 
52
// std
 
53
#include <stdexcept>
 
54
#include <fstream>
 
55
#include <string>
 
56
#include <cstring> // std::memset
 
57
#include <cassert>
 
58
#include <iostream>
 
59
 
 
60
using namespace boost;
 
61
 
 
62
namespace liblas
 
63
{
 
64
 
 
65
Reader::Reader(std::istream& ifs) :
 
66
    m_pimpl(new detail::ReaderImpl(ifs))
 
67
{
 
68
    Init();
 
69
}
 
70
 
 
71
 
 
72
Reader::Reader(ReaderIPtr reader) :
 
73
    m_pimpl(reader)
 
74
{
 
75
    Init();
 
76
}
 
77
 
 
78
Reader::Reader(Reader const& other) 
 
79
    : m_pimpl(other.m_pimpl)
 
80
{
 
81
}
 
82
 
 
83
Reader& Reader::operator=(Reader const& rhs)
 
84
{
 
85
    if (&rhs != this)
 
86
    {
 
87
        m_pimpl = rhs.m_pimpl;
 
88
    }
 
89
    return *this;
 
90
}
 
91
 
 
92
Reader::~Reader()
 
93
{
 
94
 
 
95
}
 
96
 
 
97
Header const& Reader::GetHeader() const
 
98
{
 
99
    return m_pimpl->GetHeader();
 
100
}
 
101
 
 
102
void Reader::SetHeader(Header const& header)
 
103
{
 
104
    m_pimpl->SetHeader(header);
 
105
}
 
106
 
 
107
Point const& Reader::GetPoint() const
 
108
{
 
109
    return m_pimpl->GetPoint();
 
110
}
 
111
 
 
112
bool Reader::ReadNextPoint()
 
113
{  
 
114
    try
 
115
    {
 
116
        m_pimpl->ReadNextPoint();
 
117
        return true;
 
118
    }
 
119
    catch (std::out_of_range const&)
 
120
    {
 
121
    }
 
122
 
 
123
    return false;
 
124
}
 
125
 
 
126
bool Reader::ReadPointAt(std::size_t n)
 
127
{
 
128
    if (m_pimpl->GetHeader().GetPointRecordsCount() <= n)
 
129
    {
 
130
        throw std::out_of_range("point subscript out of range");
 
131
    }
 
132
    
 
133
    try
 
134
    {
 
135
        m_pimpl->ReadPointAt(n);
 
136
        return true;
 
137
    }
 
138
    catch (std::out_of_range const&)
 
139
    {
 
140
    }
 
141
    return false;
 
142
}
 
143
 
 
144
bool Reader::Seek(std::size_t n)
 
145
{
 
146
    try
 
147
    {
 
148
        assert(n < m_pimpl->GetHeader().GetPointRecordsCount());
 
149
 
 
150
        m_pimpl->Seek(n);
 
151
        return true;
 
152
    }
 
153
    catch (std::out_of_range const&)
 
154
    {
 
155
    }
 
156
    return false;
 
157
}
 
158
 
 
159
Point const& Reader::operator[](std::size_t n)
 
160
{
 
161
    if (m_pimpl->GetHeader().GetPointRecordsCount() <= n)
 
162
    {
 
163
        throw std::out_of_range("point subscript out of range");
 
164
    }
 
165
    
 
166
    bool read = ReadPointAt(n);
 
167
 
 
168
    if (read == false) 
 
169
    {
 
170
        throw std::out_of_range("no point record at given position");
 
171
    }
 
172
 
 
173
    return m_pimpl->GetPoint();
 
174
}
 
175
 
 
176
void Reader::Init()
 
177
{   
 
178
    m_pimpl->ReadHeader();
 
179
}
 
180
 
 
181
void Reader::Reset() 
 
182
{
 
183
    Init();
 
184
}
 
185
 
 
186
void Reader::SetFilters(std::vector<liblas::FilterPtr> const& filters)
 
187
{
 
188
    m_pimpl->SetFilters(filters);
 
189
}
 
190
 
 
191
std::vector<liblas::FilterPtr>  Reader::GetFilters() const
 
192
{
 
193
    return m_pimpl->GetFilters();
 
194
}
 
195
 
 
196
void Reader::SetTransforms(std::vector<liblas::TransformPtr> const& transforms)
 
197
{
 
198
    m_pimpl->SetTransforms(transforms);
 
199
}
 
200
 
 
201
std::vector<liblas::TransformPtr>  Reader::GetTransforms() const
 
202
{
 
203
    return m_pimpl->GetTransforms();
 
204
}
 
205
 
 
206
} // namespace liblas
 
207