代码之家  ›  专栏  ›  技术社区  ›  feelfree

使用Doxygen(C++)的模板类中的typedef

  •  9
  • feelfree  · 技术社区  · 12 年前

    我的问题是关于如何用Doxygen在template类中注释typedef。我将举一个例子来说明我的问题:

     namespace fundamental
      {
        /**
        * Basic function
        */
        template <typename T>
        class Base
        {
        public:
          T x; ///< x coordinate
          T y; ///< y coordinate
        };
        typedef Base<float> Coordinate; ///< Point coordinate class
      }
    

    在使用Doxygen处理上述代码后,我可以获得一个HTML页面来显示类Base的定义。但是,对于typedef类Coordinate,它将不会与Base出现在同一页中。事实上,所有typedef类型都列在基本名称空间页面中,以及该名称空间中的所有类。我想知道是否可以在基本HTML页面中显示Coordinate类。通过这样做,基准和坐标之间的联系将变得更加紧密。谢谢

    6 回复  |  直到 12 年前
        1
  •  5
  •   doxygen    12 年前

    typedef是命名空间的一部分,因此必须记录 名称空间 使其出现,即:

    /// documentation for the namespace
    namespace fundamental
    {
       ...
       typedef Base<float> Coordinate; ///< Point coordinate class
    }
    

    或者,您可以使用 @relates 但这会使该成员陷入困境 相关功能 基类的:

    /// @relates Base
    /// Point coordinate class
    typedef Base<float> Coordinate;
    

    您可以将此标题更改为例如 相关成员 通过使用创建布局文件 doxygen -l 然后编辑 related 生成的中的元素 DoxygenLayout.xml 如下所示:

    <related title="Related Members"/>
    
        2
  •  3
  •   albert    5 年前

    In the manual 我阅读了以下内容:

    让我们重复一遍,因为它经常被忽视:要记录全局对象(函数、typedef、enum、宏等),必须记录定义它们的文件。换句话说,至少必须有

    /*! \file */ 或者 /** @file */ 行。

        3
  •  2
  •   albert    5 年前

    这就是See Also( @sa )命令,用于生成对其他实体的交叉引用。

        4
  •  1
  •   albert    5 年前

    您也可以使用 /sa command 在中手动放置引用 Base 的页面。

    namespace fundamental
    {
      /**
      * Basic function
      * /sa Coordinate
      */
      template <typename T>
      class Base
      {
      public:
        T x; ///< x coordinate
        T y; ///< y coordinate
      };
      typedef Base<float> Coordinate; ///< Point coordinate class
    }
    
        5
  •  0
  •   JohnMcG    12 年前

    其他答案会起作用,但如果 typedef Base 如果您希望它们出现在同一个Doxygen页面中,您可能需要考虑定义一个新的 namespace (在 Fundamental )只包括 基础 和你的 typedef. 然后,doxygen将为此生成一个页面 名称空间 包括 基础 和你的 类型定义。

    定义 file 文档也会做同样的事情,但这可能是一个更符合逻辑的代码布局。

        6
  •  0
  •   albert    6 年前

    这个问题还有另外两种解决办法。您可以使用@defgroup关键字定义组,并将类和typedef类型分组到一个模块中。另一种解决方案是使用 @relates