Skip to content

Commit a5e803d

Browse files
authored
Merge pull request #32 from ethz-asl/feature/improve_ppmacros
Macro improvements
2 parents 001883e + c770907 commit a5e803d

File tree

2 files changed

+22
-66
lines changed

2 files changed

+22
-66
lines changed

.github/scripts/run_build_ubuntu20_04.sh

Lines changed: 0 additions & 48 deletions
This file was deleted.

include/log++.h

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@
6868
//! Check if libraries are available at compile time and include required headers
6969
#if __has_include(<glog/logging.h>)
7070
#include <glog/logging.h>
71-
#define GLOG_SUPPORTED
71+
#define LPP_GLOG_SUPPORTED
7272
#endif
7373

7474
#if __has_include(<ros/console.h>)
7575
#include <ros/console.h>
76-
#define ROSLOG_SUPPORTED
76+
#define LPP_ROSLOG_SUPPORTED
7777
#endif
7878

7979
//! Debug flag, If LPP_DEBUG is enabled, debug output should be printed.
@@ -138,23 +138,23 @@ inline static Init lppInit;
138138
}
139139

140140
//! assert if mode is supported by the libraries available
141-
#if defined MODE_GLOG && !defined GLOG_SUPPORTED
141+
#if defined MODE_GLOG && !defined LPP_GLOG_SUPPORTED
142142
#error Logging Mode is set to glog but glog was not found
143143
#endif
144144

145-
#if defined MODE_ROSLOG && !defined ROSLOG_SUPPORTED
145+
#if defined MODE_ROSLOG && !defined LPP_ROSLOG_SUPPORTED
146146
#error Logging Mode is set to roslog but roslog was not found
147147
#endif
148148

149149

150150
//! Un-define glog`s LOG macro to avoid conflicts
151-
#ifdef GLOG_SUPPORTED
151+
#ifdef LPP_GLOG_SUPPORTED
152152
#undef LOG
153153
#endif
154154

155155

156156
//! Un-define log methods for redefinition
157-
#if defined GLOG_SUPPORTED && !defined MODE_GLOG && !defined MODE_DEFAULT
157+
#if defined LPP_GLOG_SUPPORTED && !defined MODE_GLOG && !defined MODE_DEFAULT
158158
#undef LOG_IF
159159
#undef LOG_EVERY_N
160160
#undef LOG_FIRST_N
@@ -169,7 +169,7 @@ inline static Init lppInit;
169169
#undef LOG_STRING
170170
#endif
171171

172-
#if defined ROSLOG_SUPPORTED && !defined MODE_ROSLOG && !defined MODE_DEFAULT
172+
#if defined LPP_ROSLOG_SUPPORTED && !defined MODE_ROSLOG && !defined MODE_DEFAULT
173173
#undef ROS_DEBUG
174174
#undef ROS_DEBUG_STREAM
175175
#undef ROS_INFO
@@ -236,7 +236,7 @@ inline void LOG_INIT([[maybe_unused]] char *argv, [[maybe_unused]] const std::fu
236236
#endif
237237

238238
#if defined MODE_GLOG || defined MODE_DEFAULT
239-
#ifdef GLOG_SUPPORTED
239+
#ifdef LPP_GLOG_SUPPORTED
240240
google::InitGoogleLogging(argv);
241241
FLAGS_logtostderr = true;
242242
lppInit.glog_initialized = true;
@@ -250,21 +250,21 @@ inline void LOG_INIT([[maybe_unused]] char *argv, [[maybe_unused]] const std::fu
250250
#define LPP_ASSERT_GLOG(x) static_assert((x) == LPP_INTL::GlogSeverity::INFO || (x) == LPP_INTL::GlogSeverity::WARNING || (x) == LPP_INTL::GlogSeverity::ERROR || (x) == LPP_INTL::GlogSeverity::FATAL, "Unknown severity level")
251251

252252
//! Hack to enable macro overloading. Used to overload glog's LOG() macro.
253-
#define CAT(A, B) A ## B
254-
#define SELECT(NAME, NUM) CAT( NAME ## _, NUM )
253+
#define LPP_CAT(A, B) A ## B
254+
#define LPP_SELECT(NAME, NUM) LPP_CAT( NAME ## _, NUM )
255255

256-
#define GET_COUNT(_1, _2, _3, _4, _5, _6, COUNT, ...) COUNT
257-
#define VA_SIZE(...) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )
258-
#define VA_SELECT(NAME, ...) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)
256+
#define LPP_GET_COUNT(_1, _2, _3, _4, _5, _6, COUNT, ...) COUNT
257+
#define LPP_VA_SIZE(...) LPP_GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )
258+
#define LPP_VA_SELECT(NAME, ...) LPP_SELECT( NAME, LPP_VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)
259259

260260
//! Helper macros to generate warnings
261-
#define DO_PRAGMA(x) _Pragma (#x)
262-
#define LPP_WARN(x) DO_PRAGMA(message (#x))
261+
#define LPP_PRAGMA(x) _Pragma (#x)
262+
#define LPP_WARN(x) LPP_PRAGMA(message (#x))
263263

264264
//! Overloads
265265
#pragma clang diagnostic push
266266
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
267-
#define LOG(...) VA_SELECT( LOG, __VA_ARGS__ )
267+
#define LOG(...) LPP_VA_SELECT( LOG, __VA_ARGS__ )
268268
#pragma clang diagnostic pop
269269

270270
/**
@@ -402,9 +402,9 @@ if constexpr(LPP_INTL::LppSeverity::severity == LPP_INTL::LppSeverity::I
402402
*/
403403
[[maybe_unused]] inline static int32_t LPP_FLAGS_v;
404404

405-
#ifdef GLOG_SUPPORTED
405+
#ifdef LPP_GLOG_SUPPORTED
406406
#define FLAGS_v LPP_FLAGS_v
407-
#endif //GLOG_SUPPORTED
407+
#endif //LPP_GLOG_SUPPORTED
408408
#endif //defined MODE_ROSLOG || defined MODE_LPP || MODE_NOLOG
409409

410410
#if defined MODE_ROSLOG || defined MODE_LPP
@@ -966,4 +966,8 @@ class LppGlogExtensionLog : public InternalPolicyLog<unsigned int> {
966966
#define LPP_GET_KEY() std::string(__FILE__) + std::to_string(__LINE__)
967967
#pragma clang diagnostic pop
968968

969+
// Undefine macros that are only needed in this file
970+
#undef LPP_GLOG_SUPPORTED
971+
#undef LPP_ROSLOG_SUPPORTED
972+
969973
#endif //LOG__LOG_H_

0 commit comments

Comments
 (0)