MCPcopy Create free account
hub / github.com/PDAL/PDAL / readFileHeader

Method readFileHeader

plugins/e57/libE57Format/src/ImageFileImpl.cpp:882–934  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

880#endif
881
882 void ImageFileImpl::readFileHeader( CheckedFile *file, E57FileHeader &header )
883 {
884 // Double check that compiler thinks sizeof header is what it is supposed to be
885 static_assert( sizeof( E57FileHeader ) == 48, "Unexpected size of E57FileHeader" );
886
887 // Fetch the file header
888 file->read( reinterpret_cast<char *>( &header ), sizeof( header ) );
889
890#ifdef E57_VERBOSE
891 header.dump();
892#endif
893
894 // Check signature
895 if ( strncmp( header.fileSignature, "ASTM-E57", 8 ) != 0 )
896 {
897 throw E57_EXCEPTION2( ErrorBadFileSignature, "fileName=" + file->fileName() );
898 }
899
900 // Check file version compatibility
901 if ( header.majorVersion > E57_FORMAT_MAJOR )
902 {
903 throw E57_EXCEPTION2( ErrorUnknownFileVersion,
904 "fileName=" + file->fileName() +
905 " header.majorVersion=" + toString( header.majorVersion ) +
906 " header.minorVersion=" + toString( header.minorVersion ) );
907 }
908
909 // If is a prototype version (majorVersion==0), then minorVersion has to match too. In
910 // production versions (majorVersion==E57_FORMAT_MAJOR), should be able to handle any minor
911 // version.
912 if ( header.majorVersion == E57_FORMAT_MAJOR && header.minorVersion > E57_FORMAT_MINOR )
913 {
914 throw E57_EXCEPTION2( ErrorUnknownFileVersion,
915 "fileName=" + file->fileName() +
916 " header.majorVersion=" + toString( header.majorVersion ) +
917 " header.minorVersion=" + toString( header.minorVersion ) );
918 }
919
920 // Check if file length matches actual physical length
921 if ( header.filePhysicalLength != file->length( CheckedFile::Physical ) )
922 {
923 throw E57_EXCEPTION2( ErrorBadFileLength,
924 "fileName=" + file->fileName() + " header.filePhysicalLength=" +
925 toString( header.filePhysicalLength ) + " file->length=" +
926 toString( file->length( CheckedFile::Physical ) ) );
927 }
928
929 // Check that page size is correct constant
930 if ( header.majorVersion != 0 && header.pageSize != CheckedFile::physicalPageSize )
931 {
932 throw E57_EXCEPTION2( ErrorBadFileLength, "fileName=" + file->fileName() );
933 }
934 }
935
936 void ImageFileImpl::checkImageFileOpen( const char *srcFileName, int srcLineNumber,
937 const char *srcFunctionName ) const

Callers

nothing calls this directly

Calls 5

toStringFunction · 0.70
readMethod · 0.45
dumpMethod · 0.45
fileNameMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected