libLAS API Reference  1.8.1
schema.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: 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>
48 #include <liblas/dimension.hpp>
49 #include <liblas/export.hpp>
50 
51 // boost
52 #include <boost/any.hpp>
53 #include <boost/shared_ptr.hpp>
54 #include <boost/foreach.hpp>
55 #include <boost/array.hpp>
56 #include <boost/optional.hpp>
57 
58 #include <boost/multi_index_container.hpp>
59 #include <boost/multi_index/member.hpp>
60 #include <boost/multi_index/ordered_index.hpp>
61 #include <boost/multi_index/hashed_index.hpp>
62 #include <boost/multi_index/sequenced_index.hpp>
63 #include <boost/multi_index/mem_fun.hpp>
64 #include <boost/multi_index/random_access_index.hpp>
65 
66 // std
67 #include <iosfwd>
68 #include <limits>
69 #include <string>
70 #include <vector>
71 #include <algorithm>
72 #include <boost/unordered_map.hpp>
73 
74 namespace liblas {
75 
76 typedef std::vector<Dimension> DimensionArray;
77 
78 struct name{};
79 struct position{};
80 struct index{};
81 
82 
83 typedef boost::multi_index::multi_index_container<
84  Dimension,
85  boost::multi_index::indexed_by<
86  // sort by Dimension::operator<
87  boost::multi_index::ordered_unique<boost::multi_index::tag<position>, boost::multi_index::identity<Dimension> >,
88 
89  // Random access
90  boost::multi_index::random_access<boost::multi_index::tag<index> >,
91  // sort by less<string> on GetName
92  boost::multi_index::hashed_unique<boost::multi_index::tag<name>, boost::multi_index::const_mem_fun<Dimension,std::string const&,&Dimension::GetName> >
93  >
95 
96 typedef IndexMap::index<name>::type index_by_name;
97 typedef IndexMap::index<position>::type index_by_position;
98 typedef IndexMap::index<index>::type index_by_index;
99 
100 
103 {
104 public:
105 
106  // Schema();
107  Schema(PointFormatName data_format_id);
108  Schema(std::vector<VariableRecord> const& vlrs);
109  Schema& operator=(Schema const& rhs);
110 
111  bool operator==(const Schema& other) const;
112  bool operator!=(const Schema& other) const { return !(*this == other); }
113 
114  Schema(Schema const& other);
115 
116  ~Schema() {}
117 
119  std::size_t GetByteSize() const;
120 
121  std::size_t GetBitSize() const;
122  void CalculateSizes();
123 
125  std::size_t GetBaseByteSize() const;
126 
127  PointFormatName GetDataFormatId() const { return m_data_format_id; }
128  void SetDataFormatId(PointFormatName const& value);
129 
130  void AddDimension(Dimension const& dim);
131  boost::optional< Dimension const& > GetDimension(std::string const& n) const;
132  boost::optional< Dimension const& > GetDimension(index_by_index::size_type t) const;
133 
134  // DimensionPtr GetDimension(std::size_t index) const;
135  void RemoveDimension(Dimension const& dim);
136 
137  void SetDimension(Dimension const& dim);
138 
139  std::vector<std::string> GetDimensionNames() const;
140  IndexMap const& GetDimensions() const { return m_index; }
141  liblas::property_tree::ptree GetPTree() const;
142 
143  uint16_t GetSchemaVersion() const { return m_schemaversion; }
144  void SetSchemaVersion(uint16_t v) { m_schemaversion = v; }
145 
146  bool IsCustom() const;
147  VariableRecord GetVLR() const;
148 
149 protected:
150 
152  uint32_t m_nextpos;
153  std::size_t m_bit_size;
154  std::size_t m_base_bit_size;
155  uint16_t m_schemaversion;
156 
157 private:
158 
159  IndexMap m_index;
160 
161  void add_record0_dimensions();
162  void add_time();
163  void add_color();
164  void update_required_dimensions(PointFormatName data_format_id);
165  bool IsSchemaVLR(VariableRecord const& vlr);
166  liblas::property_tree::ptree LoadPTree(VariableRecord const& v);
167  IndexMap LoadDimensions(liblas::property_tree::ptree tree);
168 
169 };
170 
171 bool inline sort_dimensions(Dimension i, Dimension j)
172 {
173  return i < j;
174 }
175 
176 LAS_DLL std::ostream& operator<<(std::ostream& os, liblas::Schema const&);
177 
178 
179 } // namespace liblas
180 
181 #endif // LIBLAS_SCHEMA_HPP_INCLUDED
std::size_t m_base_bit_size
Definition: schema.hpp:154
bool sort_dimensions(Dimension i, Dimension j)
Definition: schema.hpp:171
IndexMap const & GetDimensions() const
Definition: schema.hpp:140
Representation of variable-length record data.
Definition: variablerecord.hpp:59
#define LAS_DLL
Definition: export.hpp:58
std::ostream & operator<<(std::ostream &os, Classification const &cls)
The output stream operator is based on std::bitset<N>::operator<<.
Definition: classification.hpp:247
PointFormatName GetDataFormatId() const
Definition: schema.hpp:127
PointFormatName m_data_format_id
Definition: schema.hpp:151
uint16_t GetSchemaVersion() const
Definition: schema.hpp:143
void SetSchemaVersion(uint16_t v)
Definition: schema.hpp:144
IndexMap::index< position >::type index_by_position
Definition: schema.hpp:97
Definition: schema.hpp:79
IndexMap::index< index >::type index_by_index
Definition: schema.hpp:98
bool operator!=(const Schema &other) const
Definition: schema.hpp:112
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
PointFormatName
Versions of point record format.
Definition: version.hpp:89
uint32_t m_nextpos
Definition: schema.hpp:152
uint16_t m_schemaversion
Definition: schema.hpp:155
IndexMap::index< name >::type index_by_name
Definition: schema.hpp:96
Definition: schema.hpp:78
std::vector< Dimension > DimensionArray
Definition: schema.hpp:76
Definition: schema.hpp:80
std::size_t m_bit_size
Definition: schema.hpp:153
boost::multi_index::multi_index_container< Dimension, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< position >, boost::multi_index::identity< Dimension > >, boost::multi_index::random_access< boost::multi_index::tag< index > >, boost::multi_index::hashed_unique< boost::multi_index::tag< name >, boost::multi_index::const_mem_fun< Dimension, std::string const &,&Dimension::GetName > > >> IndexMap
Definition: schema.hpp:94
Schema definition.
Definition: schema.hpp:102
Dimension definition.
Definition: dimension.hpp:73
~Schema()
Definition: schema.hpp:116