58 void dump(
int indent = 0, std::ostream &os = std::cout )
const;
65 os <<
space( indent ) <<
"fileSignature: ";
78 isWriter_( false ), writerCount_( 0 ), readerCount_( 0 ),
79 checksumPolicy(
std::
max( 0,
std::
min( policy, 100 ) ) ), file_( nullptr ), xmlLogicalOffset_( 0 ),
80 xmlLogicalLength_( 0 ), unusedLogicalStart_( 0 )
90 #ifdef E57_MAX_VERBOSE
91 std::cout <<
"ImageFileImpl() called, fileName=" <<
fileName <<
" mode=" << mode <<
std::endl;
100 isWriter_ = ( mode ==
"w" );
102 if ( !isWriter_ && ( mode !=
"r" ) )
119 root_->setAttachedRecursive();
122 xmlLogicalOffset_ = 0;
123 xmlLogicalLength_ = 0;
144 root_->setAttachedRecursive();
147 readFileHeader( file_, header );
173 parser.
parse( xmlSection );
188 #ifdef E57_MAX_VERBOSE
189 std::cout <<
"ImageFileImpl() called, fileName=<StreamBuffer> mode=r" <<
std::endl;
192 fileName_ =
"<StreamBuffer>";
207 root_->setAttachedRecursive();
210 readFileHeader( file_, header );
236 parser.
parse( xmlSection );
256 if ( writerCount_ < 0 )
259 " writerCount=" +
toString( writerCount_ ) +
260 " readerCount=" +
toString( readerCount_ ) );
274 if ( readerCount_ < 0 )
277 " writerCount=" +
toString( writerCount_ ) +
278 " readerCount=" +
toString( readerCount_ ) );
285 checkImageFileOpen( __FILE__, __LINE__,
static_cast<const char *
>( __FUNCTION__ ) );
293 if ( file_ ==
nullptr )
301 xmlLogicalOffset_ = unusedLogicalStart_;
304 *file_ <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
305 #ifdef E57_OXYGEN_SUPPORT
312 root_->writeXml( shared_from_this(), *file_, 0,
"e57Root" );
334 #ifdef E57_MAX_VERBOSE
340 file_->
write(
reinterpret_cast<char *
>( &header ),
sizeof( header ) );
352 if ( file_ ==
nullptr )
374 return ( file_ !=
nullptr );
412 uint64_t oldLogicalStart = unusedLogicalStart_;
415 unusedLogicalStart_ += byteCount;
421 file_->
extend( unusedLogicalStart_ );
424 return oldLogicalStart;
440 checkImageFileOpen( __FILE__, __LINE__,
static_cast<const char *
>( __FUNCTION__ ) );
459 nameSpaces_.emplace_back( prefix, uri );
464 checkImageFileOpen( __FILE__, __LINE__,
static_cast<const char *
>( __FUNCTION__ ) );
467 std::vector<NameSpace>::const_iterator it;
469 for ( it = nameSpaces_.begin(); it < nameSpaces_.end(); ++it )
471 if ( it->prefix == prefix )
483 checkImageFileOpen( __FILE__, __LINE__,
static_cast<const char *
>( __FUNCTION__ ) );
486 std::vector<NameSpace>::const_iterator it;
488 for ( it = nameSpaces_.begin(); it < nameSpaces_.end(); ++it )
490 if ( it->uri == uri )
502 checkImageFileOpen( __FILE__, __LINE__,
static_cast<const char *
>( __FUNCTION__ ) );
504 return nameSpaces_.size();
509 checkImageFileOpen( __FILE__, __LINE__,
static_cast<const char *
>( __FUNCTION__ ) );
511 return nameSpaces_[index].prefix;
516 checkImageFileOpen( __FILE__, __LINE__,
static_cast<const char *
>( __FUNCTION__ ) );
518 return nameSpaces_[index].uri;
526 size_t found = elementName.find_first_of(
'/' );
528 if ( found != std::string::npos )
546 return ( prefix.length() > 0 );
551 #ifdef E57_MAX_VERBOSE
557 checkImageFileOpen( __FILE__, __LINE__,
static_cast<const char *
>( __FUNCTION__ ) );
573 #ifdef E57_MAX_VERBOSE
578 checkImageFileOpen( __FILE__, __LINE__,
static_cast<const char *
>( __FUNCTION__ ) );
618 size_t len = elementName.length();
626 unsigned char c = elementName[0];
629 if ( allowNumber &&
'0' <= c && c <=
'9' )
632 for (
size_t i = 1; i < len; i++ )
636 if ( !(
'0' <= c && c <=
'9' ) )
648 if ( c < 128 && !( (
'a' <= c && c <=
'z' ) || (
'A' <= c && c <=
'Z' ) || c ==
'_' ) )
655 for (
size_t i = 1; i < len; i++ )
659 if ( c < 128 && !( (
'a' <= c && c <=
'z' ) || (
'A' <= c && c <=
'Z' ) || c ==
'_' || c ==
':' ||
660 (
'0' <= c && c <=
'9' ) || c ==
'-' || c ==
'.' ) )
667 size_t found = elementName.find_first_of(
':' );
669 if ( found != std::string::npos )
672 if ( elementName.find_first_of(
':', found + 1 ) != std::string::npos )
679 prefix = elementName.substr( 0, found );
680 localPart = elementName.substr( found + 1 );
682 if ( prefix.length() == 0 || localPart.length() == 0 )
685 "elementName=" + elementName +
" prefix=" + prefix +
" localPart=" + localPart );
691 localPart = elementName;
700 bool isRelative =
false;
708 #ifdef E57_MAX_VERBOSE
709 std::cout <<
"pathNameParse pathname="
724 if ( pathName[start] ==
'/' )
736 while ( start < pathName.size() )
738 size_t slash = pathName.find_first_of(
'/', start );
741 ustring elementName = pathName.substr( start, slash - start );
749 fields.push_back( elementName );
751 if ( slash == std::string::npos )
758 if ( slash == pathName.size() - 1 )
760 fields.emplace_back(
"" );
769 if ( isRelative &&
fields.empty() )
774 #ifdef E57_MAX_VERBOSE
775 std::cout <<
"pathNameParse returning: isRelative=" << isRelative <<
" fields.size()=" <<
fields.size()
777 for (
size_t i = 0; i <
fields.size(); i++ )
779 std::cout <<
fields[i] <<
",";
791 path.push_back(
'/' );
794 for (
unsigned i = 0; i <
fields.size(); ++i )
798 if ( i <
fields.size() - 1 )
800 path.push_back(
'/' );
811 static_assert(
sizeof(
E57FileHeader ) == 48,
"Unexpected size of E57FileHeader" );
814 file->
read(
reinterpret_cast<char *
>( &header ),
sizeof( header ) );
816 #ifdef E57_MAX_VERBOSE
862 void ImageFileImpl::checkImageFileOpen(
const char *srcFileName,
int srcLineNumber,
863 const char *srcFunctionName )
const
876 os <<
space( indent ) <<
"writerCount: " << writerCount_ <<
std::endl;
877 os <<
space( indent ) <<
"readerCount: " << readerCount_ <<
std::endl;
885 root_->dump( indent + 2, os );
896 uint64_t stateCountMinus1 = maximum - minimum;
900 if ( stateCountMinus1 & 0xFFFFFFFF00000000LL )
902 stateCountMinus1 >>= 32;
906 if ( stateCountMinus1 & 0xFFFF0000LL )
908 stateCountMinus1 >>= 16;
912 if ( stateCountMinus1 & 0xFF00LL )
914 stateCountMinus1 >>= 8;
918 if ( stateCountMinus1 & 0xF0LL )
920 stateCountMinus1 >>= 4;
924 if ( stateCountMinus1 & 0xCLL )
926 stateCountMinus1 >>= 2;
930 if ( stateCountMinus1 & 0x2LL )
932 stateCountMinus1 >>= 1;
936 if ( stateCountMinus1 & 1LL )
std::vector< PCLPointField > fields
void write(const char *buf, size_t nWrite)
static constexpr size_t physicalPageSize
void read(char *buf, size_t nRead, size_t bufSize=0)
void extend(uint64_t newLength, OffsetMode omode=Logical)
uint64_t position(OffsetMode omode=Logical)
static uint64_t physicalToLogical(uint64_t physicalOffset)
e57::ustring fileName() const
uint64_t length(OffsetMode omode=Logical)
void seek(uint64_t offset, OffsetMode omode=Logical)
Object thrown by E57 API functions to communicate the conditions of an error.
void parse(InputSource &inputSource)
ImageFileImpl(ReadChecksumPolicy policy)
std::shared_ptr< StructureNodeImpl > root()
bool isElementNameLegal(const ustring &elementName, bool allowNumber=true)
CheckedFile * file() const
void dump(int indent=0, std::ostream &os=std::cout) const
Diagnostic functions:
void extensionsAdd(const ustring &prefix, const ustring &uri)
Manipulate registered extensions in the file.
unsigned bitsNeeded(int64_t minimum, int64_t maximum)
size_t extensionsCount() const
void checkElementNameLegal(const ustring &elementName, bool allowNumber=true)
bool extensionsLookupUri(const ustring &uri, ustring &prefix) const
void construct2(const ustring &fileName, const ustring &mode)
ustring pathNameUnparse(bool isRelative, const StringList &fields)
uint64_t allocateSpace(uint64_t byteCount, bool doExtendNow)
bool isPathNameLegal(const ustring &pathName)
void pathNameParse(const ustring &pathName, bool &isRelative, StringList &fields)
bool isElementNameExtended(const ustring &elementName)
Utility functions:
void elementNameParse(const ustring &elementName, ustring &prefix, ustring &localPart, bool allowNumber=true)
ustring extensionsPrefix(const size_t index) const
bool extensionsLookupPrefix(const ustring &prefix, ustring &uri) const
ustring extensionsUri(const size_t index) const
void pathNameCheckWellFormed(const ustring &pathName)
QTextStream & endl(QTextStream &stream)
static const std::string path
constexpr uint32_t E57_FORMAT_MAJOR
Version numbers of ASTM standard that this library supports.
int ReadChecksumPolicy
Specifies the percentage of checksums which are verified when reading an ImageFile (0-100%).
std::shared_ptr< class ImageFileImpl > ImageFileImplSharedPtr
@ E57_ERROR_INTERNAL
An unrecoverable inconsistent internal state was detected.
@ E57_ERROR_BAD_API_ARGUMENT
bad API function argument provided by user
@ E57_ERROR_BAD_FILE_SIGNATURE
file signature not "ASTM-E57"
@ E57_ERROR_IMAGEFILE_NOT_OPEN
destImageFile is no longer open
@ E57_ERROR_BAD_FILE_LENGTH
size in file header not same as actual
@ E57_ERROR_UNKNOWN_FILE_VERSION
incompatible file version
@ E57_ERROR_BAD_PATH_NAME
E57 path name is not well formed.
@ E57_ERROR_DUPLICATE_NAMESPACE_PREFIX
namespace prefix already defined
@ E57_ERROR_DUPLICATE_NAMESPACE_URI
namespace URI already defined
std::string ustring
UTF-8 encodeded Unicode string.
constexpr uint32_t E57_FORMAT_MINOR
std::string toString(T x)
std::vector< std::string > StringList
std::string space(size_t n)
NameSpace(const ustring &prefix0, const ustring &uri0)