Generate doc only for some member functions - c++

I have a project which contains an RPC-invokable API. The project also contains some other code. I'd like to generate a clean documentation just for these API functions (for users working with the API). Yet it should still be possible to generate a documentation of the whole program, intended for the developers.
The API is split into several classes ("command modules"). First thing I did is tell Doxygen to only look at those files, of course. But these classes also have some code which is not part of the API I'd like to generate the documentation for (helper functions).
These invokable functions ("commands") have a special return type: CommandResult.
As an example, here is such an API class:
class CommandModuleFoo {
int privateHelperFunction();
int privateMember;
public:
int publicHelperFunction();
int publicMember;
public slots:
/** Some documentation. */
CommandResult myFunction1(int someArg);
/** Some documentation. */
CommandResult myFunction2();
};
Now the documentation should basically contain the following:
class CommandModuleFoo
Public members:
CommandResult myFunction1(int someArg)
Some documentation.
CommandResult myFunction2()
Some documentation.
Question:
I know that I can select only a subset of the project's files by simply just naming them in the INPUT variable of my Doxyfile. But can I also select only a set of functions using a pattern?
Since I guess this is not possible, can I tell Doxygen to only generate documentation for one section? Doxygen has section markers: \if...\endif can be used to exclude some part of the document but include them with the configuration variable ENABLED_SECTIONS. But I need the opposite. Is there something like ONLY_SECTION?
Possible workarounds:
I could use above-mentioned section conditions around every code except the commands I want to document. But that sounds very ugly.
I could set HIDE_UNDOC_MEMBERS to YES in order to only generate documentation for documented members, but that would make it impossible to generate also a full documentation of the program, if one wants to. (i.e. it forbids to document non-API functions). Also, detecting undocumented API-functions is then more difficult.
I currently use the second workaround.

You could do the following:
Use \internal in the documentation of internal functions (the non-commands in this case):
/**
* \internal
* This helper function does foo.
*/
void myHelperFunction();
Your commands use normal doxygen comments:
/**
* Some documentation.
*/
CommandResult myFunction();
Then, in your Doxyfile use INTERNAL_DOCS = YES if you compile the documentation of the whole program and INTERNAL_DOCS = NO (default) to compile your API documentation.
Basically, treat your program like it was a library. Library developers often encounter this problem: they obviously want to have a clean documentation for the users of the library which only contains exported stuff, while they (probably) also want to have a more verbose documentation for developers of the library.
PS. You can also use \internal to selectively include paragraphs of the documentation of a function, i.e. your documentation for the developers could include some more detail which is not important for the users of your API. For details consult the documentation of \internal.

Related

How to automate M2Doc generation including the settings?

I've applied the guidance on programmatic usage of M2Doc (also with this help) to successfully generate a document via the API, which was previously prepared by using the M2Doc GUI (configured .docx plus a .genconf file). It seems to also work with a configured .docx, but without a .genconf file.
Now I would like to go a step further and ease the user interface in our application. The user should come with a .docx, include the {m:...} fields there, especially for variable definition, and then in our Eclipse application just assign model elements to the list of variables. Finally press "generate". The rest I would like to handle via the M2Doc API:
Get list of variables from the .docx
Tell M2Doc the variable objects (and their types and other required information, if that is separately necessary)
Provide M2Doc with sufficient information to handle AQL expressions like projectmodel::PJDiagram.allInstances() in the Word fields
I tried to analyse the M2Doc source code for this, but have some questions to achieve the goal:
The parse/generate API does not create any config information into the .docx or .genconf files, right? What would be the API to at least generate the .docx config information?
The source code mentions "if you are using a Generation" - what is meant with that? The use of a .genconf file (which seems to be optional for the generate API)?
Where can I get the list of variables from, which M2Doc found in a .docx (during parse?), so that I can present it to the user for Object (Model Element) assignment?
Do I have to tell M2Doc the types of the variables, and in which resource file they are located, besides handing over the variable objects? My guess is no, as using a blank .docx file without any M2Doc information stored also worked for the variables themselves (not for any additional AQL expressions using other types, or .oclAsType() type castings).
How can I provide M2Doc with the types information for the AQL expressions mentioned above, which I normally tell it via the nsURI configuration? I handed over the complete resourceSet of my application, but that doesn't seem to be enough.
Any help would be very much appreciated!
To give you an impression of my code so far, see below - note that it's actually Javascript instead of Java, as our application has a built-in JS-Java interface.
//=================== PARSING OF THE DOCUMENT ==============================
var templateURIString = "file:///.../templateReqs.docx";
var templateURI = URI.createURI(templateURIString);
// canNOT be empty, as we get nullpointer exceptions otherwise
var options = {"TemplateURI":templateURIString};
var exceptions = new java.util.ArrayList();
var resourceSetForModels = ...; //here our application's resource set for the whole model is used, instead of M2Doc "createResourceSetForModels" - works for the moment, but not sure if some services linking is not working
var queryEnvironment = m2doc.M2DocUtils.getQueryEnvironment(resourceSetForModels, templateURI, options);
var classProvider = m2doc.M2DocPlugin.getClassProvider();
// empty Monitor for the moment
var monitor = new BasicMonitor();
var template = m2doc.M2DocUtils.parse(resourceSetForModels.getURIConverter(), templateURI, queryEnvironment, classProvider, monitor);
// =================== GENERATION OF THE DOCUMENT ==============================
var outputURIString = "file:///.../templateReqs.autogenerated.docx";
var outputURI = URI.createURI(outputURIString);
variables["myVar1"] = ...; // assigment of objects...
m2doc.M2DocUtils.generate(template, queryEnvironment, variables, resourceSetForModels, outputURI, monitor);
Thanks!
No the API used to parse an generate don't modifies the template file nor the .genconf file. To modify the configuration of the template you will need to use the
TemplateCustomProperties class. That will allow you to register your metamodels and service classes. This instormation is then used to configure the IQueryEnvironment, so you might also want to directly configure the IQueryEnvironment in your code.
The generation in this context referes to the .genconf file. Note The genconf file is also an EMF model, so you can also craft one in memory to launch you generation if it's easier for you. But yes the use of a .genconf file is optional like in your code example.
To the list of variables in the template you can use the class TemplateCustomProperties:
TemplateCustomProperties.getVariables() will list the variables that are declared with their type
TemplateCustomProperties.getMissingVariables() to list varaibles that are used in the template but not declared
You can also find le list of used metamodels (EPackage nsURIs) and imported services classes.
The type of variables is not needed at generation time, it's only needed if you want to validate your template. At generation time you need to pass a map from the variable name to its value as you did in your example. The value of a variable can be a any object from your model (an EObject), a String, an Integer, ... If you want to use something like oclIsKindOf(pkg::MyEClass) you will need to register the nsURI of pkg first see the next point.
The code you provided should let you use something like projectmodel::PJDiagram.allInstances(). This service needs a ResourceSetRootEObjectProvider() that is initialized in M2DocUtils.getQueryEnvironment(). But you need to declare the nsURI of your metamodel in your template (see TemplateCustomProperties). This will register it in the IQueryEnvironment. You can also register it yourself using IQueryEnvironment.registerEPackage().
This should help you finding the missing parts in the configuration of the AQL environment. Your code seems good and should work when you add the configuration part.

