Skip to content

Commit

Permalink
Add extensionsLookupPrefix overload for more concise user code (#161)
Browse files Browse the repository at this point in the history
Users of the API probably don't care about the extension URI in general. Some don't even point to valid files online.
  • Loading branch information
asmaloney authored Nov 2, 2022
1 parent 0fd8073 commit 13953ef
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/E57Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ protected:

// Manipulate registered extensions in the file
void extensionsAdd( const ustring &prefix, const ustring &uri );
bool extensionsLookupPrefix( const ustring &prefix ) const;
bool extensionsLookupPrefix( const ustring &prefix, ustring &uri ) const;
bool extensionsLookupUri( const ustring &uri, ustring &prefix ) const;
size_t extensionsCount() const;
Expand Down
20 changes: 20 additions & 0 deletions src/ImageFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,26 @@ void ImageFile::extensionsAdd( const ustring &prefix, const ustring &uri )
impl_->extensionsAdd( prefix, uri );
}

/*!
@brief Look up an E57 extension prefix in the ImageFile.
@param [in] prefix The shorthand name of the extension to look up.
@details
If @a prefix = "" or @a prefix is declared in the ImageFile, then the function returns true. It is an error if @a prefix
contains an illegal character combination for E57 namespace prefixes.
@pre This ImageFile must be open (i.e. isOpen()).
@post No visible state is modified.
@return true if prefix is declared in the ImageFile.
@throw ::E57_ERROR_BAD_API_ARGUMENT
@throw ::E57_ERROR_IMAGEFILE_NOT_OPEN
@throw ::E57_ERROR_INTERNAL All objects in undocumented state
@see ImageFile::extensionsLookupUri
*/
bool ImageFile::extensionsLookupPrefix( const ustring &prefix ) const
{
ustring uri;
return impl_->extensionsLookupPrefix( prefix, uri );
}

/*!
@brief Get URI associated with an E57 extension prefix in the ImageFile.
@param [in] prefix The shorthand name of the extension to look up.
Expand Down
3 changes: 1 addition & 2 deletions src/ReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,7 @@ namespace e57

// E57_EXT_surface_normals
// See: http://www.libe57.org/E57_EXT_surface_normals.txt
ustring norExtUri;
if ( imf_.extensionsLookupPrefix( "nor", norExtUri ) )
if ( imf_.extensionsLookupPrefix( "nor" ) )
{
data3DHeader.pointFields.normalXField = proto.isDefined( "nor:normalX" );
data3DHeader.pointFields.normalYField = proto.isDefined( "nor:normalY" );
Expand Down
6 changes: 2 additions & 4 deletions src/WriterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,7 @@ namespace e57
data3DHeader.pointFields.normalZField )
{
// make sure we declare the extension before using the fields with prefix
ustring norExtUri;
if ( !imf_.extensionsLookupPrefix( "nor", norExtUri ) )
if ( !imf_.extensionsLookupPrefix( "nor" ) )
{
imf_.extensionsAdd( "nor", "http://www.libe57.org/E57_EXT_surface_normals.txt" );
}
Expand Down Expand Up @@ -1088,8 +1087,7 @@ namespace e57
}

// E57_EXT_surface_normals
ustring norExtUri;
if ( imf_.extensionsLookupPrefix( "nor", norExtUri ) )
if ( imf_.extensionsLookupPrefix( "nor" ) )
{
if ( proto.isDefined( "nor:normalX" ) && ( buffers.normalX != nullptr ) )
{
Expand Down

0 comments on commit 13953ef

Please sign in to comment.