Skip to content

Commit 19538ca

Browse files
committed
ts: expand arguments before stringifications in CV_ENUM and CV_FLAGS
added protective macros to always force macro expansion of arguments. This allows using CV_ENUM and CV_FLAGS with macro arguments.
1 parent f935a16 commit 19538ca

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

modules/ts/include/opencv2/ts/ts_perf.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ class MatType
9393
* CV_ENUM and CV_FLAGS - macro to create printable wrappers for defines and enums *
9494
\*****************************************************************************************/
9595

96+
// helper macros to force expansion of macro arguments before stringification
97+
// "#" normally blocks argument expansion
98+
#define CV_STRINGIFY_ARGS(...) CV_STRINGIFY_ARGS_(__VA_ARGS__)
99+
#define CV_STRINGIFY_ARGS_(...) #__VA_ARGS__
100+
96101
#define CV_ENUM(class_name, ...) \
97102
namespace { \
98103
using namespace cv;using namespace cv::cuda; using namespace cv::ocl; \
@@ -101,7 +106,7 @@ class MatType
101106
operator int() const { return val_; } \
102107
void PrintTo(std::ostream* os) const { \
103108
const int vals[] = { __VA_ARGS__ }; \
104-
const char* svals = #__VA_ARGS__; \
109+
const char* svals = CV_STRINGIFY_ARGS(__VA_ARGS__); \
105110
for(int i = 0, pos = 0; i < (int)(sizeof(vals)/sizeof(int)); ++i) { \
106111
while(isspace(svals[pos]) || svals[pos] == ',') ++pos; \
107112
int start = pos; \
@@ -130,7 +135,7 @@ class MatType
130135
void PrintTo(std::ostream* os) const { \
131136
using namespace cv;using namespace cv::cuda; using namespace cv::ocl; \
132137
const int vals[] = { __VA_ARGS__ }; \
133-
const char* svals = #__VA_ARGS__; \
138+
const char* svals = CV_STRINGIFY_ARGS(__VA_ARGS__); \
134139
int value = val_; \
135140
bool first = true; \
136141
for(int i = 0, pos = 0; i < (int)(sizeof(vals)/sizeof(int)); ++i) { \

0 commit comments

Comments
 (0)