9

私はいくつかの Doxygen コメント ブロックを書き込もうとしています。コードのサンプル スニペットを含めたいと思います。もちろん、サンプルが古くならないように実際にコンパイルしたいと思います。

私の example.cpp (.h ファイルに \include する) は次のようになります。

#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」からファイルの最後までを含めるようにしたいと思います(ただし、//エンドコードはありません)。

\dontinclude と \skip、\skipline、\until を試してみましたが、正しい呪文がわかりません。

編集: 私の .h ファイルを含めて、今ではほとんど正しい呪文を手に入れました。タグなしで \until を使用し、最後の // エンドコード行を example.cpp から削除する方法はあります?

4

3 に答える 3

3

クリップマクロに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

そして、私はそれを含めたいのですが、上部に#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()だけを含めて、まさに私が望むことを実行します。

于 2009-10-19T16:22:39.413 に答える
2

かなり強力なものは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();
    

このアプローチはセットアップが簡単で、維持費もかなり安価です。

于 2013-03-19T14:58:15.773 に答える
0

\ verbincludeを使用すると、ファイルをコードとしてインクルードでき// \endcode、最後の行に配置する必要がなくなるはずです。

編集:明確にするために、インクルードするコードを独自のインクルードファイルに入れ#include、CPPファイルで使用\verbincludeしてから、doxygenヘッダーファイルで使用することをお勧めします。

ソースファイルは次のようになります。

#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]
    }
}
于 2009-10-19T13:38:04.817 に答える