狮身人面像:记录枚举的正确方法?

时间:2013-07-17 03:10:36

标签: c++ python-sphinx restructuredtext

查看Sphinx的C and C++ domains,它似乎没有原生支持记录枚举(更不用说匿名枚举)。截至目前,我使用cpp:type::作为枚举类型,然后使用所有可能值及其描述的列表,但这似乎不是处理它的理想方法,尤其是因为它引用了某些值痛苦(我只引用类型,或在值前面添加额外的标记)。

有更好的方法吗?我将如何处理匿名枚举?

3 个答案:

答案 0 :(得分:5)

一个关于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执行此操作的说明,其中包括使用名为mkapiref.py的API生成器,可在 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.

你可以看看它是否对你有用。

答案 1 :(得分:1)

Sphinx现在支持enums

下面是带有枚举值的示例:

.. enum-class:: partition_affinity_domain

   .. enumerator:: \        
      not_applicable
      numa
      L4_cache
      L3_cache
      L2_cache
      L1_cache
      next_partitionab

答案 2 :(得分:0)

您好也许您应该考虑使用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
};
希望这会有所帮助。

相关问题