Doxygen for C++使用說明——注釋代碼一

寫這一節的時候,我在想網上有眾多的參考文獻,外加官網上的,要是我再將它們重復一遍,也沒什么意思。網上資料很多,但是他們有一個共同的缺點是都是羅列用法,然后顯示效果。這些都是比較散的,我想是不是可以結合一個具體的范例來講解Doxygen的用法呢?這樣大家既可以學習到語法,也可以直接拿這個模板來用。
我自己在網上下了個模板,并且加了一些內容。這是顯示效果鏈接。下面我將具體來介紹:
先看test.h.

/*** \mainpage libtest** \section intro_sec oFono telephony client APIs.** This library provides easy to use APIs to use by hiding all details.** \section install_sec Installation** \subsection Download the RPM package** Go to download page to download the RPM package.** \subsection Install** Run the following command in terminal to install:* \code* $rpm -ivh libtest-api.rpm* \endcode** \section usage_sec How to use this library** \subsection source Include in file** To use this library, you must include the headers in your source file:* \code* #include <test.h>* \endcode* If you use other interfaces, you must include it too, like message:* \code* #include <test.h>* #include <test-helper.h>* \endcode** \subsection compile How to compile** To build with this library you can use pkg-config to get link options:* \code* $pkg-config --cflags --libs test-api* \endcode*/
/*** \file test.h* \brief API interface test is in charge of path management** It provides APIs to query path list and to query properties for a specific path.** \note* This interface requirs to run in main loop thread because some GLib dependency.** Besides, you should keep main loop idle for most of times in order to get callbacks and make sure* libtest-api process signals successfully. This means you should put business logic into a separate* thread.*/
#ifndef _TEST_H
#define _TEST_H/*** \enum API_RESULT_CODE Indicating whether API operation succeed or fail.*/
enum API_RESULT_CODE {API_SUCCESS, /**< API call is successfully */API_FAILED, /**< API call is failed */
};/*** \brief Initialize libtest-api.** This function should be the first one to call when using libtest-api. It does essential initializations.* This function is synchronous.** \return #API_RESULT_CODE indicating whether this call success or failed.** \see test_deinit** \par Sample code:* \code* if (test_init() != OFONO_API_SUCCESS) {*     printf("error occurred, failed to init test\n");*     return;* }* // operations goes here* if (test_deinit() != OFONO_API_SUCCESS) {*     printf("failed to deinit \n");*     return;* }* \endcode*/
int test_init();/*** \brief Finalize libtest-api** This function is designated to be called when no longer needs libtest-api to release resources in libtest* and do some finalization.** \note* It is an error to call any APIs after calling test_deinit()** \return #API_RESULT_CODE indicating whether this call success or failed.** \see test_init*/
int test_deinit();/*** \brief Obtain current list of path ** \param [out] paths a pointer to an array of strings* \param [out] count indicating the count of path.** \note* This function will allocate memory for path array. So caller must free the array, but should not free each item.** \return #API_RESULT_CODE indicating whether this call success or failed.** \par Sample code:* \code*    char **path = NULL;*    int count = 0;*    test_get_paths(&path, &count);*    // use the path*    free(path);*    path = NULL;* \endcode*/
int test_get_paths(char ***paths, int *count);#endif

以上為代碼,下面我們將具體說說。

\mainpage

一般我們為一個C++項目建立一個說明文檔,首先應該有個總的項目說明,簡要介紹項目的背景、安裝路徑、使用方法等。這時我們可以在\mainpage中完成。它的語法為:
用法:

\mainpage [(title)]

Qt風格)示例:

/*! \mainpage My Personal Index Page** \section intro_sec Introduction** This is the introduction.** \section install_sec Installation** \subsection step1 Step 1: Opening the box** etc...*/

查看效果。
效果與上一模一樣的(JavaDoc風格)的代碼如下:

/** \mainpage My Personal Index Page** \section intro_sec Introduction** This is the introduction.** \section install_sec Installation** \subsection step1 Step 1: Opening the box** etc...*/

最上面我們給的源碼實際上使用的是JavaDoc風格。
一般, JavaDoc以兩個**開頭:

/*** ... text ...*/

Qt 風格以*!開頭

/*!* ... text ...*/

兩種用法,注釋塊中間的星號是可選, 所以將注釋塊寫成:

/*!... text ...
*/

\section

用法:

\section <section-name> (section title)

說明:
section-name為索引名,section title為章節的標題
我們再介紹一個和\mainpage相似的概念。

\page

用法:

\page <name> (title)

示例:

/*! \page page1 A documentation page\tableofcontentsLeading text.\section sec An example sectionThis page contains the subsections \ref subsection1 and \ref subsection2.For more info see page \ref page2.\subsection subsection1 The first subsectionText.\subsection subsection2 The second subsectionMore text.
*//*! \page page2 Another pageEven more info.
*/

查看效果。
注意:里面的 \ref 是索引的意思。

\code

用法:

 \code [ '{'<word>'}']

