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

« back to all changes in this revision

Viewing changes to include/liblas/schema.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:
 
1
/******************************************************************************
 
2
 * $Id$
 
3
 *
 
4
 * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
 
5
 * Purpose:  LAS Schema implementation for C++ libLAS 
 
6
 * Author:   Howard Butler, hobu.inc@gmail.com
 
7
 *
 
8
 ******************************************************************************
 
9
 * Copyright (c) 2010, Howard Butler
 
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_SCHEMA_HPP_INCLUDED
 
43
#define LIBLAS_SCHEMA_HPP_INCLUDED
 
44
 
 
45
#include <liblas/version.hpp>
 
46
#include <liblas/external/property_tree/ptree.hpp>
 
47
#include <liblas/variablerecord.hpp>
 
48
#include <liblas/dimension.hpp>
 
49
#include <liblas/export.hpp>
 
50
 
 
51
// boost
 
52
#include <boost/cstdint.hpp>
 
53
#include <boost/any.hpp>
 
54
#include <boost/shared_ptr.hpp>
 
55
#include <boost/foreach.hpp>
 
56
#include <boost/array.hpp>
 
57
#include <boost/optional.hpp>
 
58
 
 
59
#include <boost/multi_index_container.hpp>
 
60
#include <boost/multi_index/member.hpp>
 
61
#include <boost/multi_index/ordered_index.hpp>
 
62
#include <boost/multi_index/hashed_index.hpp>
 
63
#include <boost/multi_index/sequenced_index.hpp>
 
64
#include <boost/multi_index/mem_fun.hpp>
 
65
#include <boost/multi_index/random_access_index.hpp>
 
66
 
 
67
// std
 
68
#include <iosfwd>
 
69
#include <limits>
 
70
#include <string>
 
71
#include <vector>
 
72
#include <algorithm>
 
73
#include <boost/unordered_map.hpp>
 
74
 
 
75
namespace liblas {  
 
76
 
 
77
typedef std::vector<Dimension> DimensionArray;
 
78
 
 
79
struct name{};
 
80
struct position{};
 
81
struct index{};
 
82
 
 
83
 
 
84
typedef boost::multi_index::multi_index_container<
 
85
  Dimension,
 
86
  boost::multi_index::indexed_by<
 
87
    // sort by Dimension::operator<
 
88
    boost::multi_index::ordered_unique<boost::multi_index::tag<position>, boost::multi_index::identity<Dimension> >,
 
89
    
 
90
    // Random access
 
91
    boost::multi_index::random_access<boost::multi_index::tag<index> >,
 
92
    // sort by less<string> on GetName
 
93
    boost::multi_index::hashed_unique<boost::multi_index::tag<name>, boost::multi_index::const_mem_fun<Dimension,std::string const&,&Dimension::GetName> >
 
94
      >
 
95
> IndexMap;
 
96
 
 
97
typedef IndexMap::index<name>::type index_by_name;
 
98
typedef IndexMap::index<position>::type index_by_position;
 
99
typedef IndexMap::index<index>::type index_by_index;
 
100
 
 
101
 
 
102
/// Schema definition
 
103
class LAS_DLL Schema
 
104
{
 
105
public:
 
106
    
 
107
    // Schema();
 
108
    Schema(PointFormatName data_format_id);
 
109
    Schema(std::vector<VariableRecord> const& vlrs);
 
110
    Schema& operator=(Schema const& rhs);
 
111
 
 
112
    bool operator==(const Schema& other) const;
 
113
    bool operator!=(const Schema& other) const { return !(*this == other); }
 
114
        
 
115
    Schema(Schema const& other);
 
116
    
 
117
    ~Schema() {}
 
118
 
 
119
    /// Fetch byte size
 
120
    std::size_t GetByteSize() const;
 
121
 
 
122
    std::size_t GetBitSize() const;
 
123
    void CalculateSizes();
 
124
 
 
125
    /// Get the base size (only accounting for Time, Color, etc )
 
126
    std::size_t GetBaseByteSize() const;
 
127
 
 
128
    PointFormatName GetDataFormatId() const { return m_data_format_id; }
 
129
    void SetDataFormatId(PointFormatName const& value);
 
130
    
 
131
    void AddDimension(Dimension const& dim);
 
132
    boost::optional< Dimension const& > GetDimension(std::string const& n) const;
 
133
    boost::optional< Dimension const& > GetDimension(index_by_index::size_type t) const;
 
134
    
 
135
    // DimensionPtr GetDimension(std::size_t index) const;
 
136
    void RemoveDimension(Dimension const& dim);
 
137
    
 
138
    void SetDimension(Dimension const& dim);
 
139
    
 
140
    std::vector<std::string> GetDimensionNames() const;
 
141
    IndexMap const& GetDimensions() const { return m_index; }
 
142
    liblas::property_tree::ptree GetPTree() const;
 
143
    
 
144
    boost::uint16_t GetSchemaVersion() const { return m_schemaversion; }
 
145
    void SetSchemaVersion(boost::uint16_t v) { m_schemaversion = v; }
 
146
    
 
147
    bool IsCustom() const;
 
148
    VariableRecord GetVLR() const;
 
149
 
 
150
protected:
 
151
    
 
152
    PointFormatName m_data_format_id;
 
153
    boost::uint32_t m_nextpos;
 
154
    std::size_t m_bit_size;
 
155
    std::size_t m_base_bit_size;
 
156
    boost::uint16_t m_schemaversion;
 
157
    
 
158
private:
 
159
 
 
160
    IndexMap m_index;
 
161
    
 
162
    void add_record0_dimensions();
 
163
    void add_time();
 
164
    void add_color();
 
165
    void update_required_dimensions(PointFormatName data_format_id);
 
166
    bool IsSchemaVLR(VariableRecord const& vlr);
 
167
    liblas::property_tree::ptree LoadPTree(VariableRecord const& v);
 
168
    IndexMap LoadDimensions(liblas::property_tree::ptree tree);
 
169
 
 
170
};
 
171
 
 
172
bool inline sort_dimensions(Dimension i, Dimension j) 
 
173
 
174
    return i < j; 
 
175
}
 
176
 
 
177
LAS_DLL std::ostream& operator<<(std::ostream& os, liblas::Schema const&);
 
178
 
 
179
 
 
180
} // namespace liblas
 
181
 
 
182
#endif // LIBLAS_SCHEMA_HPP_INCLUDED