如何在Doxygen评论中包含.cpp文件的子集?

Eri*_* H. 9 c++ doxygen

我正在尝试编写一些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
Run Code Online (Sandbox Code Playgroud)

和我的头文件(我正在运行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
 * 
**/
Run Code Online (Sandbox Code Playgroud)

而且我想让doxygen只包含从"void demo"开始到文件末尾的东西(但是没有// endcode).

我尝试过使用\ dontinclude和\ skip,\ skipline和\ until,我无法找出正确的咒语.

编辑:包括我的.h文件,现在我几乎得到了正确的咒语.这几乎完全符合我的要求,是否有一些方法可以使用\直到没有标记,并从example.cpp中删除最后//结束代码行?

Eri*_* H. 2

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

这就是我所做的,这似乎对我有用。大部分来自 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
Run Code Online (Sandbox Code Playgroud)

我想包含它,但顶部不包含#includes。

我在 Doxyfile 中将 ALIAS 定义为:

ALIASES += clip{2}="\dontinclude \1 \n \skipline \2 \n \until endcode"
Run Code Online (Sandbox Code Playgroud)

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

/**
 * \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}
**/
Run Code Online (Sandbox Code Playgroud)

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