2016-01-02 98 views
0

我有下面的代碼。當使用#define LIST指令時,doxygen會爲Child_ *類生成文檔。使用#include指令時,將忽略Child_ *類的文檔。預處理器#include指令和宏擴展

配置文件也暴露在下面。

問題:如何配置doxygen以使#include指令正常工作?

//  test.cpp 
#include <iostream> 

#define LIST \ 
    TEST(CLASS_A, A) \ 
    TEST(CLASS_B, B) \ 
    TEST(CLASS_C, C) \ 
    TEST(CLASS_D, D) \ 
    TEST(CLASS_E, E) 

class Mother 
{ 

public: 
    void print(void) { std::cout << "Hello\n";} 
}; 

#define TEST(X,Y) class Child_##Y : public Mother {}; 
#include "List.txt" // using #include directive instead of #define LIST 
//LIST 
#undef TEST 

int main(int argc, char * argv[]) 
{ 
    #define TEST(X,Y) Child_##Y My_##X; My_##X.print(); 
    #include "List.txt" // using #include directive instead of #define LIST 
    //LIST 
    #undef TEST 
} 

與 「LIST.TXT」 載:

// List.txt 
TEST(CLASS_A, A) 
TEST(CLASS_B, B) 
TEST(CLASS_C, C) 
TEST(CLASS_D, D) 
TEST(CLASS_E, E) 

我的配置文件:

# Doxyfile 1.8.11 

#--------------------------------------------------------------------------- 
# Project related configuration options 
#--------------------------------------------------------------------------- 
DOXYFILE_ENCODING  = UTF-8 
PROJECT_NAME   = "Test Doxygen" 
PROJECT_NUMBER   = 
PROJECT_BRIEF   = "testing x macro with doxygen" 
PROJECT_LOGO   = 
OUTPUT_DIRECTORY  = doc 
CREATE_SUBDIRS   = NO 
ALLOW_UNICODE_NAMES = NO 
OUTPUT_LANGUAGE  = English 
BRIEF_MEMBER_DESC  = YES 
REPEAT_BRIEF   = YES 
ABBREVIATE_BRIEF  = "The $name class" \ 
         "The $name widget" \ 
         "The $name file" \ 
         is \ 
         provides \ 
         specifies \ 
         contains \ 
         represents \ 
         a \ 
         an \ 
         the 
ALWAYS_DETAILED_SEC = NO 
INLINE_INHERITED_MEMB = NO 
FULL_PATH_NAMES  = YES 
STRIP_FROM_PATH  = 
STRIP_FROM_INC_PATH = 
SHORT_NAMES   = NO 
JAVADOC_AUTOBRIEF  = NO 
QT_AUTOBRIEF   = NO 
MULTILINE_CPP_IS_BRIEF = NO 
INHERIT_DOCS   = YES 
SEPARATE_MEMBER_PAGES = NO 
TAB_SIZE    = 4 
ALIASES    = 
TCL_SUBST    = 
OPTIMIZE_OUTPUT_FOR_C = NO 
OPTIMIZE_OUTPUT_JAVA = NO 
OPTIMIZE_FOR_FORTRAN = NO 
OPTIMIZE_OUTPUT_VHDL = NO 
EXTENSION_MAPPING  = 
MARKDOWN_SUPPORT  = YES 
AUTOLINK_SUPPORT  = YES 
BUILTIN_STL_SUPPORT = NO 
CPP_CLI_SUPPORT  = NO 
SIP_SUPPORT   = NO 
IDL_PROPERTY_SUPPORT = YES 
DISTRIBUTE_GROUP_DOC = NO 
GROUP_NESTED_COMPOUNDS = NO 
SUBGROUPING   = YES 
INLINE_GROUPED_CLASSES = NO 
INLINE_SIMPLE_STRUCTS = NO 
TYPEDEF_HIDES_STRUCT = NO 
LOOKUP_CACHE_SIZE  = 0 
#--------------------------------------------------------------------------- 
# Build related configuration options 
#--------------------------------------------------------------------------- 
EXTRACT_ALL   = YES 
EXTRACT_PRIVATE  = NO 
EXTRACT_PACKAGE  = NO 
EXTRACT_STATIC   = NO 
EXTRACT_LOCAL_CLASSES = YES 
EXTRACT_LOCAL_METHODS = NO 
EXTRACT_ANON_NSPACES = NO 
HIDE_UNDOC_MEMBERS  = NO 
HIDE_UNDOC_CLASSES  = NO 
HIDE_FRIEND_COMPOUNDS = NO 
HIDE_IN_BODY_DOCS  = NO 
INTERNAL_DOCS   = NO 
CASE_SENSE_NAMES  = NO 
HIDE_SCOPE_NAMES  = NO 
HIDE_COMPOUND_REFERENCE= NO 
SHOW_INCLUDE_FILES  = YES 
SHOW_GROUPED_MEMB_INC = NO 
FORCE_LOCAL_INCLUDES = NO 
INLINE_INFO   = YES 
SORT_MEMBER_DOCS  = YES 
SORT_BRIEF_DOCS  = NO 
SORT_MEMBERS_CTORS_1ST = NO 
SORT_GROUP_NAMES  = NO 
SORT_BY_SCOPE_NAME  = NO 
STRICT_PROTO_MATCHING = NO 
GENERATE_TODOLIST  = YES 
GENERATE_TESTLIST  = YES 
GENERATE_BUGLIST  = YES 
GENERATE_DEPRECATEDLIST= YES 
ENABLED_SECTIONS  = 
MAX_INITIALIZER_LINES = 30 
SHOW_USED_FILES  = YES 
SHOW_FILES    = YES 
SHOW_NAMESPACES  = YES 
FILE_VERSION_FILTER = 
LAYOUT_FILE   = 
CITE_BIB_FILES   = 
#--------------------------------------------------------------------------- 
# Configuration options related to the input files 
#--------------------------------------------------------------------------- 
INPUT     = List.txt \ 
         test.cpp 