示例:

\code{.py}class Python:pass\endcode\code{.cpp}class Cpp {};\endcode

\brief

用法:

/*! \brief Brief description.**  Detailed description starts here.*/

如果JAVADOC_AUTOBRIEF 被設置為 YES,則JavaDoc風格將注釋塊中的第一個句子視為簡要描述, 這個句子可以以句號’.’、空格或者空行來結束:
用法:

/** Brief description which ends at this dot. Details follow*  here.*/

類的注釋

如下為使用Qt風格的C++代碼注釋。

//!  A test class. 
/*!A more elaborate class description.
*/
class Test
{public://! An enum./*! More detailed enum description. */enum TEnum { TVal1, /*!< Enum value TVal1. */  TVal2, /*!< Enum value TVal2. */  TVal3  /*!< Enum value TVal3. */  } //! Enum pointer./*! Details. */*enumPtr, //! Enum variable./*! Details. */enumVar;  //! A constructor./*!A more elaborate description of the constructor.*/Test();//! A destructor./*!A more elaborate description of the destructor.*/~Test();//! A normal member taking two arguments and returning an integer value./*!\param a an integer argument.\param s a constant character pointer.\return The test results\sa Test(), ~Test(), testMeToo() and publicVar()*/int testMe(int a,const char *s);//! A pure virtual member./*!\sa testMe()\param c1 the first argument.\param c2 the second argument.*/virtual void testMeToo(char c1,char c2) = 0;//! A public variable./*!Details.*/int publicVar;//! A function variable./*!Details.*/int (*handler)(int a,int b);
};

查看效果。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/259095.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/259095.shtml
英文地址,請注明出處:http://en.pswp.cn/news/259095.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

DevOps的前世今生

2019獨角獸企業重金招聘Python工程師標準>>> 目前在國外&#xff0c;互聯網巨頭如Google、Facebook、Amazon、LinkedIn、Netflix、Airbnb&#xff0c;傳統軟件公司如Adobe、IBM、Microsoft、SAP等&#xff0c;亦或是網絡業務非核心企業如蘋果、沃爾瑪、索尼影視娛樂…

【轉】最牛B的編碼套路

最近&#xff0c;我大量閱讀了Steve Yegge的文章。其中有一篇叫“Practicing Programming”&#xff08;練習編程&#xff09;&#xff0c;寫成于2005年&#xff0c;讀后令我驚訝不已&#xff1a; 與你所相信的恰恰相反&#xff0c;單純地每天埋頭于工作并不能算是真正意義上的…

ecshop 廣告設置

最近公司準備做個商城&#xff0c;讓我從JAVA轉過去&#xff0c;好吧&#xff0c;先看下吧&#xff0c;反正也得做。接到手里的是一套已經成型的模板&#xff0c;但是二次開發必須得了解下機制、文件、響應、設置什么的&#xff0c;也是個新手&#xff0c;寫點東西給后面更新的…

linux 信號_Linux信號機制

信號就是一條消息&#xff0c;通知進程系統中發生了什么事&#xff0c;每種信號都對應著某種系統事件。一般的底層硬件異常是由內核的異常處理程序處理的&#xff0c;它對用戶進程來說是透明的。而信號機制&#xff0c;提供了一種方法通知用戶進程發生了這些異常。例如&#xf…

DOxygen for C++使用說明——添加數學公式

公式 Doxygen允許你把 公式顯示在最終的輸出中&#xff08;這個功能僅限于HTML和輸出&#xff09;.為了可以在HTML documentation顯示公式&#xff08;轉化為圖片&#xff09;&#xff0c;你必須安裝以下軟件&#xff1a; latex: 編譯器, 被用來解析公式, 首先提取公式寫到一…

VC2010下Qt5的中文亂碼問題

要搞清楚這個問題&#xff0c;先要弄明白編碼。但是編碼問題實在太復雜&#xff0c;這里肯定講不開。 我先找一個例子&#xff0c;比如&#xff1a;“中文” 的 Unicode 碼點/UTF8編碼/GBK 分別是多少。 先去這個網站&#xff0c;輸入 “中文” 查詢對應的 Unicode 碼點/UTF8編…

Tomcat 的 DefaultServlet

問題描述&#xff1a; 群里有人測試 Spring MVC&#xff0c;沒有配置任何Controller&#xff0c;只配置了一個view resolver&#xff0c;指定了前綴后綴。 然后&#xff0c;他問的是 當訪問 localhost:8080/test 的時候&#xff0c;為什么會被重定向到 localhost:8080/test/ &a…

Python學習(七)面向對象 ——封裝

Python 類的封裝 承接上一節&#xff0c;學了Student類的定義及實例化&#xff0c;每個實例都擁有各自的name和score。現在若需要打印一個學生的成績&#xff0c;可定義函數 print_score() 該函數為類外的函數&#xff0c;如下&#xff1a; 1 class Student(object):2 def …

spss練習數據_SPSS篇——如何在成千上百萬個數據中標識重復個案

