2012-01-24 26 views

回答

25

您可以將示例源代碼放置在EXAMPLE_PATH下的doxygen配置中定義的特定路徑中,然後使用@example標記插入示例。

Doxygen然後會生成一個包含示例源的額外頁面。它還會從包含示例標籤的類文檔中設置一個鏈接。

另外,如果你想用小的代碼片段,您可以用@code ... @endcode

此文檔中插入它們是在這裏: Doxygen documentation

+0

是我這樣做,但在額外的頁面在.cpp,文件是EM pty:/ –

+0

嗯,doxygen會給出任何警告或錯誤? – John

+0

不,我在示例文件中包含INPUT標籤和標籤EXAMPLE_PATH中包含標籤\示例的文件...不知道最新的錯誤 –

1

我有一些錯誤使用@example在文檔中包含示例文件。這是我使用的解決方法。

examplefile.cs放置在特定於文件夾/項目的示例代碼中。 地方,在Doxygen的EXCLUDE列表文件夾(專家 - >輸入 - > EXCLUDEin Doxygen的GUI前端)和EXAMPLE_PATH(在Doxygen的GUI前端專家 - >輸入 - > EXAMPLE_PATH)

將此代碼塊某處在形成文件的文件(我把它放在文件的例子是在。)

/** @example examplefile.cs 
* A description of the example file, causes the example file to show up in 
* Examples */ 

這將導致該文件中的Doxygen的菜單例子下展現出來,而不是顯示爲項目中的類/文件。

然後記錄您的類/函數:

/** @brief MyClass does something 
* @details I have something more long winded to say about it. See example 
* in examplefile.cs: @include examplefile.cs */ 

這將導致示例文件打印出來,在它的整體的MyClass文檔。

14

另一種方法是使用\snippet命令。

  • 在你的頭文件寫一樣的東西:
\section ex1 Example 
\snippet path_to_test_class/TestClass.cpp TestClass example 
\section ex2 Expected output 
\snippet path_to_test_class/TestClass.cpp TestClass expected output 
  • 在識別TestClass。CPP文件中,有這樣的事:
//! [OptimizeSpeedOnTrackTest example] 
Class c; 
const double res = c.do_something(); 
//! [OptimizeSpeedOnTrackTest example] 
//! [OptimizeSpeedOnTrackTest expected output] 
ASSERT_DOUBLE_EQ(5,res); 
//! [OptimizeSpeedOnTrackTest expected output] 

path_to_test_class必須在你的EXAMPLE_PATH。

這給你以下幾點:

  • 您的例子不只是那裏的文檔:他們提供的測試覆蓋率以及
  • 你的測試運行(&你的編譯器)給你的保險,你的例子實際編譯&運行
  • 它非常非常適合在TDD流程
+0

使用\ snippet正是我需要的。我發現,只要我在要附加\ snippet的元素上包含\簡要描述,就會得到一個沒有代碼的空框。 –

+0

阿!但使用\部分添加標題可以讓我包含\ brief。 –