纵观 Sphinx 的C 和 C++ 域,它似乎没有原生支持记录枚举(更不用说匿名枚举)了。截至目前,我使用cpp:type::
枚举类型,然后是所有可能值及其描述的列表,但这似乎不是处理它的理想方式,特别是因为它使引用某些值成为一种痛苦(要么我仅引用类型,或在值前面添加一个额外的标记)。
有一个更好的方法吗?我将如何处理匿名枚举?
纵观 Sphinx 的C 和 C++ 域,它似乎没有原生支持记录枚举(更不用说匿名枚举)了。截至目前,我使用cpp:type::
枚举类型,然后是所有可能值及其描述的列表,但这似乎不是处理它的理想方式,特别是因为它使引用某些值成为一种痛苦(要么我仅引用类型,或在值前面添加一个额外的标记)。
有一个更好的方法吗?我将如何处理匿名枚举?
Github 上的一个项目 spdylay 似乎有办法。https://github.com/tatsuhiro-t/spdylay/blob/master/lib/includes/spdylay/spdylay.h的头文件之一 具有如下代码:
/**
* @enum
* Error codes used in the Spdylay library.
*/
typedef enum {
/**
* Invalid argument passed.
*/
SPDYLAY_ERR_INVALID_ARGUMENT = -501,
/**
* Zlib error.
*/
SPDYLAY_ERR_ZLIB = -502,
} spdylay_error;
在https://github.com/tatsuhiro-t/spdylay/tree/master/doc有一些关于他们如何做到这一点的描述,其中包括使用名为 的 API 生成器mkapiref.py
,可在
https://github.com/tatsuhiro -t/spdylay/blob/master/doc/mkapiref.py
它为此示例生成的 RST 是
.. type:: spdylay_error
Error codes used in the Spdylay library.
.. macro:: SPDYLAY_ERR_INVALID_ARGUMENT
(``-501``)
Invalid argument passed.
.. macro:: SPDYLAY_ERR_ZLIB
(``-502``)
Zlib error.
你可以看看它是否对你有用。
Sphinx 现在支持枚举
这是枚举值的示例:
.. enum-class:: partition_affinity_domain
.. enumerator:: \
not_applicable
numa
L4_cache
L3_cache
L2_cache
L1_cache
next_partitionab
嗨也许你应该考虑使用doxygen来编写文档,因为它对 c / c++ 有更多的原生支持。如果您想保留文档的 sphinx 输出,您可以从 doxygen 输出为 xml,然后使用Breathe它将获取 xml 并为您提供与您习惯相同的 sphinx 输出。
这是一个从呼吸网站以 doxygen 格式记录枚举的示例。
//! Our toolset
/*! The various tools we can opt to use to crack this particular nut */
enum Tool
{
kHammer = 0, //!< What? It does the job
kNutCrackers, //!< Boring
kNinjaThrowingStars //!< Stealthy
};
希望这可以帮助。