Skip to content

Commit

Permalink
including new code
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusRainerSchmidt committed Oct 2, 2018
1 parent 11f125d commit 904e3cf
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 41 deletions.
1 change: 1 addition & 0 deletions .clang-format
Expand Up @@ -22,6 +22,7 @@ IndentWidth: '4'
Language: Cpp
MaxEmptyLinesToKeep: '2'
NamespaceIndentation: None
PointerAlignment: Left
ReflowComments: 'true'
SortIncludes: 'true'
SpaceAfterCStyleCast: 'false'
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Expand Up @@ -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= \
Expand Down
39 changes: 17 additions & 22 deletions inc/module/module.h
Expand Up @@ -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;
}
Expand All @@ -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

Expand All @@ -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<Pledge> EXPORTED
promiseMe( std::shared_ptr<Module> pThis, std::vector<std::shared_ptr<Pledge>> vInput );
static std::shared_ptr<Pledge> EXPORTED promiseMe( std::shared_ptr<Module> pThis,
std::vector<std::shared_ptr<Pledge>> vInput );
};

/**
Expand Down Expand Up @@ -414,8 +413,7 @@ class Pledge : public Container
* once python is done...
*/
auto timeStamp = std::chrono::system_clock::now( );
content = boost::python::extract<std::shared_ptr<Container>>(
py_pledger.attr( "save_execute" )( vInput ) );
content = boost::python::extract<std::shared_ptr<Container>>( py_pledger.attr( "save_execute" )( vInput ) );
std::chrono::duration<double> duration = std::chrono::system_clock::now( ) - timeStamp;
execTime = duration.count( );
DEBUG( if( !typeCheck( content, type ) ) {
Expand All @@ -438,8 +436,7 @@ class Pledge : public Container
* Does not lock otherwise.
* In either case fDo is called.
*/
inline std::shared_ptr<Container>
lockIfNecessary( std::function<std::shared_ptr<Container>( )> fDo )
inline std::shared_ptr<Container> lockIfNecessary( std::function<std::shared_ptr<Container>( )> fDo )
{
// if(vSuccessors.size() > 1) @todo @fixme this should be here
if( pledger != nullptr && pledger->requiresLock( ) )
Expand Down Expand Up @@ -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<Container> c ) const
Expand Down Expand Up @@ -513,16 +510,15 @@ class Pledge : public Container
return pledger;
} // function

static EXPORTED std::shared_ptr<Pledge> makePledge(
std::shared_ptr<Module> pledger, std::vector<std::shared_ptr<Pledge>> vPredecessors );
static EXPORTED std::shared_ptr<Pledge> makePledge( std::shared_ptr<Module> pledger,
std::vector<std::shared_ptr<Pledge>> vPredecessors );

#ifdef WITH_PYTHON
static inline std::shared_ptr<Pledge>
makePyPledge( boost::python::object py_pledger, std::shared_ptr<Container> type,
std::vector<std::shared_ptr<Pledge>> vPredecessors )
static inline std::shared_ptr<Pledge> makePyPledge( boost::python::object py_pledger,
std::shared_ptr<Container> type,
std::vector<std::shared_ptr<Pledge>> vPredecessors )
{
std::shared_ptr<Pledge> pRet =
std::shared_ptr<Pledge>( new Pledge( py_pledger, type, vPredecessors ) );
std::shared_ptr<Pledge> pRet = std::shared_ptr<Pledge>( new Pledge( py_pledger, type, vPredecessors ) );

for( std::shared_ptr<Pledge> pPredecessor : vPredecessors )
pPredecessor->vSuccessors.push_back( std::weak_ptr<Pledge>( pRet ) );
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
}
Expand Down
89 changes: 74 additions & 15 deletions inc/util/support.h
Expand Up @@ -50,29 +50,29 @@ 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.
* @details
* Checks: Whether val is between min and max.
*/
template <typename ParameterType>
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

Expand All @@ -82,16 +82,75 @@ void vRangeCheckAndThrowInclusive( const std::string &sText, const ParameterType
* Checks: Whether val is between min and max.
*/
template <typename ParameterType>
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 <size_t IDX> 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 <size_t c, template <size_t> class Func> struct TemplateLoop
{
template <typename... TP_PARAMS> static bool iterate( TP_PARAMS&... rParams )
{
if( !TemplateLoop<c - 1, Func>::iterate( rParams... ) )
return false;
return Func<c - 1>( )( rParams... );
}
};

template <template <size_t> class Func> struct TemplateLoop<1, Func>
{
template <typename... TP_PARAMS> static bool iterate( TP_PARAMS&... rParams )
{
return Func<0>( )( rParams... );
}
};
// This makes is possible to have loops that are executed 0 times
template <template <size_t> class Func> struct TemplateLoop<0, Func>
{
template <typename... TP_PARAMS> static bool iterate( TP_PARAMS&... rParams )
{
return true;
}
};

#endif

0 comments on commit 904e3cf

Please sign in to comment.