开发者

Doxygen: strip top level namespace

开发者 https://www.devze.com 2023-03-22 11:11 出处:网络
When working with library ABC, it natural that all names are included into the same top level namespace. Is it possible to remove top level namespace from class nam开发者_JAVA技巧es, but show inclosed

When working with library ABC, it natural that all names are included into the same top level namespace. Is it possible to remove top level namespace from class nam开发者_JAVA技巧es, but show inclosed namespaces?


There is no such option inside of Doxygen. Still you can use preprocessor to make it work.

#ifndef DOXY_PARSER
    #define LIB_NAMESPACE_STARTS namespace lib_namespace { /##/
    #define LIB_NAMESPACE_ENDS } /##/
    #define LIB_NAMESPACE lib_namespace
#else
    #define LIB_NAMESPACE_STARTS /##/
    #define LIB_NAMESPACE_ENDS /##/
    #define LIB_NAMESPACE
#endif

You should include this code into some common header and set predefined DOXY_PARSER macro in Doxygen options. This workaround makes using of library namespace less convenient but it is not so crucial.

LIB_NAMESPACE_STARTS();
    namespace internal_namespace {
        struct Trololo {};
    }
    LIB_NAMESPACE::internal_namespace::Trololo T;
LIB_NAMESPACE_ENDS();


There is a general problem with the previous solution, it is not valid when using Qt. The moc'ing process doesn't use the preprocessor and the namespace is not used (leading to a compile time error).

One possible solution would be to use a #define QT_NAMESPACE lib_namespace but it will move the whole Qt to that namespace.

The next solution is more general (I've kept the macros name for convenience):

#ifndef DOXY_PARSER
    #define LIB_NAMESPACE lib_namespace
    #define LIB_NAMESPACE_STARTS namespace LIB_NAMESPACE { /##/
    #if (defined MOCED_FILE)
        #define LIB_NAMESPACE_ENDS } using namespace LIB_NAMESPACE; /##/
    #else
        #define LIB_NAMESPACE_ENDS } /##/
    #endif
    #define USING_LIB_NAMESPACE using namespace LIB_NAMESPACE; /##/
#else
    #define LIB_NAMESPACE_STARTS /##/
    #define LIB_NAMESPACE_ENDS /##/
    #define LIB_NAMESPACE
    #define USING_LIB_NAMESPACE /##/
#endif

Where MOCED_FILE is a define exclusive for mocs. If you are using CMake, you can specify such option using:

QT4_WRAP_CPP(mocSources qt_file1.h qt_file2.h)
SET_SOURCE_FILES_PROPERTIES(${mocSources} PROPERTIES COMPILE_FLAGS "-DMOCED_FILE")
0

精彩评论

暂无评论...
验证码 换一张
取 消