Doxygen: Force undeclared functions to be documented

≯℡__Kan透↙ 提交于 2020-08-08 05:12:29

问题


Our C++ program has a built-in script interface and is able to run scripts in it. The scripts have access to convenience functions provided by the C++ program.

Now we would like Doxygen to create the documentation of the functions the script has access to. Such a function declaration looks like this:

void ScriptEngine::load_script(const QString &path) {       
//...

    /*! \fn sleep_ms(const unsigned int timeout_ms)
        \brief sleeps for timeout_ms milliseconds.
        \param timeout_ms 
    */
    (*lua)["sleep_ms"] = [](const unsigned int timeout_ms) {
        //sleep(timeout_ms)
    };

    //more convenience functions..
//...
}

Obviously Doxygen won't include a

sleep_ms(const unsigned int timeout_ms)

into the documentation. Is there a way to to tell Doxygen to do so?


回答1:


Do this:

  1. Add the following line to your Doxyfile:

    PREDEFINED = _DOXYGEN_
    
  2. Make sure the ENABLE_PREPROCESSING tag in the Doxyfile is set to YES.

  3. Put your declarations and documentation for the undeclared functions inside an #ifdef _DOXYGEN_ section.

    #ifdef _DOXYGEN_
        /*! \fn sleep_ms(const unsigned int timeout_ms) 
            \brief sleeps for timeout_ms milliseconds.
            \param timeout_ms
        */
        void sleep_ms(const unsigned int timeout_ms);
    #endif
    

Don't put the above code inside a method or function such as ScriptEngine::load_script(), as you previously tried. And don't put it inside a namespace or class, unless in fact the function being declared is a member of that namespace or class.

With this method, your declarations will not create linker errors during a normal build, but will be seen by Doxygen.

See Also

http://www.doxygen.nl/manual/config.html#cfg_predefined



来源:https://stackoverflow.com/questions/42510536/doxygen-force-undeclared-functions-to-be-documented

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!