diff --git a/.clang-format b/.clang-format index 079a38c6..6635b09c 100644 --- a/.clang-format +++ b/.clang-format @@ -22,6 +22,7 @@ IndentWidth: '4' Language: Cpp MaxEmptyLinesToKeep: '2' NamespaceIndentation: None +PointerAlignment: Left ReflowComments: 'true' SortIncludes: 'true' SpaceAfterCStyleCast: 'false' diff --git a/Makefile b/Makefile index 75b563d8..0ce3c287 100644 --- a/Makefile +++ b/Makefile @@ -25,21 +25,23 @@ TARGET_OBJ= \ # flags CC=gcc +STD=-std=c++17 +#CC=clang++-6.0 # use avx instead of sse ifeq ($(NO_SSE), 1) - CCFLAGS= -Wall -Werror -fPIC -std=c++11 -O3 -g + CCFLAGS= -Wall -Werror -fPIC $(STD) -O3 -g CFLAGS= -Wall -Werror -fPIC -O3 -g else - CCFLAGS= -Wall -Werror -fPIC -std=c++11 -O3 -g -msse4.1 + CCFLAGS= -Wall -Werror -fPIC $(STD) -O3 -g -msse4.1 CFLAGS= -Wall -Werror -fPIC -O3 -g -msse4.1 endif -LDFLAGS= -std=c++11 +LDFLAGS= $(STD) LDLIBS= -lm -lpthread -lstdc++ INCLUDES= -Iinc # this adds debug switches ifeq ($(DEBUG), 1) - CCFLAGS = -Wall -Werror -fPIC -std=c++11 -g -DDEBUG_LEVEL=1 -Og + CCFLAGS = -Wall -Werror -fPIC $(STD) -g -DDEBUG_LEVEL=1 -Og # we store release and debug objects in different folders # no debug version for the ksw library TARGET_OBJ= \ diff --git a/inc/module/module.h b/inc/module/module.h index a116436f..b17a1fa3 100644 --- a/inc/module/module.h +++ b/inc/module/module.h @@ -172,11 +172,11 @@ class Module std::cerr << "cant return to python - cpp module failed" << std::endl; exit( 0 ); } - catch( const std::exception &e ) + catch( const std::exception& e ) { std::cerr << e.what( ) << std::endl; } - catch( const std::string &e ) + catch( const std::string& e ) { std::cerr << e << std::endl; } @@ -189,8 +189,7 @@ class Module } // catch return nullptr; #else - throw AlignerException( - "python modules are not allowed to call cpp modules currently - sorry" ); + throw AlignerException( "python modules are not allowed to call cpp modules currently - sorry" ); #endif } // function @@ -202,8 +201,8 @@ class Module * @note This is static since we need to save a reference to the shared_ptr of the Module * promising. */ - static std::shared_ptr EXPORTED - promiseMe( std::shared_ptr pThis, std::vector> vInput ); + static std::shared_ptr EXPORTED promiseMe( std::shared_ptr pThis, + std::vector> vInput ); }; /** @@ -414,8 +413,7 @@ class Pledge : public Container * once python is done... */ auto timeStamp = std::chrono::system_clock::now( ); - content = boost::python::extract>( - py_pledger.attr( "save_execute" )( vInput ) ); + content = boost::python::extract>( py_pledger.attr( "save_execute" )( vInput ) ); std::chrono::duration duration = std::chrono::system_clock::now( ) - timeStamp; execTime = duration.count( ); DEBUG( if( !typeCheck( content, type ) ) { @@ -438,8 +436,7 @@ class Pledge : public Container * Does not lock otherwise. * In either case fDo is called. */ - inline std::shared_ptr - lockIfNecessary( std::function( )> fDo ) + inline std::shared_ptr lockIfNecessary( std::function( )> fDo ) { // if(vSuccessors.size() > 1) @todo @fixme this should be here if( pledger != nullptr && pledger->requiresLock( ) ) @@ -475,7 +472,7 @@ class Pledge : public Container /** * @brief this is required due to the use of mutex */ - Pledge( const Pledge & ) = delete; // copy constructor + Pledge( const Pledge& ) = delete; // copy constructor // overload bool canCast( std::shared_ptr c ) const @@ -513,16 +510,15 @@ class Pledge : public Container return pledger; } // function - static EXPORTED std::shared_ptr makePledge( - std::shared_ptr pledger, std::vector> vPredecessors ); + static EXPORTED std::shared_ptr makePledge( std::shared_ptr pledger, + std::vector> vPredecessors ); #ifdef WITH_PYTHON - static inline std::shared_ptr - makePyPledge( boost::python::object py_pledger, std::shared_ptr type, - std::vector> vPredecessors ) + static inline std::shared_ptr makePyPledge( boost::python::object py_pledger, + std::shared_ptr type, + std::vector> vPredecessors ) { - std::shared_ptr pRet = - std::shared_ptr( new Pledge( py_pledger, type, vPredecessors ) ); + std::shared_ptr pRet = std::shared_ptr( new Pledge( py_pledger, type, vPredecessors ) ); for( std::shared_ptr pPredecessor : vPredecessors ) pPredecessor->vSuccessors.push_back( std::weak_ptr( pRet ) ); @@ -693,8 +689,7 @@ class Pledge : public Container if( pPledge->hasPythonPledger( ) ) { numThreads = 1; - DEBUG( std::cout << "Detected python module. Cannot use more than one thread." - << std::endl; ) + DEBUG( std::cout << "Detected python module. Cannot use more than one thread." << std::endl; ) break; } // if @@ -750,11 +745,11 @@ class Pledge : public Container { std::cerr << "Module Failed: " << e.what( ) << std::endl; } - catch( const std::exception &e ) + catch( const std::exception& e ) { std::cerr << e.what( ) << std::endl; } - catch( const std::string &e ) + catch( const std::string& e ) { std::cerr << e << std::endl; } diff --git a/inc/util/support.h b/inc/util/support.h index d7e6deb5..d77c0bbc 100644 --- a/inc/util/support.h +++ b/inc/util/support.h @@ -50,13 +50,13 @@ typedef unsigned __int64 uint64_t; #endif #endif -bool fileExists( const std::string &rsFile ); +bool fileExists( const std::string& rsFile ); -void makeDir( const std::string &rsFile ); +void makeDir( const std::string& rsFile ); /* Constructs the full filename for a prefix, suffix combination. */ -std::string EXPORTED fullFileName( const char *pcFileNamePrefix, const char *pcSuffix ); +std::string EXPORTED fullFileName( const char* pcFileNamePrefix, const char* pcSuffix ); /** * @brief Function for range checking. @@ -64,15 +64,15 @@ std::string EXPORTED fullFileName( const char *pcFileNamePrefix, const char *pcS * Checks: Whether val is between min and max. */ template -void vRangeCheckAndThrowInclusive( const std::string &sText, const ParameterType &xRangeMin, - const ParameterType &xVal, const ParameterType &xRangeMax ) +void vRangeCheckAndThrowInclusive( const std::string& sText, const ParameterType& xRangeMin, const ParameterType& xVal, + const ParameterType& xRangeMax ) { if( xVal < xRangeMin || xVal > xRangeMax ) { - throw std::runtime_error( ( - ( ( ( ( ( ( std::string( sText ) += "Out of range for value : " ) += std::to_string( - xVal ) ) += " range : [ " ) += std::to_string( xRangeMin ) ) += ".." ) += - std::to_string( xRangeMax ) ) += "]" ) ); // runtime error + throw std::runtime_error( + ( ( ( ( ( ( ( std::string( sText ) += "Out of range for value : " ) += std::to_string( xVal ) ) += + " range : [ " ) += std::to_string( xRangeMin ) ) += ".." ) += std::to_string( xRangeMax ) ) += + "]" ) ); // runtime error } // if } // template function @@ -82,16 +82,75 @@ void vRangeCheckAndThrowInclusive( const std::string &sText, const ParameterType * Checks: Whether val is between min and max. */ template -void vRangeCheckAndThrowExclusive( const std::string &sText, const ParameterType &xRangeMin, - const ParameterType &xVal, const ParameterType &xRangeMax ) +void vRangeCheckAndThrowExclusive( const std::string& sText, const ParameterType& xRangeMin, const ParameterType& xVal, + const ParameterType& xRangeMax ) { if( xVal < xRangeMin || xVal >= xRangeMax ) { - throw std::runtime_error( ( - ( ( ( ( ( ( std::string( sText ) += "Out of range for value : " ) += std::to_string( - xVal ) ) += " range : [ " ) += std::to_string( xRangeMin ) ) += ".." ) += - std::to_string( xRangeMax ) ) += ")" ) ); // runtime error + throw std::runtime_error( + ( ( ( ( ( ( ( std::string( sText ) += "Out of range for value : " ) += std::to_string( xVal ) ) += + " range : [ " ) += std::to_string( xRangeMin ) ) += ".." ) += std::to_string( xRangeMax ) ) += + ")" ) ); // runtime error } // if } // template function +/** + * @brief Loop where the counter value is known during compiletime. + * @details + * Example Usage: + * template struct Exec + * { + * bool operator( )( int& x ) + * { + * std::cout << x << std::endl; + * return true; + * } // operator + * }; // struct + * + * int main() + * { + * int x = 10; + * bool bComplete = TemplateLoop<3, Exec>::iterate(x); + * if(bComplete) + * std::cout << "true" << std::endl; + * else + * std::cout << "false" << std::endl; + * return 0; + * } // function + * Prints: + * 10 + * 10 + * 10 + * true + * + * + * The executed struct can return false in order to break the iteration. If done so iterate returns false. + * Otherwise iterate returns true. + */ +template class Func> struct TemplateLoop +{ + template static bool iterate( TP_PARAMS&... rParams ) + { + if( !TemplateLoop::iterate( rParams... ) ) + return false; + return Func( )( rParams... ); + } +}; + +template