Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate examples with Doxygen? [closed]

I documented all of my classes and now I want to integrate an example of how to use these classes. How do I do that?

like image 1000
Tobi Weißhaar Avatar asked Jan 24 '12 10:01

Tobi Weißhaar


People also ask

How do I enter a code on doxygen?

You can put example source code in a special path defined in the doxygen config under EXAMPLE_PATH , and then insert examples with the @example tag. Doxygen will then generate an extra page containing the source of the example. It will also set a link to it from the class documentation containing the example tag.

How do I exclude a file in doxygen?

How can I make doxygen ignore some code fragment? The new and easiest way is to add one comment block with a \cond command at the start and one comment block with a \endcond command at the end of the piece of code that should be ignored. This should be within the same file of course.

What does @{ mean in doxygen?

Doxygen will put members into the group whose definition has the highest "priority": e.g. An explicit \ingroup overrides an implicit grouping definition via @{ @} . Conflicting grouping definitions with the same priority trigger a warning, unless one definition was for a member without any explicit documentation.


2 Answers

You can put example source code in a special path defined in the doxygen config under EXAMPLE_PATH, and then insert examples with the @example tag.

Doxygen will then generate an extra page containing the source of the example. It will also set a link to it from the class documentation containing the example tag.

Alternatively if you want to use small code snippets you can insert them with @code ... @endcode

The documentation for this is here: doxygen documentation?

like image 128
Loebl Avatar answered Sep 19 '22 14:09

Loebl


Another way of doing it is to use the \snippet command.

  • In your header file write something like:
\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 
  • In the TestClass.cpp file, have something like:
 //! [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 must be in your EXAMPLE_PATH.

This gives you the following:

  • Your examples aren't just there for documentation: they provide test coverage as well
  • Your test runner (& your compiler) give you the insurance that your examples actually compile & run
  • It fits in pretty nicely in a TDD workflow
like image 45
Deimos Avatar answered Sep 16 '22 14:09

Deimos