1
/******************************************************************************
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
8
******************************************************************************
9
* Copyright (c) 2010, Howard Butler
11
* All rights reserved.
13
* Redistribution and use in source and binary forms, with or without
14
* modification, are permitted provided that the following
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.
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
40
****************************************************************************/
42
#ifndef LIBLAS_SCHEMA_HPP_INCLUDED
43
#define LIBLAS_SCHEMA_HPP_INCLUDED
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>
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>
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>
73
#include <boost/unordered_map.hpp>
77
typedef std::vector<Dimension> DimensionArray;
84
typedef boost::multi_index::multi_index_container<
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> >,
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> >
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;
102
/// Schema definition
108
Schema(PointFormatName data_format_id);
109
Schema(std::vector<VariableRecord> const& vlrs);
110
Schema& operator=(Schema const& rhs);
112
bool operator==(const Schema& other) const;
113
bool operator!=(const Schema& other) const { return !(*this == other); }
115
Schema(Schema const& other);
120
std::size_t GetByteSize() const;
122
std::size_t GetBitSize() const;
123
void CalculateSizes();
125
/// Get the base size (only accounting for Time, Color, etc )
126
std::size_t GetBaseByteSize() const;
128
PointFormatName GetDataFormatId() const { return m_data_format_id; }
129
void SetDataFormatId(PointFormatName const& value);
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;
135
// DimensionPtr GetDimension(std::size_t index) const;
136
void RemoveDimension(Dimension const& dim);
138
void SetDimension(Dimension const& dim);
140
std::vector<std::string> GetDimensionNames() const;
141
IndexMap const& GetDimensions() const { return m_index; }
142
liblas::property_tree::ptree GetPTree() const;
144
boost::uint16_t GetSchemaVersion() const { return m_schemaversion; }
145
void SetSchemaVersion(boost::uint16_t v) { m_schemaversion = v; }
147
bool IsCustom() const;
148
VariableRecord GetVLR() const;
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;
162
void add_record0_dimensions();
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);
172
bool inline sort_dimensions(Dimension i, Dimension j)
177
LAS_DLL std::ostream& operator<<(std::ostream& os, liblas::Schema const&);
180
} // namespace liblas
182
#endif // LIBLAS_SCHEMA_HPP_INCLUDED