How to add documentation to the class description from a comment within a function in doxygen?

When using C++ with doxygen I would like to add to the class description from within a function. I basically want to add information about the function calls I am making.
class_name.h
/**
* This is the overall description of the class
*/
class ClassName
{
...
}
class_name.cpp:
void ClassName::randomFunction()
{
/**
* #class ClassName
*
* calls testData on stuff (this should be appended to the class description)
*/
testData(stuff);
}
Doxygen output:
<b>Detailed Description</b>
<br>
This is the overall description of the class
<br>
calls testData on stuff
This method works when I put the comment outside of a function, but does not show up anywhere if I put it within randomFunction as the example shows. In the end, I would like the reader of the documentation to see a description of the class followed by the snippet that I have in the example. This makes it easier to keep my documentation in sync with the code and immediately tells the user about important functions that I am calling.
The reason I want to do this is to document the network messages that the class makes in one place instead of having the user search through documentation on multiple member functions.
EDIT:
doxygen version is 1.8.5
added clarification
The used version of doxygen (1.8.5, August 23, 2013) is a bit old and it is advised to update to the current version (1.8.17).
To have code snippets or documentation snippets in an other place as well doxygen has the command \snippet (see http://doxygen.nl/manual/commands.html#cmdsnippet).
To group information in different places doxygen has grouping commands like \defgroup (http://doxygen.nl/manual/commands.html#cmddefgroup), \ingroup (http://doxygen.nl/manual/commands.html#cmdingroup), \addtogroup (http://doxygen.nl/manual/commands.html#cmdaddtogroup).
See also the grouping chappetr in the doxgen documentation (http://doxygen.nl/manual/grouping.html).

How to insert the project name in a comment in doxygen?

I often use the project name in comments I write. However, up until now I hardcoded it. Now I realized that if the project name were to change, I would have to go through all the documentation parts and change it. Therefore, I wanted to ask if it is possible to simply reference the project name in the comment and let doxygen fill it out later.
/*! \brief This is the main function of the (project_name) project
*/
int main()
{
return 0;
}
I think what you are looking for is environment variables, which you can read about here.
The one you are looking for should be $(PROJECT_NAME).
To use it, see this answer.

Documenting Unit Tests in line with code

I'm trying to use doxygen to document my unit tests, but I'd like to document them in-line with the code instead of in the test header to reduce copy/paste errors when making similar tests. Of note, I'm using the RTF output format.
/** #brief A method for testing doxygen method documentation
* #test
* -#Step 1
* -#Step 2
* -#Step 3
*/
[TestMethod()]
public void DoxygenScratchPadInHeader()
{
// code that may or may not be in sync with header
}
/** #brief A method for testing doxygen method documentation
* #test
*/
[TestMethod()]
public void DoxygenScratchPadInLine()
{
/// #par
/// -# Initialize the value to 0
int i = 0;
/// #par
/// -# Add a number
i += 3;
/// #par
/// -# Assert that the number is three
Assert.AreEqual(3, i);
}
Test List Output:
Member UpdateProtocolQATests.CUpdateProtocolTest.DoxygenScratchPadInHeader ()
Step 1
Step 2
Step 3
Member UpdateProtocolQATests.CUpdateProtocolTest.DoxygenScratchPadInLine ()
{note no steps here}
Function description output:
void UpdateProtocolQATests.CUpdateProtocolTest.DoxygenScratchPadInHeader ()
A method for testing doxygen method documentation.
Test:
Step 1
Step 2
Step 3
void UpdateProtocolQATests.CUpdateProtocolTest.DoxygenScratchPadInLine ()
A method for testing doxygen method documentation.
Test:
1. Initialize the value to 0
1. Add a number
1. Assert that the number is three
{displaying last bit as code because stackoverflow is correcting the repeated 1. to 1. 2. 3... which is what I actually want in the end...}
Any better ideas for implementing in-line test step documentation? I don't care so much about the steps not appearing in the test list, we can live with just the references to the functions.
I'm quite sympathetic to your plight, but as far as I can tell, Doxygen really is only designed to document specific code-objects (files, classes, namespaces, variables, etc) rather than arbitrary lines of code.
At the moment, the only possibility I can think of for circumventing this shortcoming is to generate comments that include the actual code that you're wanting to document via the \code command.
There are two ways I can think of for accomplishing this:
Put some sort of special string (say, for instance, DOXY_INLINE_CODE) in the Doxy comments that should be associated with a single line of code. Then write a filter (see FILTER_PATTERNS) to replace this string with \code <nextline> \endcode where <nextline> is the next line of code that the filter sees. I'm not sure where Doxygen would put these comments or how they'd look; they might be pretty ugly, unfortunately. (One odd behavior I dislike is that the \code command seems to strip leading spaces, so you wouldn't get indentation to work correctly.)
Write a "Doxygen runner" that would automatically generate .dox files from your code before calling doxygen. These auto-generated .dox files would contain documentation generated from corresponding .cpp or other source files. You can use various Doxygen commands to link back to the documentation of the actual source code, and you can also insert a copy of the .dox documentation in the source code documentation (or vice-versa).
These are hacks, and you'd have to fiddle around with Doxygen quite a bit to get it to handle this case nicely, but I hope these suggestions help somewhat. Best of luck. (I'm currently working on doing something similar to get Doxygen to nicely document Google Tests, also in the context of a project for a highly-regulated industry.)
I remembered coming across this question when I was looking for a similar solution. I wanted to document user testing procedures as close as possible to their corresponding unit tests or groups of unit tests. The following is a subset of the solution we implemented with Doxygen groups/sub-groups.
A separate manual-test.dox file is defined to create a top-level group and several sub-groups under which specific manual tests are collected.
/**
#defgroup manualtest Manual Testing Instructions
#{
This section contains a collection of manual testing...
#defgroup menutest Menu Tests
#defgroup exporttest Import/Export Tests
#}
*/
The following shows a sample of a Java unit test class with unit test documentation and manual testing instructions.
public MenuTests {
...
/**
* #addtogroup menutest
* **Open File Test**
*
* The purpose of this test is to...
*
* -# Do something
* -# Verify something
*/
/**
* This unit test verifies that the given file can be created via
* the File->Open... menu handler. It...
*/
#Test
public void open_file_test() {
...
}
}
The resulting HTML documentation will include a Manual Testing Instruction page
under the Modules section. Said page will contain markup details as given in manual-test.dox and links to module pages for each of the defined sub-groups, such as Menu Tests.
The Menu Tests page will show all manual unit testing steps added to this
sub-group, thereby providing a separate document that can be included
by reference as part of a Software Test Plan or User Test Plan.
The only caveat is that there are no means to explicitly define the order in which test instructions are added to groups. When defined in a single class, they are added in the order they are defined and multiple classes are parsed in alphabetic order.
For projects that required more control over how tests are collected, Doxygen is used to create XML output. Test cases are extracted using an XSLT template and ordered as needed, but that is another question off its own.
Use a tool which supports document generation from inline comments:
NaturalDocs
ASCIIDoctorJ
Doxygen has helpers for perl, which is what NaturalDocs is written in.

remove Protected section from Documentation?

I have been using doxygen to generate html document for my project. And my generated documents contain a files tab. How could I remove protected attribute and protected member function fields from it?
Protected Member Functions
Protected Attributes
If you do not wish something to be extracted it should not have a documentation block. In your release provide a header file that has only the methods you wish to be exposed, create a separate header file for your own use. You may also use the \internal flag if you want internal documentation for your benefit, however this would also require that the prototype for hidden methods be exposed.
In general:
/** \internal My personal documentation
* Public documentation..................
*/
doxyfile
EXTRACT_ALL= 0,
HIDE_UNDOC_MEMBERS= 1,
INTERNAL_DOCS = 1 or 0