如何在Doxygen注释中包含.cpp文件的子集?

我正在尝试编写一些Doxygen注释块,并且我想包含示例代码片段。 当然,我希望这些示例能够真正编译,以免它们过时。

我的example.cpp(包含在.h文件中)看起来像这样:

#include "stdafx.h"

#include "../types_lib/Time_Limiter.h"
#include <vector>

void tl_demo () {
    // scarce will be a gate to control some resource that shouldn't get called
    // more than 10 times a second
    Time_Limiter scarce (10);

    // here's a bunch of requests
    std::vector<int> req (500);

    for (size_t i=0;i<req.size ();i++) {
        scarce.tick ();
        // once we get here, we know that we haven't ticked
        // more than 10 times in the last second.

        // do something interesting with req[i]
    }
}

// endcode

和我的头文件(我正在运行Doxygen)看起来像这样:

/**
 * ingroup types_lib
 *
 * class   Time_Limiter
 *
 * brief   Thread safe gate used to control a resource (such as an internet quote service) that has a limit on how often you can call it.
 *
 * dontinclude Time_Limiter_example.cpp
 * skipline void
 * until endcode
 * 
**/

我想让doxygen只包含从“void demo”开始到文件结尾的东西(但没有// endcode)。

我尝试过试用 dontinclude和 skip, skipline和 until,但我无法弄清楚正确的咒语。

编辑:包括我的.h文件,现在我几乎得到正确的咒语。 这几乎完全是我想要的,有没有方法可以使用直到没有标签,并从example.cpp中去掉最后一个// endcode行?


编辑将第二个参数添加到剪辑宏。

这是我所做的,这似乎对我有用。 大部分来自EricM的提示....

我的源文件Time_Limiter_example.cpp是:

#include "stdafx.h"

#include "../types_lib/Time_Limiter.h"
#include <vector>

void tl_demo () {
    // scarce will be a gate to control some resource that shouldn't get called
    // more than 10 times a second
    Time_Limiter scarce (10);

    // here's a bunch of requests
    std::vector<int> req (500);

    for (size_t i=0;i<req.size ();i++) {
        scarce.tick ();
        // once we get here, we know that we haven't ticked
        // more than 10 times in the last second.

        // do something interesting with req[i]
    }
} // endcode

void tl_demo_short () 
{
} //endcode

我想包括它,但没有顶部的#includes。

我在我的Doxyfile中定义了一个ALIAS,如下所示:

ALIASES += clip{2}="dontinclude 1 n skipline 2 n until endcode"

在我的标题中,我的评论如下所示:

/**
 * ingroup types_lib
 *
 * class   Time_Limiter
 *
 * brief   Thread safe gate used to control a resource (such as an internet quote service) that has a limit on how often you can call it.
 *
 * clip{Time_Limiter_example.cpp,tl_demo}
**/

而这正是我想要的,包括来自.cpp文件的函数tl_demo()。


snippet命令是一个非常强大的功能。 假设你有这样的功能:

/*!@brief Factory
 *
 * Creates sthg
 */
sthg* Create();

你想添加sthgTests/sthg_factory.cpp文件的一部分:

  • 编辑sthgTests/sthg_factory.cpp并在代码中希望出现在文档中的部分添加一个标签(比如使用名为test_factory的标签),如下所示:

    //! [test_factory]
    void test_factory()
    {
      // code here
    }
    //! [test_factory]
    
  • 然后像这样使用snippet命令:

    /*!@brief Factory
     *
     * Creates sthg
     * @snippet sthgTests/sthg_factory.cpp test_factory
     */
    sthg* Create();
    
  • 这种方法很容易设置,而且维护起来很便宜。


    我认为 verbinclude应该允许你包含一个文件作为代码,而不必把// endcode放在最后一行。

    编辑:为了澄清,我建议你把你想要包含在自己的包含文件中的代码,并在CPP文件中使用#include ,然后在doxygen头文件中使用verbinclude

    你的源文件看起来像这样:

    #include "stdafx.h"
    #include "../types_lib/Time_Limiter.h"
    #include <vector>    
    #include "Time_Limiter_example.inc"
    

    然后,文件“Time_Limiter_example.inc”可以包含代码示例:

    void tl_demo () {
        // scarce will be a gate to control some resource that shouldn't get called
        // more than 10 times a second
        Time_Limiter scarce (10);
    
        // here's a bunch of requests
        std::vector<int> req (500);
    
        for (size_t i=0;i<req.size ();i++) {
            scarce.tick ();
            // once we get here, we know that we haven't ticked
            // more than 10 times in the last second.
    
            // do something interesting with req[i]
        }
    }
    
    链接地址: http://www.djcxy.com/p/43495.html

    上一篇: How can I include a subset of a .cpp file in a Doxygen comment?

    下一篇: How do I list all the available views of a particular table in SQLite?