Created
February 11, 2016 14:32
-
-
Save 3Hren/921d34af687ff8d5d26d to your computer and use it in GitHub Desktop.
BOOST PP MAGIC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/preprocessor/comparison/not_equal.hpp> | |
#include <boost/preprocessor/punctuation/remove_parens.hpp> | |
#include <boost/preprocessor/tuple/pop_back.hpp> | |
#include <boost/preprocessor/tuple/push_back.hpp> | |
#include <boost/preprocessor/tuple/reverse.hpp> | |
#include <boost/preprocessor/variadic/to_array.hpp> | |
#define __COCAINE_LOG_IS_NEW_SYNTAX(...) \ | |
BOOST_PP_NOT_EQUAL(1, \ | |
BOOST_PP_LIST_FIRST( \ | |
BOOST_PP_VARIADIC_TO_ARRAY( \ | |
BOOST_PP_REMOVE_PARENS( \ | |
BOOST_PP_TUPLE_ELEM(0, BOOST_PP_TUPLE_REVERSE((__VA_ARGS__))) \ | |
) \ | |
) \ | |
) \ | |
) | |
#define __COCAINE_LOG_ADD_SOURCE(...) \ | |
BOOST_PP_TUPLE_PUSH_BACK( \ | |
BOOST_PP_TUPLE_POP_BACK((__VA_ARGS__)), \ | |
(::blackhole::attribute_list{ \ | |
BOOST_PP_REMOVE_PARENS(BOOST_PP_TUPLE_ELEM(0, BOOST_PP_TUPLE_REVERSE((__VA_ARGS__))))\ | |
,{"dbg.lineno", __LINE__}\ | |
,{"dbg.filename", __FILE__}\ | |
,{"dbg.function", __func__ }\ | |
,{"dbg.translation", __DATE__ ":" __TIME__}\ | |
})\ | |
) | |
#define COCAINE_LOG(__logger__, __severity__, ...) \ | |
::cocaine::detail::logging::make_facade(__logger__).log(__severity__, \ | |
BOOST_PP_REMOVE_PARENS(\ | |
BOOST_PP_IF(__COCAINE_LOG_IS_NEW_SYNTAX(__VA_ARGS__), \ | |
__COCAINE_LOG_ADD_SOURCE(__VA_ARGS__), \ | |
(__VA_ARGS__)\ | |
)\ | |
)\ | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment