University of Leeds

Example

Doxygen Commands

For the report to be generated, we need to include specially formatted comments in our source code. A Doxygen comment block is start by /**. We usually just document the class header file as this contains the methods contained in the class. The example below is for the Circle class developed earlier in the module.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef CIRCLE_H
#define CIRCLE_H

#define PI 3.14159265

/** Circle class

@brief Class for calculating the area of a circle

@version 1.0

@author Dr Craig A. Evans

@date November 2018

@code

#include <iostream>
// include the class header file in main
#include "Circle.h"

int main() {
  std::cout << "Enter circle radius (in metres): ";
  float radius;
  std::cin >> radius;
  // create a circle object and use the public methods
  Circle circle;
  circle.set_radius(radius);
  float area = circle.get_area();
  std::cout << "The circle has an area of " << area << " m^2.\n";
  return 0;
}

@endcode
*/
class Circle {
 public:
  /** 
  * @brief Sets the radius
  * @param radius @details Radius of the circle in metres
  */
  void set_radius(float radius);
  /** 
  * @brief Gets the area
  * @returns the area of the circle (in metres squared)
  */
  float get_area();
 private:
  float _radius;
  float _area;
};

#endif

Note the Doxygen commands start with an @ sign. Directly above the class definition, we include a Doxygen comment block and use it to specify the brief, version, author and date. We can also include some example code between the @code and @endcode tags.

Then for each method in the class, we create a Doxygen comment block and use it to specify a brief, list the parameters (arguments) and any return values. The brief is meant to be brief i.e. a few words. More details can be included using the @details tags.

Output

Once the code is commented using the Doxygen commands, the output can be generated. The output of the example above is here.