Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doxygen: How to link to annotated source code?

Tags:

c++

doxygen

I have a very simple example Main.cpp file for my library, and I have a tutorial page for it. The page looks something like this:

/**
 *  @page simpleexample Simple Example
 *
 *  This example shows basic use. It is in \ref simple_example/Main.cpp.
 *
 *  And this is the description of the example.
 */

Now what this does is it replaces the simple_example/Main.cpp reference by a link to that file documentation. I would like it to go directly to the annotated source code.

Is there a way to do it without entirely disabling the per-file documentation? I'd like to have it, but i don't like that people need to click the Main.cpp link and then also the Go to the source code of this file. link once inside. I don't care too much about how the links in the Files section behave, although I'd rather have them go to file documentation, as they do by default.

I don't want to include the source code inside the tutorial page using \example either, as it is already there in small parts which are explained individually.

like image 893
the swine Avatar asked Dec 12 '13 20:12

the swine


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 include a CPP file in doxygen?

In DoxyWizard, go to Expert->Input then scroll down to FILE_PATTERNS . Make sure the . cpp extension is listed. If not, insert it into the list.


2 Answers

I found in my old code that I once used main.c_source to reference the annotated source code (not the documentation!), but testing in now it doesn't work...

The best solution I have for you us a hack. Use HTML to reference the actual .html file of the annotated source.

<A HREF=main_8c_source.html><B> main.c annotated source </B></A>

From my observations Doxygen follows a standard renaming scheme. The "." is change to "_8" consistently, and "_source" is appended to reference the source code. Capitals are consistently changed to lower-case and preceded with an underscore. MyFile.c becomes _my_file_8c

You must also set CREATE_SUBDIRS = NO. If CREATE_SUBDIRS = YES then you can't really be sure which sub-directory the file will be in.

Of course as a hack, you can never be sure if it'll work in the next release. You'll always have to be double checking if it still works. Maybe suggest it to them as a Feature request...

like image 174
Michael Avatar answered Sep 22 '22 05:09

Michael


Instead of redirecting your reader anywhere you could take a different approach and quote the example code in your tutorial automatically using \include or \snippet.

I agree that the two-step effect of \ref is a bit of a faff, but even having a single step to go look at the code separately from the tutorial text breaks the concentration of the reader.

Depending on the volume of code in your 'example' you could either have it inserted into the doxygen output in its entirety with \include or you could quote the key parts in your tutorial page using \snippet. The latter has the advantage that you can do it in parts interspersed by your tutorial text.

Both these have the mixed blessing that the included sample is treated as code. This means that the doxygen comments in the target file will be shown as code rather than as doxygen. This might seem undesirable but it will help make it clear which is tutorial text and which is the example file. (That said, I've only ever used snippet for just quoting real code samples in a tutorial page myself.)

Relevant Doxygen manual section here.

I note you're not wanting to use \example. My approach is slightly different (especially with \snippet), and doesn't create the 'Examples' page. This may still not be what you want, but I offer it here in case it's useful for others anyway.

like image 36
Cheeseminer Avatar answered Sep 21 '22 05:09

Cheeseminer