【问题标题】:CRTP function specialisation: add to the docstring of the interface functionCRTP函数特化:添加到接口函数的docstring中
【发布时间】:2021-05-29 15:47:27
【问题描述】:

我正在实现由 CRTP 派生的类。这需要在需要时进行函数专门化。现在,对于派生类中的特定专业化,我想在“全局”接口函数的文档字符串中添加一些内容。我该怎么做(使用 doxygen 1.9.1)?

示例

考虑这个例子:

template <class D>
class CommonInterface
{
public:
    /**
    \brief My common function description.
    */
    void foo()
    {
        static_cast<D*>(this)->foo_impl();
    }
};

class A : public CommonInterface<A>
{
public:
    A() = default;

private:
    void foo_impl() {};

    friend class CommonInterface<A>;
};

A::foo()A 的文档中显示为CommonInterface&lt;D&gt;::foo 的派生方法。现在,我想为 foo 方法添加一些文档,这些文档仅在 class A 的文档中可见,而在 class CommonInterface 的文档中不可见。

我不想:

  • 重写函数,而是专门使用 CRTP 来避免重写,因为我使用模板化的“重写”。
  • 文档foo_impl(),因为它在公共文档中没有任何意义。

【问题讨论】:

  • 您的意思是要为方法 foo 添加一些仅在 A 类的文档中可见但在 CommonInterface 类的文档中不可见的文档?
  • @albert 是的,这正是我的意思!我根据你的公式进行了编辑,比我的要好得多。

标签: doxygen


【解决方案1】:

不是答案,而是解决方法?

我认为 doxygen 中不存在这种情况,但也许以下可能是可接受的解决方法?

Doxyfile

EXTRACT_ALL            = YES
QUIET                  = YES
MACRO_EXPANSION        = YES
PREDEFINED             = DOXYGEN
HAVE_DOT               = YES
CALL_GRAPH             = YES
CALLER_GRAPH           = YES

aa.h

template <class D>
class CommonInterface
{
public:
    /**
    \brief My common function description.
    \details My common function detailed description.
    */
#if DOXYGEN
virtual
#endif
    void foo()
    {
        static_cast<D*>(this)->foo_impl();
    }
};

class A : public CommonInterface<A>
{
public:
    A() = default;

#if DOXYGEN
/**
\copydoc CommonInterface::foo

Some extra documentation for A::foo ?
*/
    void foo()
    {
        static_cast<D*>(this)->foo_impl();
    }
#endif
private:
    void foo_impl() {};

    friend class CommonInterface<A>;
};

【讨论】:

  • 非常感谢您的工作。确实,这可以解决问题,尽管从美学角度来看,仅为文档提供源代码并不令人惊奇。 doxygen 中用于伪造函数定义的函数在这方面看起来会更好。但我想它可能会与 doxygen 中的某些东西背道而驰
  • 这确实有点肮脏/不美观。我认为这种“奇怪地重复出现的模板模式”是一种非常特殊的情况(我以前从未见过)。我没有很快看到在派生类中为非虚拟函数实现特定功能的真正可能性(因为我认为这就是这里发生的事情)。也许值得在 doxygen github 问题跟踪器中进行增强问题(尽管我对修复的机会并不乐观)。
  • 会的! (CRTP确实很好奇,名字是什么,但我需要它来模板override函数)
  • 哎呀,我写了“我以前从未见过它”,但我现在看到 doxygen 也在它自己的代码中使用它(例如在 docparser.h:class DocRoot : public CompAccept&lt;DocRoot&gt;)一定已经进入我的位 -桶
猜你喜欢
  • 2023-02-02
  • 1970-01-01
  • 2023-02-13
  • 1970-01-01
  • 1970-01-01
  • 2021-11-24
  • 2020-07-02
  • 2021-12-11
  • 2020-09-06
相关资源
最近更新 更多