Skip to content

Commit

Permalink
{format} Update clang-format rules & apply formatting (#168)
Browse files Browse the repository at this point in the history
Adds the test code to the formatting rules & changes CI to use clang-format 15.
  • Loading branch information
asmaloney authored Nov 6, 2022
1 parent a216e5e commit 8ae8261
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
Expand Down Expand Up @@ -57,6 +58,8 @@ ContinuationIndentWidth: 3
Cpp11BracedListStyle: false
DeriveLineEnding: false
DerivePointerAlignment: false
EmptyLineBeforeAccessModifier: LogicalBlock
EmptyLineAfterAccessModifier: Never
FixNamespaceComments: false
IncludeBlocks: Preserve
IncludeCategories:
Expand All @@ -71,6 +74,7 @@ IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 3
IndentWrappedFunctionNames: true
InsertBraces: true
KeepEmptyLinesAtTheStartOfBlocks: true
Language: Cpp
MaxEmptyLinesToKeep: 1
Expand All @@ -91,6 +95,7 @@ SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
- name: Run clang-format style check
uses: jidicula/clang-format-action@v4.9.0
with:
clang-format-version: '13'
clang-format-version: '15'
exclude-regex: 'extern'
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ add_subdirectory( extern/CRCpp )
add_subdirectory( include )
add_subdirectory( src )

include( ClangFormat )

# Target properties
set_target_properties( E57Format
PROPERTIES
Expand Down Expand Up @@ -219,6 +217,9 @@ if ( E57_BUILD_TEST )
add_subdirectory( test )
endif()

# Formatting
include( ClangFormat )

# CMake package files
install(
EXPORT
Expand Down
11 changes: 11 additions & 0 deletions cmake/Modules/ClangFormat.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ if ( E57_CLANG_FORMAT_EXE )
list( FILTER e57_sources EXCLUDE REGEX ".*/E57Export.h" )
list( FILTER e57_sources EXCLUDE REGEX ".*/extern/.*" )

# Get list of test files. We cannot use get_target_property here
# since we will not have a target if E57_BUILD_TEST is off.
file( GLOB e57_test_sources
LIST_DIRECTORIES false
CONFIGURE_DEPENDS
${PROJECT_SOURCE_DIR}/test/include/*.h
${PROJECT_SOURCE_DIR}/test/src/*.cpp
)

list( APPEND e57_sources ${e57_test_sources} )

add_custom_target( format
COMMAND clang-format --style=file -i ${e57_sources}
COMMENT "Running clang-format..."
Expand Down
1 change: 1 addition & 0 deletions src/BlobNodeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace e57
{
return E57_BLOB;
}

bool isTypeEquivalent( NodeImplSharedPtr ni ) override;
bool isDefined( const ustring &pathName ) override;

Expand Down
2 changes: 2 additions & 0 deletions src/CheckedFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ uint64_t CheckedFile::lseek64( int64_t offset, int whence )
// triggered (cygwin != WIN32)?
#ifdef E57_MAX_DEBUG
if ( sizeof( off_t ) != sizeof( offset ) )
{
throw E57_EXCEPTION2( E57_ERROR_INTERNAL, "sizeof(off_t)=" + toString( sizeof( off_t ) ) );
}
#endif
int64_t result = ::lseek( fd_, offset, whence );
#else
Expand Down
2 changes: 2 additions & 0 deletions src/CheckedFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ namespace e57
uint64_t position( OffsetMode omode = Logical );
uint64_t length( OffsetMode omode = Logical );
void extend( uint64_t newLength, OffsetMode omode = Logical );

e57::ustring fileName() const
{
return fileName_;
}

void close();
void unlink();

Expand Down
4 changes: 4 additions & 0 deletions src/CompressedVectorNodeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace e57
{
return E57_COMPRESSED_VECTOR;
}

bool isTypeEquivalent( NodeImplSharedPtr ni ) override;
bool isDefined( const ustring &pathName ) override;
void setAttachedRecursive() override;
Expand All @@ -64,14 +65,17 @@ namespace e57
{
return ( recordCount_ );
}

uint64_t getBinarySectionLogicalStart() const
{
return ( binarySectionLogicalStart_ );
}

void setRecordCount( int64_t recordCount )
{
recordCount_ = recordCount;
}

void setBinarySectionLogicalStart( uint64_t binarySectionLogicalStart )
{
binarySectionLogicalStart_ = binarySectionLogicalStart;
Expand Down
3 changes: 3 additions & 0 deletions src/Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace e57
virtual uint64_t totalRecordsCompleted() = 0;
virtual size_t inputProcess( const char *source, size_t count ) = 0;
virtual void stateReset() = 0;

unsigned bytestreamNumber() const
{
return bytestreamNumber_;
Expand Down Expand Up @@ -158,10 +159,12 @@ namespace e57
ConstantIntegerDecoder( bool isScaledInteger, unsigned bytestreamNumber, SourceDestBuffer &dbuf, int64_t minimum,
double scale, double offset, uint64_t maxRecordCount );
void destBufferSetNew( std::vector<SourceDestBuffer> &dbufs ) override;

uint64_t totalRecordsCompleted() override
{
return currentRecordIndex_;
}

size_t inputProcess( const char *source, size_t availableByteCount ) override;
void stateReset() override;
#ifdef E57_DEBUG
Expand Down
2 changes: 2 additions & 0 deletions src/E57XmlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ class E57FileInputStream : public BinInputStream
{
return ( logicalPosition_ );
}

XMLSize_t readBytes( XMLByte *const toFill, XMLSize_t maxToRead ) override;

const XMLCh *getContentType() const override
{
return nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/E57XmlParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace e57
ParseInfo(); // default ctor
void dump( int indent = 0, std::ostream &os = std::cout ) const;
};

std::stack<ParseInfo> stack_; /// Stores the current path in tree we are reading

SAX2XMLReader *xmlReader;
Expand Down
2 changes: 2 additions & 0 deletions src/Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,9 @@ template <typename RegisterT> uint64_t BitpackIntegerEncoder<RegisterT>::process
/// Double check that register will hold at least one input records worth of
/// bits
if ( 8 * sizeof( RegisterT ) < bitsPerRecord_ )
{
throw E57_EXCEPTION2( E57_ERROR_INTERNAL, "bitsPerRecord=" + toString( bitsPerRecord_ ) );
}
#endif

/// Before we add any more, try to shift current contents of outBuffer_ down
Expand Down
1 change: 1 addition & 0 deletions src/FloatNodeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace e57
{
return E57_FLOAT;
}

bool isTypeEquivalent( NodeImplSharedPtr ni ) override;
bool isDefined( const ustring &pathName ) override;

Expand Down
1 change: 1 addition & 0 deletions src/IntegerNodeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace e57
{
return E57_INTEGER;
}

bool isTypeEquivalent( NodeImplSharedPtr ni ) override;
bool isDefined( const ustring &pathName ) override;

Expand Down
2 changes: 2 additions & 0 deletions src/NodeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ namespace e57

explicit NodeImpl( ImageFileImplWeakPtr destImageFile );
NodeImpl &operator=( NodeImpl &n );

virtual NodeImplSharedPtr lookup( const ustring & /*pathName*/ )
{
return NodeImplSharedPtr();
}

NodeImplSharedPtr getRoot();

ImageFileImplWeakPtr destImageFile_;
Expand Down
2 changes: 2 additions & 0 deletions src/Packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,9 @@ void IndexPacket::verify( unsigned bufferLength, uint64_t totalRecordCount, uint
for ( unsigned i = neededLength; i < packetLength; i++ )
{
if ( p[i] != 0 )
{
throw E57_EXCEPTION2( E57_ERROR_BAD_CV_PACKET, "i=" + toString( i ) );
}
}

/// Verify records and offsets are in sorted order
Expand Down
8 changes: 8 additions & 0 deletions src/ScaledIntegerNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,21 @@ ScaledIntegerNode::ScaledIntegerNode( ImageFile destImageFile, int64_t rawValue,
impl_( new ScaledIntegerNodeImpl( destImageFile.impl(), rawValue, minimum, maximum, scale, offset ) )
{
}

ScaledIntegerNode::ScaledIntegerNode( ImageFile destImageFile, int rawValue, int64_t minimum, int64_t maximum,
double scale, double offset ) :
impl_( new ScaledIntegerNodeImpl( destImageFile.impl(), static_cast<int64_t>( rawValue ), minimum, maximum, scale,
offset ) )
{
}

ScaledIntegerNode::ScaledIntegerNode( ImageFile destImageFile, int rawValue, int minimum, int maximum, double scale,
double offset ) :
impl_( new ScaledIntegerNodeImpl( destImageFile.impl(), static_cast<int64_t>( rawValue ),
static_cast<int64_t>( minimum ), static_cast<int64_t>( maximum ), scale, offset ) )
{
}

/*!
@brief This second constructor creates an E57 element for storing a fixed point
number but does the scaling for you.
Expand Down Expand Up @@ -169,6 +172,7 @@ ScaledIntegerNode::ScaledIntegerNode( ImageFile destImageFile, double scaledValu
impl_( new ScaledIntegerNodeImpl( destImageFile.impl(), scaledValue, scaledMinimum, scaledMaximum, scale, offset ) )
{
}

//! @brief Is this a root node.
//! @copydetails Node::isRoot()
bool ScaledIntegerNode::isRoot() const
Expand Down Expand Up @@ -254,6 +258,7 @@ int64_t ScaledIntegerNode::minimum() const
{
return impl_->minimum();
}

/*!
@brief Get the declared scaled minimum that the scaled value may take.
@pre The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Expand All @@ -267,6 +272,7 @@ double ScaledIntegerNode::scaledMinimum() const
{
return impl_->scaledMinimum();
}

/*!
@brief Get the declared maximum that the raw value may take.
@pre The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Expand All @@ -280,6 +286,7 @@ int64_t ScaledIntegerNode::maximum() const
{
return impl_->maximum();
}

/*!
@brief Get the declared scaled maximum that the scaled value may take.
@pre The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Expand All @@ -293,6 +300,7 @@ double ScaledIntegerNode::scaledMaximum() const // Added by SC
{
return impl_->scaledMaximum();
}

/*!
@brief Get declared scaling factor.
@pre The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Expand Down
2 changes: 2 additions & 0 deletions src/ScaledIntegerNodeImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ namespace e57
checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
return ( minimum_ );
}

double ScaledIntegerNodeImpl::scaledMinimum()
{
checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
Expand All @@ -149,6 +150,7 @@ namespace e57
checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
return ( maximum_ );
}

double ScaledIntegerNodeImpl::scaledMaximum()
{
checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
Expand Down
1 change: 1 addition & 0 deletions src/ScaledIntegerNodeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace e57
{
return E57_SCALED_INTEGER;
}

bool isTypeEquivalent( NodeImplSharedPtr ni ) override;
bool isDefined( const ustring &pathName ) override;

Expand Down
9 changes: 9 additions & 0 deletions src/SourceDestBufferImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,47 @@ namespace e57
{
return pathName_;
}

MemoryRepresentation memoryRepresentation() const
{
return memoryRepresentation_;
}

void *base() const
{
return base_;
}

StringList *ustrings() const
{
return ustrings_;
}

bool doConversion() const
{
return doConversion_;
}

bool doScaling() const
{
return doScaling_;
}

size_t stride() const
{
return stride_;
}

size_t capacity() const
{
return capacity_;
}

unsigned nextIndex() const
{
return nextIndex_;
}

void rewind()
{
nextIndex_ = 0;
Expand Down
1 change: 1 addition & 0 deletions src/StringNodeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace e57
{
return E57_STRING;
}

bool isTypeEquivalent( NodeImplSharedPtr ni ) override;
bool isDefined( const ustring &pathName ) override;

Expand Down
1 change: 1 addition & 0 deletions src/StructureNodeImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ int64_t StructureNodeImpl::childCount() const

return children_.size();
}

NodeImplSharedPtr StructureNodeImpl::get( int64_t index )
{
checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
Expand Down

0 comments on commit 8ae8261

Please sign in to comment.