Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documenting a C++ concept using doxygen? [closed]

Is there a convenient way to document a C++ concept in doxygen? I would like to have some kind of documentation like this in the boost documentation.

like image 220
proto Avatar asked Apr 10 '12 10:04

proto


People also ask

What is doxygen comments in C?

From the Doxygen www site: "Doxygen is the de facto standard tool for generating documentation from annotated C++ sources, but it also supports other popular programming languages such as C, Objective-C, C#, PHP, Java, Python, IDL (Corba and Microsoft flavors), Fortran, VHDL, Tcl, and to some extent D."

Can doxygen generate Markdown?

Description. This is a command line tool that converts Doxygen generated XML files into markdown files (or JSON). You can use the generated Markdown files to create beautiful C++ documentation using with MkDocs, GitBook, VuePress, Hugo, Docsify, or any other static site generator that supports markdown.

How exclude code from 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.


4 Answers

After some struggling with Doxygen, I finally came to the following solution.

  1. Define a group for your concept: using pages is not that appropriate since a page should indicate its subpages (from top to bottom of the tree), while groups indicate potentially many parents groups. This allows:

    • Adding a concept to one (or more) parent concept(s), without changing the parent concept itself (refinement/generalization of concepts)
    • Linking an entity to several concepts, without changing the concept itself (eg. when adding a class to the library implementing a specific concept)

    Example

    /*!@defgroup measurement_functor_concepts Measurement function objects
     * @ingroup generalconcepts
     * @{
     * @par Description
     * blablabla
     *
     * @par Notations
     * Let @c F be the type of the function object, @c f an instance.
     *
     * @par Valid Expressions
     * - @c f function object is ...
     * - <b>f.result()</b> returns ...
     * @}
     */
    
  2. Define a custom command concept with one argument:

    ALIASES += concept{1}="@ingroup \1\n@par Implemented concepts:\n@ref \1"
    

    The command:

    • includes the entity into the group defining the concept: the entity will appear in the documentation of the concept (the entity may appear in several groups)
    • adds a paragraph with Implemented concepts providing a link to the implemented concept.
  3. Indicate that a particular class/struct implements the concept:

    //!@brief Does things...
    //!@concept{measurement_functor_concepts}
    template <class T>
    struct my_struct: public std::unary_function<T, void> {};
    

I did not find a way to generate a nice documentation like in Boost (nice tables for the valid expression, etc), but at least this organization of the documentation separates things properly.

like image 182
Raffi Avatar answered Nov 16 '22 17:11

Raffi


What you can do is define a custom tag called Concept, which you can then use as you describe. An example of this is to use the alias mechanism in Doxygen, something like:

ALIASES += "con=\xrefitem con \"Concept\" \"Concepts\" "

like image 29
JadziaMD Avatar answered Nov 16 '22 15:11

JadziaMD


You can use \tparam to comment/document on template parameters.

like image 2
Attila Avatar answered Nov 16 '22 17:11

Attila


I currently use separate manual pages to document concepts and group the with \section and \subsection. I can then link to them with \ref. This works as long as you describe concepts with tables as in the link you gave, but unfortunately will not enable links to single sections.

I also have an alias to create a list of concepts that a type models.

like image 1
pmr Avatar answered Nov 16 '22 16:11

pmr