Combining multiple Doxygen comments into one PlantUML diagram

0 votes
asked Mar 18 in Question / help by anonymous

If I have the following code:


/**
* @brief Check the status and perform an action accordingly.
*
* This function checks the status of a boolean variable and performs
* different actions based on its value.
*
* @param[in] bStatus The boolean status to check.
*/
void checkStatus(bool bStatus) {

    /// First, check the status
    if (bStatus) {
        /// Everything is good, run the process
        process();
    } else {
        /// There was a problem, report an error
        error();
    }
}


How might I go about writing/combining the Doxygen comments within the code itself to produce the following when Doxygen is run and uses the PlantUML engine.


/// @startuml

/// start

/// if (status) is (valid) then

///     :Everything is good, run the process;

/// else

///     :There was a problem, report an error

/// endif

/// end

/// @enduml


If I have the comments all in one block, it works fine, but when it is split across multiple lines like below I get errors thrown by PlantUML.


/**
* @brief Check the status and perform an action accordingly.
*
* This function checks the status of a boolean variable and performs
* different actions based on its value.
*
* @param[in] bStatus The boolean status to check.
*/
void checkStatus(bool bStatus) {

    /// @startuml

    /// start

    /// if (status) is (valid) then
    if (bStatus) {
        /// :Everything is good, run the process
        process();
    } else {

        /// else
        /// :There was a problem, report an error
        error();
    }

    /// endif

    /// @enduml

}


 Is this even possible?

Thank you for your time.

commented Mar 19 by albert (3,520 points)

Which version of doxygen are you using?

No this is not possible as the plantuml commands are distributed over multiple comment blocks.
Only thing you can do is to make one block out of it and add this.
commented Mar 19 by anonymous
I am using Doxygen v 1.10.0.

Thanks for your reply though. I was not sure so thought I would ask.

1 Answer

0 votes
answered Mar 21 by caring-coder (580 points)

If you pipe your document to doxygen yourself, you can do some preprocessing, and filter out your code that is between plantuml tags this way:

cat code.cpp \
   | awk 'BEGIN{norm=1}; /\/\/\/ @startuml/{spec=1;norm=0}; /\/\/\// && (norm || spec) {print}; !/\/\/\// && (norm && !spec){print}; /\/\/\/ @enduml/{spec=0;norm=1};' \
   | doxygen -

I didn't try the command with doxygen directly, but the effect of the awk line is to keep only the comment between '/// @startuml' and '/// @enduml', and keep everything (code and comments) outside those tags

commented Mar 22 by anonymous
Thank you for the suggestion. I will see if that works for my scenario. Appreciate your time!
...