2009-10-16 90 views
7

我正在尝试编写一些Doxygen注释块,并且我想包含示例代码片段。当然,我希望这些示例能够真正编译,以免它们过时。如何在Doxygen注释中包含.cpp文件的子集?

我example.cpp(即I \包括在.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和\试验,直到我不能完全弄清楚正确的咒语。

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

+0

您是否正确设置了doxyfile中的EXAMPLE_PATH? – 2009-10-16 17:56:25

+0

是的。包含的文本,我只是想找出一些咒语,所以我不必在开始时看到三个#includes。 – 2009-10-16 17:59:09

+0

而你在http://www.stack.nl/~dimitri/doxygen/commands.html#cmddontinclude上看到了这个例子吗? – 2009-10-16 18:05:26

回答

2

编辑追加第二ARG夹宏。

这是我所做的,这似乎为我工作。从提示从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定义的别名为:

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()。

0

我认为\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] 
    } 
} 
+0

没错,但这并不符合我的要求,即只包含文件的一个子集。 – 2009-10-19 16:17:29

2

一些功能比较强大的是snippet命令。假设你有这样的功能:

/*[email protected] Factory 
* 
* Creates sthg 
*/ 
sthg* Create(); 

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

  • 编辑sthgTests/sthg_factory.cpp和周围添加你想要的部分代码标签出现在文档中(使用说叫test_factory标签)是这样的:

    //! [test_factory] 
    void test_factory() 
    { 
        // code here 
    } 
    //! [test_factory] 
    
  • 然后利用片段命令这样:

    /*[email protected] Factory 
    * 
    * Creates sthg 
    * @snippet sthgTests/sthg_factory.cpp test_factory 
    */ 
    sthg* Create(); 
    

这种做法是很容易设置和相当便宜,以保持。

相关问题