29#ifndef EXCEPTIONS_INCLUDED
30#define EXCEPTIONS_INCLUDED
37#define VERBOSE_MESSAGING
41#define DO_PRAGMA(x) _Pragma (#x)
42#define MSVC_WARNING(x) DO_PRAGMA( message( "[WARNING] " #x ) )
45#define MSVC_WARNING(x)
50 template<
typename ... Arguments >
void _AddToMessageStream( std::stringstream &stream , Arguments ... arguments );
52 template<
typename Argument ,
typename ... Arguments >
void _AddToMessageStream( std::stringstream &stream , Argument argument , Arguments ... arguments )
58#ifdef VERBOSE_MESSAGING
59 template<
typename ... Arguments >
60 std::string
MakeMessageString( std::string header , std::string fileName ,
int line , std::string functionName , Arguments ... arguments )
62 size_t headerSize = header.size();
63 std::stringstream stream;
66 stream << header <<
" " << fileName <<
" (Line " << line <<
")" << std::endl;
69 for(
size_t i=0 ; i<=headerSize ; i++ ) stream <<
" ";
70 stream << functionName << std::endl;
73 for(
size_t i=0 ; i<=headerSize ; i++ ) stream <<
" ";
81 const char *
what(
void )
const noexcept {
return _message.c_str(); }
82 template<
typename ... Args >
83 Exception(
const char *fileName ,
int line ,
const char *functionName , Args ... args )
91 template<
typename ... Args >
void Throw(
const char *fileName ,
int line ,
const char *functionName , Args ... args ){
throw Exception( fileName , line , functionName , args ... ); }
92 template<
typename ... Args >
93 void Warn(
const char *fileName ,
int line ,
const char *functionName , Args ... args )
95 std::cerr <<
MakeMessageString(
"[WARNING]" , fileName , line , functionName , args ... ) << std::endl;
98 template<
typename ... Args >
99 void ErrorOut(
const char *fileName ,
int line ,
const char *functionName , Args ... args )
101 std::cerr <<
MakeMessageString(
"[ERROR]" , fileName , line , functionName , args ... ) << std::endl;
105 template<
typename ... Arguments >
106 std::string
MakeMessageString( std::string header , std::string functionName , Arguments ... arguments )
108 std::stringstream stream;
111 stream << header <<
" " << functionName <<
": ";
118 struct Exception :
public std::exception
120 const char *
what(
void )
const noexcept {
return _message.c_str(); }
121 template<
typename ... Args >
122 Exception(
const char *functionName , Args ... args )
129 template<
typename ... Args >
void Throw(
const char *functionName , Args ... args ){
throw Exception( functionName , args ... ); }
130 template<
typename ... Args >
131 void Warn(
const char *functionName , Args ... args )
133 std::cerr <<
MakeMessageString(
"[WARNING]" , functionName , args ... ) << std::endl;
135 template<
typename ... Args >
136 void ErrorOut(
const char *functionName , Args ... args )
138 std::cerr <<
MakeMessageString(
"[WARNING]" , functionName , args ... ) << std::endl;
143#ifdef VERBOSE_MESSAGING
145#define WARN( ... ) Util::Warn( __FILE__ , __LINE__ , __FUNCTION__ , __VA_ARGS__ )
148#define WARN_ONCE( ... ) { static bool firstTime = true ; if( firstTime ) Util::Warn( __FILE__ , __LINE__ , __FUNCTION__ , __VA_ARGS__ ) ; firstTime = false; }
151#define THROW( ... ) Util::Throw( __FILE__ , __LINE__ , __FUNCTION__ , __VA_ARGS__ )
154#define ERROR_OUT( ... ) Util::ErrorOut( __FILE__ , __LINE__ , __FUNCTION__ , __VA_ARGS__ )
158#define WARN( ... ) Util::Warn( __FUNCTION__ , __VA_ARGS__ )
161#define WARN_ONCE( ... ) { static bool firstTime = true ; if( firstTime ) Util::Warn( __FUNCTION__ , __VA_ARGS__ ) ; firstTime = false; }
164#define THROW( ... ) Util::Throw( __FUNCTION__ , __VA_ARGS__ )
167#define ERROR_OUT( ... ) Util::ErrorOut( __FUNCTION__ , __VA_ARGS__ )
void _AddToMessageStream(std::stringstream &stream, Arguments ... arguments)
void Warn(const char *fileName, int line, const char *functionName, Args ... args)
Definition: exceptions.h:93
void Throw(const char *fileName, int line, const char *functionName, Args ... args)
Definition: exceptions.h:91
std::string MakeMessageString(std::string header, std::string fileName, int line, std::string functionName, Arguments ... arguments)
Definition: exceptions.h:60
void ErrorOut(const char *fileName, int line, const char *functionName, Args ... args)
Definition: exceptions.h:99
Definition: exceptions.h:80
std::string _message
Definition: exceptions.h:88
Exception(const char *fileName, int line, const char *functionName, Args ... args)
Definition: exceptions.h:83
const char * what(void) const noexcept
Definition: exceptions.h:81