【问题标题】:typedef in template class with Doxygen (C++)带有 Doxygen 的模板类中的 typedef (C++)
【发布时间】:2012-08-04 15:52:17
【问题描述】:

我的问题与如何使用 Doxygen 在模板类中注释 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 类型以及该命名空间中的所有类都列在基本命名空间页面中。我想知道是否可以在 Base HTML 页面中显示坐标类。这样一来,Base 和 Coordinate 之间的联系就会更加紧密。谢谢!

【问题讨论】:

    标签: c++ doxygen


    【解决方案1】:

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

    /// 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 创建布局文件,然后编辑生成的DoxygenLayout.xml 中出现的两次related 元素,将标题更改为例如Related Members,如下所示:

    <related title="Related Members"/>
    

    【讨论】:

      【解决方案2】:

      In the manual我读到以下内容:

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

      /*! \file *//** @file */ 此文件中的行。

      【讨论】:

        【解决方案3】:

        还有 See Also (@sa) 命令,可用于生成对其他实体的交叉引用。

        【讨论】:

          【解决方案4】:

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

          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】:

            其他答案将起作用,但如果您的 typedefBase 类密切相关,您希望它们出现在同一个 Doxygen 页面中,您可能需要考虑定义一个新的 namespace(在Fundamental) 将只包含Base 和您的typedef. 然后,d​​oxygen 将为该namespace 生成一个页面,其中将包含Base 和您的typedef.

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

            【讨论】:

              【解决方案6】:

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

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 2013-02-12
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2015-07-02
                相关资源
                最近更新 更多