#include <boost/preprocessor/stringize.hpp> #include <boost/preprocessor/arithmetic/dec.hpp> #include <boost/preprocessor/cat.hpp> #include <boost/preprocessor/repetition/repeat.hpp> #include <boost/preprocessor/arithmetic/add.hpp>
#define FILE_AND_LINE_MESSAGE MESSAGE(__FILE__ " : " BOOST_PP_STRINGIZE(__LINE__) " :")
#define PP_DEC0(v) BOOST_PP_IF(v, BOOST_PP_DEC(v), -1) //allows decrementing from the value 0 too
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
#define MESSAGE2(x) __pragma (message(BOOST_PP_STRINGIZE(x))) #define MESSAGE(x) __pragma (message(x))
#else
#include <boost/preprocessor/debug/assert.hpp>
#define MESSAGE2(x) BOOST_PP_ASSERT_MSG(1, BOOST_PP_STRINGIZE(x)) #define MESSAGE(x) BOOST_PP_ASSERT_MSG(1, x)
#endif
#ifdef __cplusplus
template <int val, int dummyI> struct numeric_message; #define DEFINE_NUMERIC_MESSAGE_T(z, n, data) template <int dummyI> struct numeric_message<n - 1, dummyI> { numeric_message() { MESSAGE(BOOST_PP_STRINGIZE(BOOST_PP_CAT(val :, PP_DEC0(n)))) }; }; #ifndef MAX_NUMERIC_MESSAGE #define MAX_NUMERIC_MESSAGE 128 #endif #if defined(BOOST_PP_REPEAT) && defined(BOOST_PP_ADD)
BOOST_PP_REPEAT(BOOST_PP_ADD(MAX_NUMERIC_MESSAGE, 2), DEFINE_NUMERIC_MESSAGE_T,) #endif
#define NUMERIC_MESSAGE(val) numeric_message<val, __COUNTER__> BOOST_PP_CAT(__numeric_message__, __COUNTER__); //counter is evaluated during compile time, not preprocessing time, so it is ok to use it here
#define NUMERIC_MESSAGE2(val) FILE_AND_LINE_MESSAGE NUMERIC_MESSAGE(val) // TODO: currently the line numbers are printed before other stuff
#endif //#ifdef __cplusplus |