本文就帶大家來學習一個小技巧&#xff0c;如何運用SPSS標識重復個案。我們都知道在Excel中&#xff0c;通常會用到“篩選”功能來選出指定條件相同的單元格。那么在SPSS中&#xff0c;如何在成千上百萬個數據中篩選出重復的個案呢&#xff1f; 小編就是要告訴你&#xff0c;幾…

DOxygen for C++使用說明——Markdown支持

自Doxygen 版本1.8.0&#xff0c;Markdown被引進。 接下來&#xff0c;我們將先簡單介紹標準的Markdown語法&#xff0c;讀者可以進入Markdown官網查詢更詳細的細節。然后討論一下Doxygen支持的Markdown擴展&#xff0c;最后討論一下Doxygen對Markdown標準的實現細節。 Stand…

方程式漏洞之復現window2008/win7 遠程命令執行漏洞

前幾天就想寫的&#xff0c;因為一些緣故就沒寫。此次是在外網環境下進行的。大家在內網中也一個樣。 方法&#xff1a; 使用Eternalblue模塊&#xff0c;劍測是否有漏洞然后msf生成一個dll直接反彈shell. PS&#xff1a;win版本的不知道緣何生成出來的dll是0kb 我就在自己本地…

C++空類和string類

1. 空類 1.1 空類默認哪六個成員函數。 1 class Empty2 {3 public:4 Empty(); //缺省構造函數 Empty e;5 Empty( const Empty& ); //拷貝構造函數 Empty e2(e1);6 ~Empty(); //析構函數7 Empty& operator( const Empty& ); //賦值運算符…

客服會話 小程序 如何發起_小程序、公眾號、App三者如何融合布局?這里有一份避坑指南...

對產品經理來說&#xff0c;小程序無疑是2020年最火爆的詞之一了。我們能看到&#xff0c;就在今年疫情期間&#xff0c;小程序DAU達到4.5億&#xff0c;而超市、生鮮果蔬、社區購物等都同比增長100個點左右&#xff0c;小程序的商業價值很明顯地在快速釋放。小程序如此火爆&am…

DOxygen for C++使用說明——注釋代碼二

這一次我在谷歌搜索中檢索到了Doxygen在github的倉庫&#xff0c;進去一看&#xff0c;令人大喜&#xff0c;github倉庫里含有了一個Doxygen的官方配置文件Doxyfile,于是下載下來&#xff0c;發現Doxyfile已經配置了將倉庫中的\src文件編譯成Documentation,并且將結果放在了dox…

python super()(轉載)

一、問題的發現與提出 在Python類的方法&#xff08;method&#xff09;中&#xff0c;要調用父類的某個方法&#xff0c;在Python 2.2以前&#xff0c;通常的寫法如代碼段1&#xff1a; 代碼段1&#xff1a; class A:def __init__(self):print "enter A"print "…

Swagger+Spring mvc生成Restful接口文檔

2019獨角獸企業重金招聘Python工程師標準>>> Swagger 是一個規范和完整的框架&#xff0c;用于生成、描述、調用和可視化 RESTful 風格的 Web 服務。總體目標是使客戶端和文件系統作為服務器以同樣的速度來更新。文件的方法&#xff0c;參數和模型緊密集成到服務器端…

JavaScript——變量與基本數據類型

前言 JavaScript中的變量為松散類型&#xff0c;所謂松散類型就是指當一個變量被申明出來就可以保存任意類型的值&#xff0c;就是不像SQL一樣申明某個鍵值為int就只能保存整型數值&#xff0c;申明varchar只能保存字符串。一個變量所保存值的類型也可以改變&#xff0c;這在Ja…

vscode可以打開jupyternotebook嗎_剛剛,官方宣布 VS Code 支持 Python 全開發了!

關注Python高校每天早上23:10準時推送北京時間 2019 年 9 月 21 日&#xff0c;PyCon China 2019 在上海舉行。在下午的演講中&#xff0c;來自微軟開發工具事業部的資深研發工程師韓駿做了主題為《Python 與 Visual Studio Code 在人工智能應用中的最佳 Azure 實踐》的演講。在…

C++類的內聯成員函數應放在哪

今天復習C Primer的時候&#xff0c;看到了關于C類的內聯成員函數的放置&#xff0c;應該放在頭文件中。那么這到底是為什么 呢&#xff1f;僅僅是一種代碼規范問題還是必須這樣做呢&#xff1f; 下面我就來講講我自己的理解吧。要徹底理解這個問題&#xff0c;首先就要了解下函…

python selenium自動化(三)Chrome Webdriver的兼容

當一個自動化測試被實現在一個瀏覽器之后&#xff0c;我們會希望我們的測試能夠覆蓋到盡量多的別的瀏覽器。通過跨平臺的測試來保證我們的程序在多個瀏覽器下都能正常工作。 在安裝了selenium之后&#xff0c;firefox webdriver和IE webdriver就已經是ready to use的了&#xf…