INPUT_ENCODING   = UTF-8 
FILE_PATTERNS   = 
RECURSIVE    = NO 
EXCLUDE    = 
EXCLUDE_SYMLINKS  = NO 
EXCLUDE_PATTERNS  = 
EXCLUDE_SYMBOLS  = 
EXAMPLE_PATH   = 
EXAMPLE_PATTERNS  = * 
EXAMPLE_RECURSIVE  = NO 
IMAGE_PATH    = 
INPUT_FILTER   = 
FILTER_PATTERNS  = 
FILTER_SOURCE_FILES = NO 
FILTER_SOURCE_PATTERNS = 
USE_MDFILE_AS_MAINPAGE = 
#--------------------------------------------------------------------------- 
# Configuration options related to source browsing 
#--------------------------------------------------------------------------- 
SOURCE_BROWSER   = NO 
INLINE_SOURCES   = NO 
STRIP_CODE_COMMENTS = YES 
REFERENCED_BY_RELATION = NO 
REFERENCES_RELATION = NO 
REFERENCES_LINK_SOURCE = YES 
SOURCE_TOOLTIPS  = YES 
USE_HTAGS    = NO 
VERBATIM_HEADERS  = YES 
CLANG_ASSISTED_PARSING = NO 
CLANG_OPTIONS   = 
#--------------------------------------------------------------------------- 
# Configuration options related to the preprocessor 
#--------------------------------------------------------------------------- 
ENABLE_PREPROCESSING = YES 
MACRO_EXPANSION  = YES 
EXPAND_ONLY_PREDEF  = NO 
SEARCH_INCLUDES  = YES 
INCLUDE_PATH   = . 
INCLUDE_FILE_PATTERNS = 
PREDEFINED    = 
EXPAND_AS_DEFINED  = 
SKIP_FUNCTION_MACROS = NO 
#--------------------------------------------------------------------------- 
# Configuration options related to external references 
#--------------------------------------------------------------------------- 
TAGFILES    = 
GENERATE_TAGFILE  = 
ALLEXTERNALS   = NO 
EXTERNAL_GROUPS  = YES 
EXTERNAL_PAGES   = YES 
PERL_PATH    = /usr/bin/perl 
+0

doxygen是否使用文件名的擴展名來確定它如何處理文件並生成文檔?使用'List.h'而不是'List.txt'是否有所作爲? – Cornstalks

+0

@Cornstalks:我嘗試將List.txt重命名爲List.h或List.def,但沒有成功。我也嘗試過使用txt = C++的EXTENSION_MAPPING規則,但它沒有做任何改變。但是,使用List.h時,它接頭的頭文件是在.cpp文件之前進行預處理的,輸出爲空白(用-d預處理器調試功能可以看到)... – Heyji

回答

0

看來,這個問題已經被問here和答案,提供來自Doxygen manual的spyderfreek是:

...預處理器解析,但實際上在遇到#include時不包含代碼(#include在{...}塊內找到的例外)。

因此,代碼樣本應該是:

#include <iostream> 

#define LIST \ 
    TEST(CLASS_A, A) \ 
    TEST(CLASS_B, B) \ 
    TEST(CLASS_C, C) \ 
    TEST(CLASS_D, D) \ 
    TEST(CLASS_E, E) 

namespace God { 
    class Mother 
    { 

     public: 
      void print(void) { std::cout << "Hello\n";} 
    }; 
} 

#define TEST(X,Y) class Child_##Y : public Mother {}; 
namespace God { 
    #include "List.txt" // using #include directive instead of #define LIST 
    //LIST 
} 
#undef TEST 

int main(int argc, char * argv[]) 
{ 
    #define TEST(X,Y) Child_##Y My_##X; My_##X.print(); 
    #include "List.txt" // using #include directive instead of #define LIST 
//LIST 
    #undef TEST 
} 

其產生所需的文檔。