ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
SectionHeaders.cpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright 2009 - 2010 Kevin Ackley (kackley@gwi.net)
3  * Modified work Copyright 2018 - 2020 Andy Maloney <asmaloney@gmail.com>
4  *
5  * Permission is hereby granted, free of charge, to any person or organization
6  * obtaining a copy of the software and accompanying documentation covered by
7  * this license (the "Software") to use, reproduce, display, distribute,
8  * execute, and transmit the Software, and to prepare derivative works of the
9  * Software, and to permit third-parties to whom the Software is furnished to
10  * do so, all subject to the following:
11  *
12  * The copyright notices in the Software and this entire statement, including
13  * the above license grant, this restriction and the following disclaimer,
14  * must be included in all copies of the Software, in whole or in part, and
15  * all derivative works of the Software, unless such copies or derivative
16  * works are solely in the form of machine-executable object code generated by
17  * a source language processor.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  * DEALINGS IN THE SOFTWARE.
26  */
27 
28 #include "SectionHeaders.h"
29 
30 namespace e57
31 {
32 #ifdef E57_DEBUG
33  void BlobSectionHeader::dump( int indent, std::ostream &os )
34  {
35  os << space( indent ) << "sectionId: " << sectionId << std::endl;
36  os << space( indent ) << "sectionLogicalLength: " << sectionLogicalLength << std::endl;
37  }
38 #endif
39 
41  {
44  static_assert( sizeof( CompressedVectorSectionHeader ) == 32,
45  "Unexpected size of CompressedVectorSectionHeader" );
46  }
47 
48  void CompressedVectorSectionHeader::verify( uint64_t filePhysicalSize )
49  {
51  for ( unsigned i = 0; i < sizeof( reserved1 ); i++ )
52  {
53  if ( reserved1[i] != 0 )
54  {
56  "i=" + toString( i ) + " reserved=" + toString( reserved1[i] ) );
57  }
58  }
59 
61  if ( sectionLogicalLength % 4 )
62  {
63  throw E57_EXCEPTION2( E57_ERROR_BAD_CV_HEADER, "sectionLogicalLength=" + toString( sectionLogicalLength ) );
64  }
65 
67  if ( filePhysicalSize > 0 && sectionLogicalLength >= filePhysicalSize )
68  {
69  throw E57_EXCEPTION2( E57_ERROR_BAD_CV_HEADER, "sectionLogicalLength=" + toString( sectionLogicalLength ) +
70  " filePhysicalSize=" + toString( filePhysicalSize ) );
71  }
72 
74  if ( filePhysicalSize > 0 && dataPhysicalOffset >= filePhysicalSize )
75  {
76  throw E57_EXCEPTION2( E57_ERROR_BAD_CV_HEADER, "dataPhysicalOffset=" + toString( dataPhysicalOffset ) +
77  " filePhysicalSize=" + toString( filePhysicalSize ) );
78  }
79 
81  if ( filePhysicalSize > 0 && indexPhysicalOffset >= filePhysicalSize )
82  {
83  throw E57_EXCEPTION2( E57_ERROR_BAD_CV_HEADER, "indexPhysicalOffset=" + toString( indexPhysicalOffset ) +
84  " filePhysicalSize=" + toString( filePhysicalSize ) );
85  }
86  }
87 
88 #ifdef E57_DEBUG
89  void CompressedVectorSectionHeader::dump( int indent, std::ostream &os ) const
90  {
91  os << space( indent ) << "sectionId: " << static_cast<unsigned>( sectionId ) << std::endl;
92  os << space( indent ) << "sectionLogicalLength: " << sectionLogicalLength << std::endl;
93  os << space( indent ) << "dataPhysicalOffset: " << dataPhysicalOffset << std::endl;
94  os << space( indent ) << "indexPhysicalOffset: " << indexPhysicalOffset << std::endl;
95  }
96 #endif
97 }
#define E57_EXCEPTION2(ecode, context)
Definition: Common.h:68
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
@ E57_ERROR_BAD_CV_HEADER
a CompressedVector binary header was bad
Definition: E57Exception.h:44
std::string toString(T x)
Definition: Common.h:80
std::string space(size_t n)
Definition: Common.h:73
const uint8_t sectionId
void dump(int indent=0, std::ostream &os=std::cout)
void verify(uint64_t filePhysicalSize=0)
void dump(int indent=0, std::ostream &os=std::cout) const