mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 11:45:30 +08:00
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.
This commit is contained in:
parent
f935a16ef2
commit
19538cac1e
@ -93,6 +93,11 @@ private:
|
||||
* CV_ENUM and CV_FLAGS - macro to create printable wrappers for defines and enums *
|
||||
\*****************************************************************************************/
|
||||
|
||||
// helper macros to force expansion of macro arguments before stringification
|
||||
// "#" normally blocks argument expansion
|
||||
#define CV_STRINGIFY_ARGS(...) CV_STRINGIFY_ARGS_(__VA_ARGS__)
|
||||
#define CV_STRINGIFY_ARGS_(...) #__VA_ARGS__
|
||||
|
||||
#define CV_ENUM(class_name, ...) \
|
||||
namespace { \
|
||||
using namespace cv;using namespace cv::cuda; using namespace cv::ocl; \
|
||||
@ -101,7 +106,7 @@ private:
|
||||
operator int() const { return val_; } \
|
||||
void PrintTo(std::ostream* os) const { \
|
||||
const int vals[] = { __VA_ARGS__ }; \
|
||||
const char* svals = #__VA_ARGS__; \
|
||||
const char* svals = CV_STRINGIFY_ARGS(__VA_ARGS__); \
|
||||
for(int i = 0, pos = 0; i < (int)(sizeof(vals)/sizeof(int)); ++i) { \
|
||||
while(isspace(svals[pos]) || svals[pos] == ',') ++pos; \
|
||||
int start = pos; \
|
||||
@ -130,7 +135,7 @@ private:
|
||||
void PrintTo(std::ostream* os) const { \
|
||||
using namespace cv;using namespace cv::cuda; using namespace cv::ocl; \
|
||||
const int vals[] = { __VA_ARGS__ }; \
|
||||
const char* svals = #__VA_ARGS__; \
|
||||
const char* svals = CV_STRINGIFY_ARGS(__VA_ARGS__); \
|
||||
int value = val_; \
|
||||
bool first = true; \
|
||||
for(int i = 0, pos = 0; i < (int)(sizeof(vals)/sizeof(int)); ++i) { \
|
||||
|
Loading…
Reference in New Issue
Block a user