2009-10-16 83 views
7

我正在嘗試編寫一些Doxygen註釋塊,並且我想包含示例代碼片段。當然,我希望這些示例能夠真正編譯,以免它們過時。如何在Doxygen註釋中包含.cpp文件的子集?

我example.cpp(即I \包括在.h文件中)看起來是這樣的:

#include "stdafx.h" 

#include "../types_lib/Time_Limiter.h" 
#include <vector> 

void tl_demo() { 
    // scarce will be a gate to control some resource that shouldn't get called 
    // more than 10 times a second 
    Time_Limiter scarce (10); 

    // here's a bunch of requests 
    std::vector<int> req (500); 

    for (size_t i=0;i<req.size();i++) { 
     scarce.tick(); 
     // once we get here, we know that we haven't ticked 
     // more than 10 times in the last second. 

     // do something interesting with req[i] 
    } 
} 

// endcode 

,我的頭文件(即我運行Doxygen的)看起來是這樣的:

/** 
* \ingroup types_lib 
* 
* \class Time_Limiter 
* 
* \brief Thread safe gate used to control a resource (such as an internet quote service) that has a limit on how often you can call it. 
* 
* \dontinclude Time_Limiter_example.cpp 
* \skipline void 
* \until endcode 
* 
**/ 

我想讓doxygen只包含從「void demo」開始到文件末尾(但沒有// endcode)的東西。

我試過用\ dontinclude和\ skip,\ skipline和\試驗,直到我不能完全弄清楚正確的咒語。

編輯:包括我的.h文件,現在我幾乎得到正確的咒語。這是幾乎正是我想要的,有沒有一種方法來使用\直到沒有標籤,並擺脫最後一個//從example.cpp endcode行?

+0

您是否正確設置了doxyfile中的EXAMPLE_PATH? – 2009-10-16 17:56:25

+0

是的。包含的文本,我只是想找出一些咒語,所以我不必在開始時看到三個#includes。 – 2009-10-16 17:59:09

+0

而你在http://www.stack.nl/~dimitri/doxygen/commands.html#cmddontinclude上看到了這個例子嗎? – 2009-10-16 18:05:26

回答

2

編輯追加第二ARG夾宏。

這是我所做的,這似乎爲我工作。從提示從EricM ....

大多采取我的源文件Time_Limiter_example.cpp是:

#include "stdafx.h" 

#include "../types_lib/Time_Limiter.h" 
#include <vector> 

void tl_demo() { 
    // scarce will be a gate to control some resource that shouldn't get called 
    // more than 10 times a second 
    Time_Limiter scarce (10); 

    // here's a bunch of requests 
    std::vector<int> req (500); 

    for (size_t i=0;i<req.size();i++) { 
     scarce.tick(); 
     // once we get here, we know that we haven't ticked 
     // more than 10 times in the last second. 

     // do something interesting with req[i] 
    } 
} // endcode 

void tl_demo_short() 
{ 
} //endcode 

而且我想包括它,但沒有在頂部的#includes。

我在我的Doxyfile定義的別名爲:

ALIASES += clip{2}="\dontinclude \1 \n \skipline \2 \n \until endcode" 

而且在我的頭,我的意見是這樣的:

/** 
* \ingroup types_lib 
* 
* \class Time_Limiter 
* 
* \brief Thread safe gate used to control a resource (such as an internet quote service) that has a limit on how often you can call it. 
* 
* \clip{Time_Limiter_example.cpp,tl_demo} 
**/ 

而這不正是我想要的,包括剛纔的功能可按.cpp文件中的tl_demo()。

0

我認爲\verbinclude應該允許你包含一個文件作爲代碼,而不必把// \endcode放在最後一行。

編輯:爲了澄清,我建議你把你想要包含在自己的包含文件中的代碼,並在CPP文件中使用#include,然後在doxygen頭文件中使用\verbinclude

您的源文件看起來像:

#include "stdafx.h" 
#include "../types_lib/Time_Limiter.h" 
#include <vector>  
#include "Time_Limiter_example.inc" 

文件 「Time_Limiter_example.inc」 就可以只包含的代碼示例:

void tl_demo() { 
    // scarce will be a gate to control some resource that shouldn't get called 
    // more than 10 times a second 
    Time_Limiter scarce (10); 

    // here's a bunch of requests 
    std::vector<int> req (500); 

    for (size_t i=0;i<req.size();i++) { 
     scarce.tick(); 
     // once we get here, we know that we haven't ticked 
     // more than 10 times in the last second. 

     // do something interesting with req[i] 
    } 
} 
+0

沒錯,但這並不符合我的要求,即只包含文件的一個子集。 – 2009-10-19 16:17:29

2

一些功能比較強大的是snippet命令。假設你有這樣的功能:

/*[email protected] Factory 
* 
* Creates sthg 
*/ 
sthg* Create(); 

你想添加的文件sthgTests/sthg_factory.cpp的一部分:

  • 編輯sthgTests/sthg_factory.cpp和周圍添加你想要的部分代碼標籤出現在文檔中(使用說叫test_factory標籤)是這樣的:

    //! [test_factory] 
    void test_factory() 
    { 
        // code here 
    } 
    //! [test_factory] 
    
  • 然後利用片段命令這樣:

    /*[email protected] Factory 
    * 
    * Creates sthg 
    * @snippet sthgTests/sthg_factory.cpp test_factory 
    */ 
    sthg* Create(); 
    

這種做法是很容易設置和相當便宜,以保持。