2010-03-01 07:22:14 -06:00
|
|
|
.. highlight:: rst
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
=======
|
|
|
|
Domains
|
|
|
|
=======
|
2010-01-17 12:16:18 -06:00
|
|
|
|
2010-03-01 07:22:14 -06:00
|
|
|
.. versionadded:: 1.0
|
|
|
|
|
|
|
|
Originally, Sphinx was conceived for a single project, the documentation of the
|
|
|
|
Python language. Shortly afterwards, it was made available for everyone as a
|
|
|
|
documentation tool, but the documentation of Python modules remained deeply
|
|
|
|
built in -- the most fundamental directives, like ``function``, were designed
|
|
|
|
for Python objects. Since Sphinx has become somewhat popular, interest
|
|
|
|
developed in using it for many different purposes: C/C++ projects, JavaScript,
|
|
|
|
or even reStructuredText markup (like in this documentation).
|
|
|
|
|
|
|
|
While this was always possible, it is now much easier to easily support
|
2017-11-03 15:20:36 -05:00
|
|
|
documentation of projects using different programming languages or even ones
|
|
|
|
not supported by the main Sphinx distribution, by providing a **domain** for
|
|
|
|
every such purpose.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
A domain is a collection of markup (reStructuredText :term:`directive`\ s and
|
|
|
|
:term:`role`\ s) to describe and link to :term:`object`\ s belonging together,
|
|
|
|
e.g. elements of a programming language. Directive and role names in a domain
|
2017-11-03 15:20:36 -05:00
|
|
|
have names like ``domain:name``, e.g. ``py:function``. Domains can also
|
|
|
|
provide custom indices (like the Python Module Index).
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Having domains means that there are no naming problems when one set of
|
2017-11-03 15:20:36 -05:00
|
|
|
documentation wants to refer to e.g. C++ and Python classes. It also means
|
|
|
|
that extensions that support the documentation of whole new languages are much
|
|
|
|
easier to write.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2017-06-01 15:11:48 -05:00
|
|
|
This section describes what the domains that are included with Sphinx provide.
|
|
|
|
The domain API is documented as well, in the section :ref:`domain-api`.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
|
|
|
|
.. _basic-domain-markup:
|
|
|
|
|
|
|
|
Basic Markup
|
|
|
|
------------
|
|
|
|
|
|
|
|
Most domains provide a number of :dfn:`object description directives`, used to
|
|
|
|
describe specific objects provided by modules. Each directive requires one or
|
|
|
|
more signatures to provide basic information about what is being described, and
|
|
|
|
the content should be the description. The basic version makes entries in the
|
|
|
|
general index; if no index entry is desired, you can give the directive option
|
|
|
|
flag ``:noindex:``. An example using a Python domain directive::
|
|
|
|
|
|
|
|
.. py:function:: spam(eggs)
|
|
|
|
ham(eggs)
|
|
|
|
|
|
|
|
Spam or ham the foo.
|
|
|
|
|
2010-08-05 09:03:36 -05:00
|
|
|
This describes the two Python functions ``spam`` and ``ham``. (Note that when
|
|
|
|
signatures become too long, you can break them if you add a backslash to lines
|
|
|
|
that are continued in the next line. Example::
|
|
|
|
|
|
|
|
.. py:function:: filterwarnings(action, message='', category=Warning, \
|
|
|
|
module='', lineno=0, append=False)
|
|
|
|
:noindex:
|
|
|
|
|
|
|
|
(This example also shows how to use the ``:noindex:`` flag.)
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
The domains also provide roles that link back to these object descriptions.
|
|
|
|
For example, to link to one of the functions described in the example above,
|
|
|
|
you could say ::
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
The function :py:func:`spam` does a similar thing.
|
|
|
|
|
|
|
|
As you can see, both directive and role names contain the domain name and the
|
|
|
|
directive name.
|
|
|
|
|
|
|
|
.. rubric:: Default Domain
|
|
|
|
|
2017-03-21 02:24:35 -05:00
|
|
|
For documentation describing objects from solely one domain, authors will not
|
2017-03-21 03:23:35 -05:00
|
|
|
have to state again its name at each directive, role, etc... after
|
2017-03-21 02:26:11 -05:00
|
|
|
having specified a default. This can be done either via the config
|
2017-03-21 02:24:35 -05:00
|
|
|
value :confval:`primary_domain` or via this directive:
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. default-domain:: name
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2010-05-23 09:48:54 -05:00
|
|
|
Select a new default domain. While the :confval:`primary_domain` selects a
|
2010-03-01 07:22:14 -06:00
|
|
|
global default, this only has an effect within the same file.
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
If no other default is selected, the Python domain (named ``py``) is the
|
|
|
|
default one, mostly for compatibility with documentation written for older
|
|
|
|
versions of Sphinx.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Directives and roles that belong to the default domain can be mentioned without
|
|
|
|
giving the domain name, i.e. ::
|
|
|
|
|
|
|
|
.. function:: pyfunc()
|
|
|
|
|
|
|
|
Describes a Python function.
|
|
|
|
|
|
|
|
Reference to :func:`pyfunc`.
|
|
|
|
|
2010-03-01 07:53:30 -06:00
|
|
|
Cross-referencing syntax
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
For cross-reference roles provided by domains, the same facilities exist as for
|
|
|
|
general cross-references. See :ref:`xref-syntax`.
|
|
|
|
|
|
|
|
In short:
|
|
|
|
|
|
|
|
* You may supply an explicit title and reference target: ``:role:`title
|
|
|
|
<target>``` will refer to *target*, but the link text will be *title*.
|
|
|
|
|
|
|
|
* If you prefix the content with ``!``, no reference/hyperlink will be created.
|
|
|
|
|
|
|
|
* If you prefix the content with ``~``, the link text will only be the last
|
|
|
|
component of the target. For example, ``:py:meth:`~Queue.Queue.get``` will
|
|
|
|
refer to ``Queue.Queue.get`` but only display ``get`` as the link text.
|
|
|
|
|
2010-04-08 14:33:03 -05:00
|
|
|
|
2010-03-01 07:22:14 -06:00
|
|
|
The Python Domain
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
The Python domain (name **py**) provides the following directives for module
|
|
|
|
declarations:
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. py:module:: name
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
This directive marks the beginning of the description of a module (or package
|
|
|
|
submodule, in which case the name should be fully qualified, including the
|
2014-06-18 10:53:25 -05:00
|
|
|
package name). It does not create content (like e.g. :rst:dir:`py:class`
|
|
|
|
does).
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
This directive will also cause an entry in the global module index.
|
|
|
|
|
|
|
|
The ``platform`` option, if present, is a comma-separated list of the
|
|
|
|
platforms on which the module is available (if it is available on all
|
|
|
|
platforms, the option should be omitted). The keys are short identifiers;
|
|
|
|
examples that are in use include "IRIX", "Mac", "Windows", and "Unix". It is
|
|
|
|
important to use a key which has already been used when applicable.
|
|
|
|
|
|
|
|
The ``synopsis`` option should consist of one sentence describing the
|
|
|
|
module's purpose -- it is currently only used in the Global Module Index.
|
|
|
|
|
|
|
|
The ``deprecated`` option can be given (with no value) to mark a module as
|
|
|
|
deprecated; it will be designated as such in various locations then.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. py:currentmodule:: name
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
This directive tells Sphinx that the classes, functions etc. documented from
|
2010-08-05 06:39:23 -05:00
|
|
|
here are in the given module (like :rst:dir:`py:module`), but it will not
|
|
|
|
create index entries, an entry in the Global Module Index, or a link target
|
|
|
|
for :rst:role:`py:mod`. This is helpful in situations where documentation
|
|
|
|
for things in a module is spread over multiple files or sections -- one
|
|
|
|
location has the :rst:dir:`py:module` directive, the others only
|
|
|
|
:rst:dir:`py:currentmodule`.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
The following directives are provided for module and class contents:
|
|
|
|
|
2013-11-24 09:02:34 -06:00
|
|
|
.. rst:directive:: .. py:function:: name(parameters)
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Describes a module-level function. The signature should include the
|
2014-01-13 12:12:42 -06:00
|
|
|
parameters as given in the Python function definition, see :ref:`signatures`.
|
|
|
|
For example::
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2014-01-13 12:12:42 -06:00
|
|
|
.. py:function:: Timer.repeat(repeat=3, number=1000000)
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2014-01-13 12:12:42 -06:00
|
|
|
For methods you should use :rst:dir:`py:method`.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2014-01-13 13:13:44 -06:00
|
|
|
The description normally includes information about the parameters required
|
|
|
|
and how they are used (especially whether mutable objects passed as
|
|
|
|
parameters are modified), side effects, and possible exceptions.
|
|
|
|
|
|
|
|
This information can (in any ``py`` directive) optionally be given in a
|
|
|
|
structured form, see :ref:`info-field-lists`.
|
|
|
|
|
2019-04-13 06:14:09 -05:00
|
|
|
The ``async`` option can be given (with no value) to indicate the function is
|
|
|
|
an async method.
|
|
|
|
|
|
|
|
.. versionchanged:: 2.1
|
|
|
|
|
|
|
|
``:async:`` option added.
|
|
|
|
|
2014-01-13 13:13:44 -06:00
|
|
|
.. rst:directive:: .. py:data:: name
|
|
|
|
|
|
|
|
Describes global data in a module, including both variables and values used
|
|
|
|
as "defined constants." Class and object attributes are not documented
|
|
|
|
using this environment.
|
|
|
|
|
|
|
|
.. rst:directive:: .. py:exception:: name
|
|
|
|
|
|
|
|
Describes an exception class. The signature can, but need not include
|
|
|
|
parentheses with constructor arguments.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2013-11-24 09:02:34 -06:00
|
|
|
.. rst:directive:: .. py:class:: name
|
|
|
|
.. py:class:: name(parameters)
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2013-11-24 09:02:34 -06:00
|
|
|
Describes a class. The signature can optionally include parentheses with
|
|
|
|
parameters which will be shown as the constructor arguments. See also
|
2010-03-01 07:22:14 -06:00
|
|
|
:ref:`signatures`.
|
|
|
|
|
|
|
|
Methods and attributes belonging to the class should be placed in this
|
|
|
|
directive's body. If they are placed outside, the supplied name should
|
|
|
|
contain the class name so that cross-references still work. Example::
|
|
|
|
|
|
|
|
.. py:class:: Foo
|
2014-01-13 12:12:42 -06:00
|
|
|
|
2010-03-01 07:22:14 -06:00
|
|
|
.. py:method:: quux()
|
|
|
|
|
|
|
|
-- or --
|
|
|
|
|
|
|
|
.. py:class:: Bar
|
|
|
|
|
|
|
|
.. py:method:: Bar.quux()
|
|
|
|
|
|
|
|
The first way is the preferred one.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. py:attribute:: name
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Describes an object data attribute. The description should include
|
|
|
|
information about the type of the data to be expected and whether it may be
|
|
|
|
changed directly.
|
|
|
|
|
2013-11-24 09:02:34 -06:00
|
|
|
.. rst:directive:: .. py:method:: name(parameters)
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Describes an object method. The parameters should not include the ``self``
|
|
|
|
parameter. The description should include similar information to that
|
2014-01-13 12:12:42 -06:00
|
|
|
described for ``function``. See also :ref:`signatures` and
|
|
|
|
:ref:`info-field-lists`.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2019-04-13 06:14:09 -05:00
|
|
|
The ``async`` option can be given (with no value) to indicate the method is
|
|
|
|
an async method.
|
|
|
|
|
2019-04-07 07:09:57 -05:00
|
|
|
The ``classmethod`` option and ``staticmethod`` option can be given (with
|
|
|
|
no value) to indicate the method is a class method (or a static method).
|
|
|
|
|
|
|
|
.. versionchanged:: 2.1
|
|
|
|
|
2019-04-13 06:14:09 -05:00
|
|
|
``:async:``, ``:classmethod:`` and ``:staticmethod:`` options added.
|
2019-04-07 07:09:57 -05:00
|
|
|
|
2013-11-24 09:02:34 -06:00
|
|
|
.. rst:directive:: .. py:staticmethod:: name(parameters)
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
Like :rst:dir:`py:method`, but indicates that the method is a static method.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
.. versionadded:: 0.4
|
|
|
|
|
2013-11-24 09:02:34 -06:00
|
|
|
.. rst:directive:: .. py:classmethod:: name(parameters)
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
Like :rst:dir:`py:method`, but indicates that the method is a class method.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
.. versionadded:: 0.6
|
|
|
|
|
2011-01-08 03:07:42 -06:00
|
|
|
.. rst:directive:: .. py:decorator:: name
|
2013-11-24 09:02:34 -06:00
|
|
|
.. py:decorator:: name(parameters)
|
2011-01-08 03:07:42 -06:00
|
|
|
|
2014-01-13 12:12:42 -06:00
|
|
|
Describes a decorator function. The signature should represent the usage as
|
|
|
|
a decorator. For example, given the functions
|
2011-01-08 03:07:42 -06:00
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
def removename(func):
|
|
|
|
func.__name__ = ''
|
|
|
|
return func
|
|
|
|
|
|
|
|
def setnewname(name):
|
|
|
|
def decorator(func):
|
|
|
|
func.__name__ = name
|
|
|
|
return func
|
|
|
|
return decorator
|
|
|
|
|
|
|
|
the descriptions should look like this::
|
|
|
|
|
|
|
|
.. py:decorator:: removename
|
|
|
|
|
|
|
|
Remove name of the decorated function.
|
|
|
|
|
|
|
|
.. py:decorator:: setnewname(name)
|
|
|
|
|
|
|
|
Set name of the decorated function to *name*.
|
|
|
|
|
2013-11-25 13:43:23 -06:00
|
|
|
(as opposed to ``.. py:decorator:: removename(func)``.)
|
|
|
|
|
2011-01-08 03:07:42 -06:00
|
|
|
There is no ``py:deco`` role to link to a decorator that is marked up with
|
|
|
|
this directive; rather, use the :rst:role:`py:func` role.
|
|
|
|
|
|
|
|
.. rst:directive:: .. py:decoratormethod:: name
|
|
|
|
.. py:decoratormethod:: name(signature)
|
|
|
|
|
|
|
|
Same as :rst:dir:`py:decorator`, but for decorators that are methods.
|
|
|
|
|
|
|
|
Refer to a decorator method using the :rst:role:`py:meth` role.
|
|
|
|
|
2010-03-01 07:22:14 -06:00
|
|
|
.. _signatures:
|
|
|
|
|
|
|
|
Python Signatures
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Signatures of functions, methods and class constructors can be given like they
|
2014-01-13 12:12:42 -06:00
|
|
|
would be written in Python.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Default values for optional arguments can be given (but if they contain commas,
|
|
|
|
they will confuse the signature parser). Python 3-style argument annotations
|
|
|
|
can also be given as well as return type annotations::
|
|
|
|
|
2014-01-13 12:12:42 -06:00
|
|
|
.. py:function:: compile(source : string, filename, symbol='file') -> ast object
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
For functions with optional parameters that don't have default values
|
|
|
|
(typically functions implemented in C extension modules without keyword
|
|
|
|
argument support), you can use brackets to specify the optional parts:
|
2014-01-13 12:12:42 -06:00
|
|
|
|
|
|
|
.. py:function:: compile(source[, filename[, symbol]])
|
|
|
|
|
|
|
|
It is customary to put the opening bracket before the comma.
|
|
|
|
|
|
|
|
.. _info-field-lists:
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Info field lists
|
|
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
.. versionadded:: 0.4
|
|
|
|
|
|
|
|
Inside Python object description directives, reST field lists with these fields
|
|
|
|
are recognized and formatted nicely:
|
|
|
|
|
|
|
|
* ``param``, ``parameter``, ``arg``, ``argument``, ``key``, ``keyword``:
|
|
|
|
Description of a parameter.
|
2014-11-12 04:32:21 -06:00
|
|
|
* ``type``: Type of a parameter. Creates a link if possible.
|
2010-03-01 07:22:14 -06:00
|
|
|
* ``raises``, ``raise``, ``except``, ``exception``: That (and when) a specific
|
|
|
|
exception is raised.
|
|
|
|
* ``var``, ``ivar``, ``cvar``: Description of a variable.
|
2015-03-09 08:51:20 -05:00
|
|
|
* ``vartype``: Type of a variable. Creates a link if possible.
|
2010-03-01 07:22:14 -06:00
|
|
|
* ``returns``, ``return``: Description of the return value.
|
2014-11-12 04:32:21 -06:00
|
|
|
* ``rtype``: Return type. Creates a link if possible.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2016-12-16 23:46:39 -06:00
|
|
|
.. note::
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
In current release, all ``var``, ``ivar`` and ``cvar`` are represented as
|
|
|
|
"Variable". There is no difference at all.
|
2016-12-16 23:46:39 -06:00
|
|
|
|
2010-03-01 07:22:14 -06:00
|
|
|
The field names must consist of one of these keywords and an argument (except
|
|
|
|
for ``returns`` and ``rtype``, which do not need an argument). This is best
|
|
|
|
explained by an example::
|
|
|
|
|
2013-09-05 11:52:54 -05:00
|
|
|
.. py:function:: send_message(sender, recipient, message_body, [priority=1])
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2013-09-05 11:52:54 -05:00
|
|
|
Send a message to a recipient
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2013-09-15 20:51:02 -05:00
|
|
|
:param str sender: The person sending the message
|
|
|
|
:param str recipient: The recipient of the message
|
|
|
|
:param str message_body: The body of the message
|
2013-09-05 11:52:54 -05:00
|
|
|
:param priority: The priority of the message, can be a number 1-5
|
|
|
|
:type priority: integer or None
|
|
|
|
:return: the message id
|
|
|
|
:rtype: int
|
|
|
|
:raises ValueError: if the message_body exceeds 160 characters
|
|
|
|
:raises TypeError: if the message_body is not a basestring
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
This will render like this:
|
|
|
|
|
2013-09-05 11:52:54 -05:00
|
|
|
.. py:function:: send_message(sender, recipient, message_body, [priority=1])
|
2010-03-01 07:22:14 -06:00
|
|
|
:noindex:
|
|
|
|
|
2013-09-05 11:52:54 -05:00
|
|
|
Send a message to a recipient
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2013-09-15 20:51:02 -05:00
|
|
|
:param str sender: The person sending the message
|
|
|
|
:param str recipient: The recipient of the message
|
|
|
|
:param str message_body: The body of the message
|
|
|
|
:param priority: The priority of the message, can be a number 1-5
|
2013-09-05 11:52:54 -05:00
|
|
|
:type priority: integer or None
|
|
|
|
:return: the message id
|
|
|
|
:rtype: int
|
|
|
|
:raises ValueError: if the message_body exceeds 160 characters
|
|
|
|
:raises TypeError: if the message_body is not a basestring
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2010-11-12 01:26:20 -06:00
|
|
|
It is also possible to combine parameter type and description, if the type is a
|
|
|
|
single word, like this::
|
|
|
|
|
2013-09-15 20:51:02 -05:00
|
|
|
:param int priority: The priority of the message, can be a number 1-5
|
2010-11-12 01:26:20 -06:00
|
|
|
|
2016-08-02 15:29:07 -05:00
|
|
|
.. versionadded:: 1.5
|
|
|
|
|
|
|
|
Container types such as lists and dictionaries can be linked automatically
|
|
|
|
using the following syntax::
|
|
|
|
|
|
|
|
:type priorities: list(int)
|
|
|
|
:type priorities: list[int]
|
|
|
|
:type mapping: dict(str, int)
|
|
|
|
:type mapping: dict[str, int]
|
|
|
|
:type point: tuple(float, float)
|
|
|
|
:type point: tuple[float, float]
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Multiple types in a type field will be linked automatically if separated by the
|
|
|
|
word "or"::
|
2016-09-18 00:38:27 -05:00
|
|
|
|
|
|
|
:type an_arg: int or None
|
|
|
|
:vartype a_var: str or int
|
|
|
|
:rtype: float or str
|
|
|
|
|
2011-01-06 13:44:55 -06:00
|
|
|
.. _python-roles:
|
|
|
|
|
2010-03-01 07:53:30 -06:00
|
|
|
Cross-referencing Python objects
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
The following roles refer to objects in modules and are possibly hyperlinked if
|
|
|
|
a matching identifier is found:
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: py:mod
|
2010-03-01 07:53:30 -06:00
|
|
|
|
|
|
|
Reference a module; a dotted name may be used. This should also be used for
|
|
|
|
package names.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: py:func
|
2010-03-01 07:53:30 -06:00
|
|
|
|
|
|
|
Reference a Python function; dotted names may be used. The role text needs
|
|
|
|
not include trailing parentheses to enhance readability; they will be added
|
|
|
|
automatically by Sphinx if the :confval:`add_function_parentheses` config
|
2014-06-18 11:34:28 -05:00
|
|
|
value is ``True`` (the default).
|
2010-03-01 07:53:30 -06:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: py:data
|
2010-03-01 07:53:30 -06:00
|
|
|
|
|
|
|
Reference a module-level variable.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: py:const
|
2010-03-01 07:53:30 -06:00
|
|
|
|
2014-01-11 07:52:41 -06:00
|
|
|
Reference a "defined" constant. This may be a Python variable that is not
|
|
|
|
intended to be changed.
|
2010-03-01 07:53:30 -06:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: py:class
|
2010-03-01 07:53:30 -06:00
|
|
|
|
|
|
|
Reference a class; a dotted name may be used.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: py:meth
|
2010-03-01 07:53:30 -06:00
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Reference a method of an object. The role text can include the type name
|
|
|
|
and the method name; if it occurs within the description of a type, the type
|
|
|
|
name can be omitted. A dotted name may be used.
|
2010-03-01 07:53:30 -06:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: py:attr
|
2010-03-01 07:53:30 -06:00
|
|
|
|
|
|
|
Reference a data attribute of an object.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: py:exc
|
2010-03-01 07:53:30 -06:00
|
|
|
|
|
|
|
Reference an exception. A dotted name may be used.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: py:obj
|
2010-03-01 07:53:30 -06:00
|
|
|
|
|
|
|
Reference an object of unspecified type. Useful e.g. as the
|
|
|
|
:confval:`default_role`.
|
|
|
|
|
|
|
|
.. versionadded:: 0.4
|
|
|
|
|
|
|
|
The name enclosed in this markup can include a module name and/or a class name.
|
2017-11-03 15:20:36 -05:00
|
|
|
For example, ``:py:func:`filter``` could refer to a function named ``filter``
|
|
|
|
in the current module, or the built-in function of that name. In contrast,
|
2010-03-01 07:53:30 -06:00
|
|
|
``:py:func:`foo.filter``` clearly refers to the ``filter`` function in the
|
|
|
|
``foo`` module.
|
|
|
|
|
|
|
|
Normally, names in these roles are searched first without any further
|
|
|
|
qualification, then with the current module name prepended, then with the
|
2017-11-03 15:20:36 -05:00
|
|
|
current module and class name (if any) prepended. If you prefix the name with
|
|
|
|
a dot, this order is reversed. For example, in the documentation of Python's
|
2010-03-01 07:53:30 -06:00
|
|
|
:mod:`codecs` module, ``:py:func:`open``` always refers to the built-in
|
|
|
|
function, while ``:py:func:`.open``` refers to :func:`codecs.open`.
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
A similar heuristic is used to determine whether the name is an attribute of
|
|
|
|
the currently documented class.
|
2010-08-05 06:39:23 -05:00
|
|
|
|
2010-06-12 04:37:56 -05:00
|
|
|
Also, if the name is prefixed with a dot, and no exact match is found, the
|
2017-11-03 15:20:36 -05:00
|
|
|
target is taken as a suffix and all object names with that suffix are searched.
|
|
|
|
For example, ``:py:meth:`.TarFile.close``` references the
|
2010-06-12 04:37:56 -05:00
|
|
|
``tarfile.TarFile.close()`` function, even if the current module is not
|
|
|
|
``tarfile``. Since this can get ambiguous, if there is more than one possible
|
|
|
|
match, you will get a warning from Sphinx.
|
|
|
|
|
2010-08-05 06:39:23 -05:00
|
|
|
Note that you can combine the ``~`` and ``.`` prefixes:
|
|
|
|
``:py:meth:`~.TarFile.close``` will reference the ``tarfile.TarFile.close()``
|
|
|
|
method, but the visible link caption will only be ``close()``.
|
2010-03-01 07:53:30 -06:00
|
|
|
|
|
|
|
|
2010-05-24 08:12:27 -05:00
|
|
|
.. _c-domain:
|
|
|
|
|
2010-03-01 07:22:14 -06:00
|
|
|
The C Domain
|
|
|
|
------------
|
|
|
|
|
|
|
|
The C domain (name **c**) is suited for documentation of C API.
|
|
|
|
|
2017-09-07 14:24:44 -05:00
|
|
|
.. rst:directive:: .. c:function:: function prototype
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Describes a C function. The signature should be given as in C, e.g.::
|
|
|
|
|
|
|
|
.. c:function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
|
|
|
|
|
|
|
|
This is also used to describe function-like preprocessor macros. The names
|
|
|
|
of the arguments should be given so they may be used in the description.
|
|
|
|
|
|
|
|
Note that you don't have to backslash-escape asterisks in the signature, as
|
|
|
|
it is not parsed by the reST inliner.
|
|
|
|
|
2017-09-07 14:24:44 -05:00
|
|
|
.. rst:directive:: .. c:member:: declaration
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Describes a C struct member. Example signature::
|
|
|
|
|
|
|
|
.. c:member:: PyObject* PyTypeObject.tp_bases
|
|
|
|
|
|
|
|
The text of the description should include the range of values allowed, how
|
|
|
|
the value should be interpreted, and whether the value can be changed.
|
|
|
|
References to structure members in text should use the ``member`` role.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. c:macro:: name
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Describes a "simple" C macro. Simple macros are macros which are used for
|
|
|
|
code expansion, but which do not take arguments so cannot be described as
|
2014-01-11 07:52:41 -06:00
|
|
|
functions. This is a simple C-language ``#define``. Examples of its use in
|
|
|
|
the Python documentation include :c:macro:`PyObject_HEAD` and
|
2010-03-01 07:22:14 -06:00
|
|
|
:c:macro:`Py_BEGIN_ALLOW_THREADS`.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. c:type:: name
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Describes a C type (whether defined by a typedef or struct). The signature
|
|
|
|
should just be the type name.
|
|
|
|
|
2017-09-07 14:24:44 -05:00
|
|
|
.. rst:directive:: .. c:var:: declaration
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
Describes a global C variable. The signature should include the type, such
|
|
|
|
as::
|
|
|
|
|
|
|
|
.. c:var:: PyObject* PyClass_Type
|
|
|
|
|
2011-01-06 13:44:55 -06:00
|
|
|
.. _c-roles:
|
|
|
|
|
2010-03-01 07:53:30 -06:00
|
|
|
Cross-referencing C constructs
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
The following roles create cross-references to C-language constructs if they
|
|
|
|
are defined in the documentation:
|
2010-03-01 07:53:30 -06:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: c:func
|
2010-03-01 07:53:30 -06:00
|
|
|
|
|
|
|
Reference a C-language function. Should include trailing parentheses.
|
|
|
|
|
2017-09-07 14:24:44 -05:00
|
|
|
.. rst:role:: c:member
|
|
|
|
|
|
|
|
Reference a C-language member of a struct.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: c:macro
|
2010-03-01 07:53:30 -06:00
|
|
|
|
|
|
|
Reference a "simple" C macro, as defined above.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:role:: c:type
|
2010-03-01 07:53:30 -06:00
|
|
|
|
|
|
|
Reference a C-language type.
|
|
|
|
|
2017-09-07 14:24:44 -05:00
|
|
|
.. rst:role:: c:data
|
|
|
|
|
|
|
|
Reference a C-language variable.
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
|
2017-07-18 03:52:02 -05:00
|
|
|
.. _cpp-domain:
|
2010-03-01 07:53:30 -06:00
|
|
|
|
2010-03-09 12:38:49 -06:00
|
|
|
The C++ Domain
|
|
|
|
--------------
|
|
|
|
|
|
|
|
The C++ domain (name **cpp**) supports documenting C++ projects.
|
|
|
|
|
2019-01-06 10:12:06 -06:00
|
|
|
Directives for Declaring Entities
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2017-01-14 09:52:08 -06:00
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
The following directives are available. All declarations can start with a
|
|
|
|
visibility statement (``public``, ``private`` or ``protected``).
|
2010-03-09 12:38:49 -06:00
|
|
|
|
2015-03-22 05:28:25 -05:00
|
|
|
.. rst:directive:: .. cpp:class:: class specifier
|
2019-01-09 12:27:54 -06:00
|
|
|
.. cpp:struct:: class specifier
|
2010-03-09 12:38:49 -06:00
|
|
|
|
2014-08-06 11:54:00 -05:00
|
|
|
Describe a class/struct, possibly with specification of inheritance, e.g.,::
|
2014-10-09 09:53:33 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
.. cpp:class:: MyClass : public MyBase, MyOtherBase
|
2014-08-06 11:54:00 -05:00
|
|
|
|
2019-01-09 12:27:54 -06:00
|
|
|
The difference between :rst:dir:`cpp:class` and :rst:dir:`cpp:struct` is
|
|
|
|
only cosmetic: the prefix rendered in the output, and the specifier shown
|
|
|
|
in the index.
|
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
The class can be directly declared inside a nested scope, e.g.,::
|
|
|
|
|
|
|
|
.. cpp:class:: OuterScope::MyClass : public MyBase, MyOtherBase
|
|
|
|
|
2017-05-03 23:34:00 -05:00
|
|
|
A class template can be declared::
|
2015-09-05 07:49:14 -05:00
|
|
|
|
|
|
|
.. cpp:class:: template<typename T, std::size_t N> std::array
|
|
|
|
|
2015-10-27 08:52:44 -05:00
|
|
|
or with a line break::
|
2015-09-05 07:49:14 -05:00
|
|
|
|
|
|
|
.. cpp:class:: template<typename T, std::size_t N> \
|
|
|
|
std::array
|
|
|
|
|
|
|
|
Full and partial template specialisations can be declared::
|
|
|
|
|
2016-08-02 14:22:50 -05:00
|
|
|
.. cpp:class:: template<> \
|
2018-05-26 10:25:41 -05:00
|
|
|
std::array<bool, 256>
|
2015-09-05 07:49:14 -05:00
|
|
|
|
2016-08-02 14:22:50 -05:00
|
|
|
.. cpp:class:: template<typename T> \
|
2018-05-26 10:25:41 -05:00
|
|
|
std::array<T, 42>
|
2015-09-05 07:49:14 -05:00
|
|
|
|
2019-01-09 12:27:54 -06:00
|
|
|
.. versionadded:: 2.0
|
|
|
|
The :rst:dir:`cpp:struct` directive.
|
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
.. rst:directive:: .. cpp:function:: (member) function prototype
|
2014-08-06 11:54:00 -05:00
|
|
|
|
|
|
|
Describe a function or member function, e.g.,::
|
2010-03-09 12:38:49 -06:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
.. cpp:function:: bool myMethod(int arg1, std::string arg2)
|
2010-05-27 07:12:24 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
A function with parameters and types.
|
2010-05-27 07:12:24 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
.. cpp:function:: bool myMethod(int, double)
|
2010-05-27 07:12:24 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
A function with unnamed parameters.
|
2010-05-27 07:12:24 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
.. cpp:function:: const T &MyClass::operator[](std::size_t i) const
|
2010-05-27 07:12:24 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
An overload for the indexing operator.
|
2010-05-27 07:12:24 -05:00
|
|
|
|
|
|
|
.. cpp:function:: operator bool() const
|
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
A casting operator.
|
2010-05-27 07:12:24 -05:00
|
|
|
|
2011-09-22 17:48:52 -05:00
|
|
|
.. cpp:function:: constexpr void foo(std::string &bar[2]) noexcept
|
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
A constexpr function.
|
2011-09-22 17:48:52 -05:00
|
|
|
|
2014-08-06 11:54:00 -05:00
|
|
|
.. cpp:function:: MyClass::MyClass(const MyClass&) = default
|
2010-05-27 07:12:24 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
A copy constructor with default implementation.
|
|
|
|
|
|
|
|
Function templates can also be described::
|
|
|
|
|
|
|
|
.. cpp:function:: template<typename U> \
|
|
|
|
void print(U &&u)
|
2010-05-27 07:12:24 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
and function template specialisations::
|
|
|
|
|
|
|
|
.. cpp:function:: template<> \
|
|
|
|
void print(int i)
|
|
|
|
|
|
|
|
.. rst:directive:: .. cpp:member:: (member) variable declaration
|
|
|
|
.. cpp:var:: (member) variable declaration
|
2011-09-22 17:48:52 -05:00
|
|
|
|
2016-01-01 13:54:30 -06:00
|
|
|
Describe a variable or member variable, e.g.,::
|
2011-09-22 17:48:52 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
.. cpp:member:: std::string MyClass::myMember
|
2010-05-27 07:12:24 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
.. cpp:var:: std::string MyClass::myOtherMember[N][M]
|
2011-09-22 17:48:52 -05:00
|
|
|
|
2015-02-26 14:44:46 -06:00
|
|
|
.. cpp:member:: int a = 42
|
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
Variable templates can also be described::
|
|
|
|
|
|
|
|
.. cpp:member:: template<class T> \
|
|
|
|
constexpr T pi = T(3.1415926535897932385)
|
|
|
|
|
|
|
|
.. rst:directive:: .. cpp:type:: typedef declaration
|
2014-08-06 11:54:00 -05:00
|
|
|
.. cpp:type:: name
|
2015-09-05 07:49:14 -05:00
|
|
|
.. cpp:type:: type alias declaration
|
2014-08-06 11:54:00 -05:00
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Describe a type as in a typedef declaration, a type alias declaration, or
|
|
|
|
simply the name of a type with unspecified type, e.g.,::
|
2014-08-06 11:54:00 -05:00
|
|
|
|
|
|
|
.. cpp:type:: std::vector<int> MyList
|
2014-07-27 04:42:01 -05:00
|
|
|
|
|
|
|
A typedef-like declaration of a type.
|
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
.. cpp:type:: MyContainer::const_iterator
|
2010-05-27 07:12:24 -05:00
|
|
|
|
2014-07-27 04:42:01 -05:00
|
|
|
Declaration of a type alias with unspecified type.
|
2010-03-09 12:38:49 -06:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
.. cpp:type:: MyType = std::unordered_map<int, std::string>
|
|
|
|
|
|
|
|
Declaration of a type alias.
|
|
|
|
|
|
|
|
A type alias can also be templated::
|
|
|
|
|
2016-03-30 02:55:02 -05:00
|
|
|
.. cpp:type:: template<typename T> \
|
2015-09-05 07:49:14 -05:00
|
|
|
MyContainer = std::vector<T>
|
2016-03-30 02:55:02 -05:00
|
|
|
|
|
|
|
The example are rendered as follows.
|
|
|
|
|
|
|
|
.. cpp:type:: std::vector<int> MyList
|
|
|
|
|
|
|
|
A typedef-like declaration of a type.
|
|
|
|
|
|
|
|
.. cpp:type:: MyContainer::const_iterator
|
|
|
|
|
|
|
|
Declaration of a type alias with unspecified type.
|
|
|
|
|
|
|
|
.. cpp:type:: MyType = std::unordered_map<int, std::string>
|
|
|
|
|
|
|
|
Declaration of a type alias.
|
|
|
|
|
|
|
|
.. cpp:type:: template<typename T> \
|
|
|
|
MyContainer = std::vector<T>
|
2015-09-05 07:49:14 -05:00
|
|
|
|
2015-02-08 16:09:44 -06:00
|
|
|
.. rst:directive:: .. cpp:enum:: unscoped enum declaration
|
|
|
|
.. cpp:enum-struct:: scoped enum declaration
|
|
|
|
.. cpp:enum-class:: scoped enum declaration
|
2015-01-03 09:59:08 -06:00
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Describe a (scoped) enum, possibly with the underlying type specified. Any
|
|
|
|
enumerators declared inside an unscoped enum will be declared both in the
|
|
|
|
enum scope and in the parent scope. Examples::
|
2015-01-03 09:59:08 -06:00
|
|
|
|
|
|
|
.. cpp:enum:: MyEnum
|
|
|
|
|
|
|
|
An unscoped enum.
|
|
|
|
|
|
|
|
.. cpp:enum:: MySpecificEnum : long
|
|
|
|
|
|
|
|
An unscoped enum with specified underlying type.
|
|
|
|
|
2015-02-08 16:09:44 -06:00
|
|
|
.. cpp:enum-class:: MyScopedEnum
|
2015-01-03 09:59:08 -06:00
|
|
|
|
|
|
|
A scoped enum.
|
|
|
|
|
2015-02-08 16:09:44 -06:00
|
|
|
.. cpp:enum-struct:: protected MyScopedVisibilityEnum : std::underlying_type<MySpecificEnum>::type
|
2015-01-03 09:59:08 -06:00
|
|
|
|
|
|
|
A scoped enum with non-default visibility, and with a specified underlying type.
|
|
|
|
|
|
|
|
.. rst:directive:: .. cpp:enumerator:: name
|
|
|
|
.. cpp:enumerator:: name = constant
|
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
Describe an enumerator, optionally with its value defined, e.g.,::
|
|
|
|
|
2016-08-02 14:22:50 -05:00
|
|
|
.. cpp:enumerator:: MyEnum::myEnumerator
|
2015-01-03 09:59:08 -06:00
|
|
|
|
2016-08-02 14:22:50 -05:00
|
|
|
.. cpp:enumerator:: MyEnum::myOtherEnumerator = 42
|
2010-03-09 12:38:49 -06:00
|
|
|
|
2018-05-26 13:03:25 -05:00
|
|
|
.. rst:directive:: .. cpp:union:: name
|
|
|
|
|
|
|
|
Describe a union.
|
|
|
|
|
2019-01-20 05:28:57 -06:00
|
|
|
.. versionadded:: 1.8
|
|
|
|
|
2016-05-28 01:31:03 -05:00
|
|
|
.. rst:directive:: .. cpp:concept:: template-parameter-list name
|
|
|
|
|
|
|
|
.. warning:: The support for concepts is experimental. It is based on the
|
2017-11-25 07:37:27 -06:00
|
|
|
current draft standard and the Concepts Technical Specification.
|
|
|
|
The features may change as they evolve.
|
2016-05-28 01:31:03 -05:00
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Describe a concept. It must have exactly 1 template parameter list. The name
|
|
|
|
may be a nested name. Example::
|
2016-05-28 01:31:03 -05:00
|
|
|
|
|
|
|
.. cpp:concept:: template<typename It> std::Iterator
|
|
|
|
|
|
|
|
Proxy to an element of a notional sequence that can be compared,
|
|
|
|
indirected, or incremented.
|
|
|
|
|
2017-05-03 23:34:00 -05:00
|
|
|
**Notation**
|
|
|
|
|
|
|
|
.. cpp:var:: It r
|
|
|
|
|
|
|
|
An lvalue.
|
|
|
|
|
|
|
|
**Valid Expressions**
|
|
|
|
|
|
|
|
- :cpp:expr:`*r`, when :cpp:expr:`r` is dereferenceable.
|
|
|
|
- :cpp:expr:`++r`, with return type :cpp:expr:`It&`, when :cpp:expr:`r` is incrementable.
|
|
|
|
|
2017-10-25 15:41:42 -05:00
|
|
|
This will render as follows:
|
2016-05-28 01:31:03 -05:00
|
|
|
|
|
|
|
.. cpp:concept:: template<typename It> std::Iterator
|
|
|
|
|
|
|
|
Proxy to an element of a notional sequence that can be compared,
|
|
|
|
indirected, or incremented.
|
|
|
|
|
2017-05-03 23:34:00 -05:00
|
|
|
**Notation**
|
|
|
|
|
|
|
|
.. cpp:var:: It r
|
|
|
|
|
|
|
|
An lvalue.
|
|
|
|
|
|
|
|
**Valid Expressions**
|
|
|
|
|
|
|
|
- :cpp:expr:`*r`, when :cpp:expr:`r` is dereferenceable.
|
2017-11-03 15:20:36 -05:00
|
|
|
- :cpp:expr:`++r`, with return type :cpp:expr:`It&`, when :cpp:expr:`r`
|
|
|
|
is incrementable.
|
2017-05-03 23:34:00 -05:00
|
|
|
|
2019-01-20 05:28:57 -06:00
|
|
|
.. versionadded:: 1.5
|
|
|
|
|
|
|
|
|
2017-01-14 09:52:08 -06:00
|
|
|
Options
|
2017-11-03 15:20:36 -05:00
|
|
|
^^^^^^^
|
2017-01-14 09:52:08 -06:00
|
|
|
|
|
|
|
Some directives support options:
|
|
|
|
|
|
|
|
- ``:noindex:``, see :ref:`basic-domain-markup`.
|
|
|
|
- ``:tparam-line-spec:``, for templated declarations.
|
|
|
|
If specified, each template parameter will be rendered on a separate line.
|
|
|
|
|
2019-01-20 05:28:57 -06:00
|
|
|
.. versionadded:: 1.6
|
|
|
|
|
2018-06-09 05:24:34 -05:00
|
|
|
Anonymous Entities
|
|
|
|
~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2018-12-25 12:10:25 -06:00
|
|
|
C++ supports anonymous namespaces, classes, enums, and unions.
|
2018-06-09 05:24:34 -05:00
|
|
|
For the sake of documentation they must be given some name that starts with ``@``,
|
|
|
|
e.g., ``@42`` or ``@data``.
|
|
|
|
These names can also be used in cross-references and (type) expressions,
|
|
|
|
though nested symbols will be found even when omitted.
|
|
|
|
The ``@...`` name will always be rendered as **[anonymous]** (possibly as a link).
|
|
|
|
|
|
|
|
Example::
|
|
|
|
|
|
|
|
.. cpp:class:: Data
|
|
|
|
|
|
|
|
.. cpp:union:: @data
|
|
|
|
|
|
|
|
.. cpp:var:: int a
|
|
|
|
|
|
|
|
.. cpp:var:: double b
|
|
|
|
|
|
|
|
Explicit ref: :cpp:var:`Data::@data::a`. Short-hand ref: :cpp:var:`Data::a`.
|
|
|
|
|
|
|
|
This will be rendered as:
|
|
|
|
|
|
|
|
.. cpp:class:: Data
|
|
|
|
|
|
|
|
.. cpp:union:: @data
|
|
|
|
|
|
|
|
.. cpp:var:: int a
|
|
|
|
|
|
|
|
.. cpp:var:: double b
|
|
|
|
|
|
|
|
Explicit ref: :cpp:var:`Data::@data::a`. Short-hand ref: :cpp:var:`Data::a`.
|
|
|
|
|
2019-01-20 05:28:57 -06:00
|
|
|
.. versionadded:: 1.8
|
|
|
|
|
2018-06-09 05:24:34 -05:00
|
|
|
|
2019-01-06 10:12:06 -06:00
|
|
|
Aliasing Declarations
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Sometimes it may be helpful list declarations elsewhere than their main documentation,
|
|
|
|
e.g., when creating a synopsis of a class interface.
|
|
|
|
The following directive can be used for this purpose.
|
|
|
|
|
|
|
|
.. rst:directive:: .. cpp:alias:: name or function signature
|
|
|
|
|
|
|
|
Insert one or more alias declarations. Each entity can be specified
|
|
|
|
as they can in the :rst:role:`cpp:any` role.
|
|
|
|
If the name of a function is given (as opposed to the complete signature),
|
|
|
|
then all overloads of the function will be listed.
|
|
|
|
|
|
|
|
For example::
|
|
|
|
|
|
|
|
.. cpp:alias:: Data::a
|
|
|
|
overload_example::C::f
|
|
|
|
|
|
|
|
becomes
|
|
|
|
|
|
|
|
.. cpp:alias:: Data::a
|
|
|
|
overload_example::C::f
|
|
|
|
|
|
|
|
whereas::
|
|
|
|
|
|
|
|
.. cpp:alias:: void overload_example::C::f(double d) const
|
|
|
|
void overload_example::C::f(double d)
|
|
|
|
|
|
|
|
becomes
|
|
|
|
|
2019-01-20 05:28:57 -06:00
|
|
|
.. cpp:alias:: void overload_example::C::f(double d) const
|
|
|
|
void overload_example::C::f(double d)
|
|
|
|
|
|
|
|
.. versionadded:: 2.0
|
2019-01-06 10:12:06 -06:00
|
|
|
|
|
|
|
|
2016-05-28 01:31:03 -05:00
|
|
|
Constrained Templates
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2017-11-25 07:37:27 -06:00
|
|
|
.. warning:: The support for concepts is experimental. It is based on the
|
|
|
|
current draft standard and the Concepts Technical Specification.
|
|
|
|
The features may change as they evolve.
|
2016-05-28 01:31:03 -05:00
|
|
|
|
|
|
|
.. note:: Sphinx does not currently support ``requires`` clauses.
|
|
|
|
|
|
|
|
Placeholders
|
2017-11-03 15:20:36 -05:00
|
|
|
^^^^^^^^^^^^
|
2016-05-28 01:31:03 -05:00
|
|
|
|
|
|
|
Declarations may use the name of a concept to introduce constrained template
|
2017-11-03 15:20:36 -05:00
|
|
|
parameters, or the keyword ``auto`` to introduce unconstrained template
|
|
|
|
parameters::
|
2016-05-28 01:31:03 -05:00
|
|
|
|
|
|
|
.. cpp:function:: void f(auto &&arg)
|
|
|
|
|
|
|
|
A function template with a single unconstrained template parameter.
|
|
|
|
|
|
|
|
.. cpp:function:: void f(std::Iterator it)
|
|
|
|
|
|
|
|
A function template with a single template parameter, constrained by the
|
|
|
|
Iterator concept.
|
|
|
|
|
2016-05-28 08:00:13 -05:00
|
|
|
Template Introductions
|
2017-11-03 15:20:36 -05:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^
|
2016-05-28 08:00:13 -05:00
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Simple constrained function or class templates can be declared with a `template
|
|
|
|
introduction` instead of a template parameter list::
|
2016-05-28 08:00:13 -05:00
|
|
|
|
|
|
|
.. cpp:function:: std::Iterator{It} void advance(It &it)
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
A function template with a template parameter constrained to be an
|
|
|
|
Iterator.
|
2016-05-28 08:00:13 -05:00
|
|
|
|
|
|
|
.. cpp:class:: std::LessThanComparable{T} MySortedContainer
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
A class template with a template parameter constrained to be
|
|
|
|
LessThanComparable.
|
2016-05-28 08:00:13 -05:00
|
|
|
|
|
|
|
They are rendered as follows.
|
|
|
|
|
|
|
|
.. cpp:function:: std::Iterator{It} void advance(It &it)
|
|
|
|
|
|
|
|
A function template with a template parameter constrained to be an Iterator.
|
|
|
|
|
|
|
|
.. cpp:class:: std::LessThanComparable{T} MySortedContainer
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
A class template with a template parameter constrained to be
|
|
|
|
LessThanComparable.
|
2016-05-28 08:00:13 -05:00
|
|
|
|
|
|
|
Note however that no checking is performed with respect to parameter
|
|
|
|
compatibility. E.g., ``Iterator{A, B, C}`` will be accepted as an introduction
|
|
|
|
even though it would not be valid C++.
|
|
|
|
|
2018-12-25 12:10:25 -06:00
|
|
|
Inline Expressions and Types
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2017-05-03 23:34:00 -05:00
|
|
|
|
|
|
|
.. rst:role:: cpp:expr
|
2018-05-26 10:25:41 -05:00
|
|
|
cpp:texpr
|
2017-05-03 23:34:00 -05:00
|
|
|
|
2018-05-26 10:25:41 -05:00
|
|
|
Insert a C++ expression or type either as inline code (``cpp:expr``)
|
|
|
|
or inline text (``cpp:texpr``). For example::
|
2017-05-03 23:34:00 -05:00
|
|
|
|
|
|
|
.. cpp:var:: int a = 42
|
|
|
|
|
|
|
|
.. cpp:function:: int f(int i)
|
|
|
|
|
2018-05-26 10:25:41 -05:00
|
|
|
An expression: :cpp:expr:`a * f(a)` (or as text: :cpp:texpr:`a * f(a)`).
|
|
|
|
|
|
|
|
A type: :cpp:expr:`const MySortedContainer<int>&`
|
|
|
|
(or as text :cpp:texpr:`const MySortedContainer<int>&`).
|
2017-05-03 23:34:00 -05:00
|
|
|
|
|
|
|
will be rendered as follows:
|
|
|
|
|
2018-05-26 10:25:41 -05:00
|
|
|
.. cpp:var:: int a = 42
|
|
|
|
|
|
|
|
.. cpp:function:: int f(int i)
|
2017-05-03 23:34:00 -05:00
|
|
|
|
2018-05-26 10:25:41 -05:00
|
|
|
An expression: :cpp:expr:`a * f(a)` (or as text: :cpp:texpr:`a * f(a)`).
|
|
|
|
|
|
|
|
A type: :cpp:expr:`const MySortedContainer<int>&`
|
|
|
|
(or as text :cpp:texpr:`const MySortedContainer<int>&`).
|
2017-05-03 23:34:00 -05:00
|
|
|
|
2019-01-20 05:28:57 -06:00
|
|
|
.. versionadded:: 1.7
|
|
|
|
The :rst:role:`cpp:expr` role.
|
|
|
|
|
|
|
|
.. versionadded:: 1.8
|
|
|
|
The :rst:role:`cpp:texpr` role.
|
2017-05-03 23:34:00 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
Namespacing
|
2017-11-03 15:20:36 -05:00
|
|
|
~~~~~~~~~~~
|
|
|
|
|
|
|
|
Declarations in the C++ domain are as default placed in global scope. The
|
|
|
|
current scope can be changed using three namespace directives. They manage a
|
|
|
|
stack declarations where ``cpp:namespace`` resets the stack and changes a given
|
|
|
|
scope.
|
2015-09-05 07:49:14 -05:00
|
|
|
|
2015-09-06 15:28:55 -05:00
|
|
|
The ``cpp:namespace-push`` directive changes the scope to a given inner scope
|
|
|
|
of the current one.
|
2017-11-03 15:20:36 -05:00
|
|
|
|
|
|
|
The ``cpp:namespace-pop`` directive undoes the most recent
|
|
|
|
``cpp:namespace-push`` directive.
|
2015-09-06 15:28:55 -05:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
.. rst:directive:: .. cpp:namespace:: scope specification
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Changes the current scope for the subsequent objects to the given scope, and
|
|
|
|
resets the namespace directive stack. Note that the namespace does not need
|
|
|
|
to correspond to C++ namespaces, but can end in names of classes, e.g.,::
|
2014-08-06 11:54:00 -05:00
|
|
|
|
|
|
|
.. cpp:namespace:: Namespace1::Namespace2::SomeClass::AnInnerClass
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
All subsequent objects will be defined as if their name were declared with
|
|
|
|
the scope prepended. The subsequent cross-references will be searched for
|
|
|
|
starting in the current scope.
|
2014-08-06 11:54:00 -05:00
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Using ``NULL``, ``0``, or ``nullptr`` as the scope will change to global
|
|
|
|
scope.
|
2015-02-08 16:09:44 -06:00
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
A namespace declaration can also be templated, e.g.,::
|
|
|
|
|
|
|
|
.. cpp:class:: template<typename T> \
|
|
|
|
std::vector
|
|
|
|
|
|
|
|
.. cpp:namespace:: template<typename T> std::vector
|
|
|
|
|
|
|
|
.. cpp:function:: std::size_t size() const
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
declares ``size`` as a member function of the class template
|
|
|
|
``std::vector``. Equivalently this could have been declared using::
|
2015-09-05 07:49:14 -05:00
|
|
|
|
|
|
|
.. cpp:class:: template<typename T> \
|
|
|
|
std::vector
|
|
|
|
|
|
|
|
.. cpp:function:: std::size_t size() const
|
|
|
|
|
2018-05-26 10:25:41 -05:00
|
|
|
or::
|
2015-09-05 07:49:14 -05:00
|
|
|
|
|
|
|
.. cpp:class:: template<typename T> \
|
|
|
|
std::vector
|
|
|
|
|
2015-09-06 15:28:55 -05:00
|
|
|
.. rst:directive:: .. cpp:namespace-push:: scope specification
|
|
|
|
|
|
|
|
Change the scope relatively to the current scope. For example, after::
|
|
|
|
|
|
|
|
.. cpp:namespace:: A::B
|
|
|
|
|
|
|
|
.. cpp:namespace-push:: C::D
|
|
|
|
|
|
|
|
the current scope will be ``A::B::C::D``.
|
|
|
|
|
2019-01-20 05:28:57 -06:00
|
|
|
.. versionadded:: 1.4
|
|
|
|
|
2015-09-06 15:28:55 -05:00
|
|
|
.. rst:directive:: .. cpp:namespace-pop::
|
|
|
|
|
|
|
|
Undo the previous ``cpp:namespace-push`` directive (*not* just pop a scope).
|
|
|
|
For example, after::
|
|
|
|
|
|
|
|
.. cpp:namespace:: A::B
|
|
|
|
|
|
|
|
.. cpp:namespace-push:: C::D
|
|
|
|
|
|
|
|
.. cpp:namespace-pop::
|
|
|
|
|
|
|
|
the current scope will be ``A::B`` (*not* ``A::B::C``).
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
If no previous ``cpp:namespace-push`` directive has been used, but only a
|
|
|
|
``cpp:namespace`` directive, then the current scope will be reset to global
|
|
|
|
scope. That is, ``.. cpp:namespace:: A::B`` is equivalent to::
|
2015-09-06 15:28:55 -05:00
|
|
|
|
|
|
|
.. cpp:namespace:: nullptr
|
|
|
|
|
|
|
|
.. cpp:namespace-push:: A::B
|
|
|
|
|
2019-01-20 05:28:57 -06:00
|
|
|
.. versionadded:: 1.4
|
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
Info field lists
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
The C++ directives support the following info fields (see also
|
|
|
|
:ref:`info-field-lists`):
|
2015-09-05 07:49:14 -05:00
|
|
|
|
|
|
|
* `param`, `parameter`, `arg`, `argument`: Description of a parameter.
|
2015-11-21 09:51:17 -06:00
|
|
|
* `tparam`: Description of a template parameter.
|
2015-09-05 07:49:14 -05:00
|
|
|
* `returns`, `return`: Description of a return value.
|
|
|
|
* `throws`, `throw`, `exception`: Description of a possibly thrown exception.
|
|
|
|
|
2011-01-06 13:44:55 -06:00
|
|
|
.. _cpp-roles:
|
|
|
|
|
2015-09-05 07:49:14 -05:00
|
|
|
Cross-referencing
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
2015-10-13 19:41:52 -05:00
|
|
|
These roles link to the given declaration types:
|
2010-03-09 12:38:49 -06:00
|
|
|
|
2015-02-26 14:44:46 -06:00
|
|
|
.. rst:role:: cpp:any
|
|
|
|
cpp:class
|
2019-01-09 12:27:54 -06:00
|
|
|
cpp:struct
|
2015-02-08 16:09:44 -06:00
|
|
|
cpp:func
|
|
|
|
cpp:member
|
2015-02-26 14:44:46 -06:00
|
|
|
cpp:var
|
2015-02-08 16:09:44 -06:00
|
|
|
cpp:type
|
2016-05-28 01:31:03 -05:00
|
|
|
cpp:concept
|
2015-02-08 16:09:44 -06:00
|
|
|
cpp:enum
|
|
|
|
cpp:enumerator
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Reference a C++ declaration by name (see below for details). The name must
|
|
|
|
be properly qualified relative to the position of the link.
|
2010-03-09 12:38:49 -06:00
|
|
|
|
2019-01-09 12:27:54 -06:00
|
|
|
.. versionadded:: 2.0
|
|
|
|
The :rst:role:`cpp:struct` role as alias for the :rst:role:`cpp:class` role.
|
|
|
|
|
2015-10-13 19:41:52 -05:00
|
|
|
.. admonition:: Note on References with Templates Parameters/Arguments
|
2010-06-05 11:21:48 -05:00
|
|
|
|
2018-05-26 10:25:41 -05:00
|
|
|
These roles follow the Sphinx :ref:`xref-syntax` rules. This means care must be
|
|
|
|
taken when referencing a (partial) template specialization, e.g. if the link looks like
|
|
|
|
this: ``:cpp:class:`MyClass<int>```.
|
|
|
|
This is interpreted as a link to ``int`` with a title of ``MyClass``.
|
|
|
|
In this case, escape the opening angle bracket with a backslash,
|
|
|
|
like this: ``:cpp:class:`MyClass\<int>```.
|
|
|
|
|
|
|
|
When a custom title is not needed it may be useful to use the roles for inline expressions,
|
|
|
|
:rst:role:`cpp:expr` and :rst:role:`cpp:texpr`, where angle brackets do not need escaping.
|
2010-06-05 11:21:48 -05:00
|
|
|
|
2015-10-13 19:41:52 -05:00
|
|
|
Declarations without template parameters and template arguments
|
2017-11-03 15:20:36 -05:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2015-10-13 19:41:52 -05:00
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
For linking to non-templated declarations the name must be a nested name, e.g.,
|
|
|
|
``f`` or ``MyClass::f``.
|
2015-10-13 19:41:52 -05:00
|
|
|
|
2018-08-14 16:54:50 -05:00
|
|
|
|
|
|
|
Overloaded (member) functions
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
When a (member) function is referenced using just its name, the reference
|
|
|
|
will point to an arbitrary matching overload.
|
2019-03-07 07:17:41 -06:00
|
|
|
The :rst:role:`cpp:any` and :rst:role:`cpp:func` roles use an alternative
|
2018-08-14 16:54:50 -05:00
|
|
|
format, which simply is a complete function declaration.
|
|
|
|
This will resolve to the exact matching overload.
|
|
|
|
As example, consider the following class declaration:
|
|
|
|
|
|
|
|
.. cpp:namespace-push:: overload_example
|
|
|
|
.. cpp:class:: C
|
|
|
|
|
|
|
|
.. cpp:function:: void f(double d) const
|
|
|
|
.. cpp:function:: void f(double d)
|
|
|
|
.. cpp:function:: void f(int i)
|
|
|
|
.. cpp:function:: void f()
|
|
|
|
|
|
|
|
References using the :rst:role:`cpp:func` role:
|
|
|
|
|
|
|
|
- Arbitrary overload: ``C::f``, :cpp:func:`C::f`
|
|
|
|
- Also arbitrary overload: ``C::f()``, :cpp:func:`C::f()`
|
|
|
|
- Specific overload: ``void C::f()``, :cpp:func:`void C::f()`
|
|
|
|
- Specific overload: ``void C::f(int)``, :cpp:func:`void C::f(int)`
|
|
|
|
- Specific overload: ``void C::f(double)``, :cpp:func:`void C::f(double)`
|
|
|
|
- Specific overload: ``void C::f(double) const``, :cpp:func:`void C::f(double) const`
|
|
|
|
|
|
|
|
Note that the :confval:`add_function_parentheses` configuration variable
|
|
|
|
does not influence specific overload references.
|
|
|
|
|
|
|
|
.. cpp:namespace-pop::
|
|
|
|
|
|
|
|
|
2015-10-13 19:41:52 -05:00
|
|
|
Templated declarations
|
2017-11-03 15:20:36 -05:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^
|
2015-10-13 19:41:52 -05:00
|
|
|
|
|
|
|
Assume the following declarations.
|
|
|
|
|
|
|
|
.. cpp:class:: Wrapper
|
|
|
|
|
|
|
|
.. cpp:class:: template<typename TOuter> \
|
|
|
|
Outer
|
|
|
|
|
|
|
|
.. cpp:class:: template<typename TInner> \
|
|
|
|
Inner
|
|
|
|
|
2018-05-26 10:25:41 -05:00
|
|
|
In general the reference must include the template parameter declarations,
|
2018-08-11 03:30:10 -05:00
|
|
|
and template arguments for the prefix of qualified names. For example:
|
|
|
|
|
|
|
|
- ``template\<typename TOuter> Wrapper::Outer``
|
|
|
|
(:cpp:class:`template\<typename TOuter> Wrapper::Outer`)
|
|
|
|
- ``template\<typename TOuter> template\<typename TInner> Wrapper::Outer<TOuter>::Inner``
|
|
|
|
(:cpp:class:`template\<typename TOuter> template\<typename TInner> Wrapper::Outer<TOuter>::Inner`)
|
|
|
|
|
|
|
|
Currently the lookup only succeed if the template parameter identifiers are equal strings.
|
|
|
|
That is, ``template\<typename UOuter> Wrapper::Outer`` will not work.
|
|
|
|
|
|
|
|
As a shorthand notation, if a template parameter list is omitted,
|
|
|
|
then the lookup will assume either a primary template or a non-template,
|
|
|
|
but not a partial template specialisation.
|
|
|
|
This means the following references work as well:
|
|
|
|
|
|
|
|
- ``Wrapper::Outer``
|
|
|
|
(:cpp:class:`Wrapper::Outer`)
|
|
|
|
- ``Wrapper::Outer::Inner``
|
|
|
|
(:cpp:class:`Wrapper::Outer::Inner`)
|
2017-11-03 15:20:36 -05:00
|
|
|
- ``template\<typename TInner> Wrapper::Outer::Inner``
|
|
|
|
(:cpp:class:`template\<typename TInner> Wrapper::Outer::Inner`)
|
2015-10-13 19:41:52 -05:00
|
|
|
|
|
|
|
(Full) Template Specialisations
|
2017-11-03 15:20:36 -05:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2015-10-13 19:41:52 -05:00
|
|
|
|
|
|
|
Assume the following declarations.
|
|
|
|
|
|
|
|
.. cpp:class:: template<typename TOuter> \
|
|
|
|
Outer
|
|
|
|
|
|
|
|
.. cpp:class:: template<typename TInner> \
|
|
|
|
Inner
|
|
|
|
|
|
|
|
.. cpp:class:: template<> \
|
|
|
|
Outer<int>
|
|
|
|
|
|
|
|
.. cpp:class:: template<typename TInner> \
|
|
|
|
Inner
|
|
|
|
|
|
|
|
.. cpp:class:: template<> \
|
|
|
|
Inner<bool>
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
In general the reference must include a template parameter list for each
|
|
|
|
template argument list. The full specialisation above can therefore be
|
|
|
|
referenced with ``template\<> Outer\<int>`` (:cpp:class:`template\<>
|
|
|
|
Outer\<int>`) and ``template\<> template\<> Outer\<int>::Inner\<bool>``
|
|
|
|
(:cpp:class:`template\<> template\<> Outer\<int>::Inner\<bool>`). As a
|
|
|
|
shorthand the empty template parameter list can be omitted, e.g.,
|
|
|
|
``Outer\<int>`` (:cpp:class:`Outer\<int>`) and ``Outer\<int>::Inner\<bool>``
|
|
|
|
(:cpp:class:`Outer\<int>::Inner\<bool>`).
|
2015-10-13 19:41:52 -05:00
|
|
|
|
|
|
|
Partial Template Specialisations
|
2017-11-03 15:20:36 -05:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2015-10-13 19:41:52 -05:00
|
|
|
|
|
|
|
Assume the following declaration.
|
|
|
|
|
|
|
|
.. cpp:class:: template<typename T> \
|
|
|
|
Outer<T*>
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
References to partial specialisations must always include the template
|
|
|
|
parameter lists, e.g., ``template\<typename T> Outer\<T*>``
|
|
|
|
(:cpp:class:`template\<typename T> Outer\<T*>`). Currently the lookup only
|
|
|
|
succeed if the template parameter identifiers are equal strings.
|
2015-10-13 19:41:52 -05:00
|
|
|
|
2016-08-05 17:08:02 -05:00
|
|
|
Configuration Variables
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
See :ref:`cpp-config`.
|
|
|
|
|
2019-02-08 11:47:19 -06:00
|
|
|
.. _domains-std:
|
2010-03-09 12:38:49 -06:00
|
|
|
|
2010-03-01 07:22:14 -06:00
|
|
|
The Standard Domain
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
The so-called "standard" domain collects all markup that doesn't warrant a
|
|
|
|
domain of its own. Its directives and roles are not prefixed with a domain
|
|
|
|
name.
|
|
|
|
|
|
|
|
The standard domain is also where custom object descriptions, added using the
|
|
|
|
:func:`~sphinx.application.Sphinx.add_object_type` API, are placed.
|
|
|
|
|
|
|
|
There is a set of directives allowing documenting command-line programs:
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. option:: name args, name args, ...
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Describes a command line argument or switch. Option argument names should
|
|
|
|
be enclosed in angle brackets. Examples::
|
2014-01-22 10:42:38 -06:00
|
|
|
|
|
|
|
.. option:: dest_dir
|
|
|
|
|
|
|
|
Destination directory.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
.. option:: -m <module>, --module <module>
|
|
|
|
|
|
|
|
Run a module as a script.
|
|
|
|
|
2014-01-22 10:42:38 -06:00
|
|
|
The directive will create cross-reference targets for the given options,
|
2018-12-25 12:10:25 -06:00
|
|
|
referenceable by :rst:role:`option` (in the example case, you'd use something
|
2014-01-22 10:42:38 -06:00
|
|
|
like ``:option:`dest_dir```, ``:option:`-m```, or ``:option:`--module```).
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2015-07-25 05:45:18 -05:00
|
|
|
``cmdoption`` directive is a deprecated alias for the ``option`` directive.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. envvar:: name
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Describes an environment variable that the documented code or program uses
|
2018-12-25 12:10:25 -06:00
|
|
|
or defines. Referenceable by :rst:role:`envvar`.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. program:: name
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2014-06-18 10:53:25 -05:00
|
|
|
Like :rst:dir:`py:currentmodule`, this directive produces no output.
|
|
|
|
Instead, it serves to notify Sphinx that all following :rst:dir:`option`
|
|
|
|
directives document options for the program called *name*.
|
2010-03-01 07:22:14 -06:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
If you use :rst:dir:`program`, you have to qualify the references in your
|
|
|
|
:rst:role:`option` roles by the program name, so if you have the following
|
2010-03-01 07:22:14 -06:00
|
|
|
situation ::
|
|
|
|
|
|
|
|
.. program:: rm
|
|
|
|
|
|
|
|
.. option:: -r
|
|
|
|
|
|
|
|
Work recursively.
|
|
|
|
|
|
|
|
.. program:: svn
|
|
|
|
|
|
|
|
.. option:: -r revision
|
|
|
|
|
|
|
|
Specify the revision to work upon.
|
|
|
|
|
|
|
|
then ``:option:`rm -r``` would refer to the first option, while
|
|
|
|
``:option:`svn -r``` would refer to the second one.
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
The program name may contain spaces (in case you want to document
|
|
|
|
subcommands like ``svn add`` and ``svn commit`` separately).
|
2010-03-01 07:22:14 -06:00
|
|
|
|
|
|
|
.. versionadded:: 0.5
|
|
|
|
|
|
|
|
There is also a very generic object description directive, which is not tied to
|
|
|
|
any domain:
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. describe:: text
|
2010-03-01 07:22:14 -06:00
|
|
|
.. object:: text
|
|
|
|
|
|
|
|
This directive produces the same formatting as the specific ones provided by
|
|
|
|
domains, but does not create index entries or cross-referencing targets.
|
|
|
|
Example::
|
|
|
|
|
|
|
|
.. describe:: PAPER
|
|
|
|
|
|
|
|
You can set this variable to select a paper size.
|
2010-03-30 13:40:46 -05:00
|
|
|
|
2010-04-08 14:33:03 -05:00
|
|
|
|
2010-03-30 13:40:46 -05:00
|
|
|
The JavaScript Domain
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
The JavaScript domain (name **js**) provides the following directives:
|
|
|
|
|
2017-02-25 22:26:28 -06:00
|
|
|
.. rst:directive:: .. js:module:: name
|
|
|
|
|
|
|
|
This directive sets the module name for object declarations that follow
|
|
|
|
after. The module name is used in the global module index and in cross
|
|
|
|
references. This directive does not create an object heading like
|
|
|
|
:rst:dir:`py:class` would, for example.
|
|
|
|
|
|
|
|
By default, this directive will create a linkable entity and will cause an
|
2017-11-03 15:20:36 -05:00
|
|
|
entry in the global module index, unless the ``noindex`` option is
|
|
|
|
specified. If this option is specified, the directive will only update the
|
|
|
|
current module name.
|
2017-02-25 22:26:28 -06:00
|
|
|
|
|
|
|
.. versionadded:: 1.6
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. js:function:: name(signature)
|
2010-03-30 13:40:46 -05:00
|
|
|
|
2010-05-27 06:52:02 -05:00
|
|
|
Describes a JavaScript function or method. If you want to describe
|
2017-11-03 15:20:36 -05:00
|
|
|
arguments as optional use square brackets as :ref:`documented <signatures>`
|
|
|
|
for Python signatures.
|
2010-03-30 14:14:01 -05:00
|
|
|
|
2010-03-31 10:15:43 -05:00
|
|
|
You can use fields to give more details about arguments and their expected
|
|
|
|
types, errors which may be thrown by the function, and the value being
|
|
|
|
returned::
|
|
|
|
|
2010-04-08 14:33:03 -05:00
|
|
|
.. js:function:: $.getJSON(href, callback[, errback])
|
2010-03-31 10:15:43 -05:00
|
|
|
|
2010-04-08 14:33:03 -05:00
|
|
|
:param string href: An URI to the location of the resource.
|
2014-01-11 07:52:41 -06:00
|
|
|
:param callback: Gets called with the object.
|
2010-04-08 14:33:03 -05:00
|
|
|
:param errback:
|
2014-01-11 07:52:41 -06:00
|
|
|
Gets called in case the request fails. And a lot of other
|
|
|
|
text so we need multiple lines.
|
2010-04-08 14:33:03 -05:00
|
|
|
:throws SomeError: For whatever reason in that case.
|
2014-01-11 07:52:41 -06:00
|
|
|
:returns: Something.
|
2010-03-31 10:15:43 -05:00
|
|
|
|
|
|
|
This is rendered as:
|
|
|
|
|
2010-04-08 14:33:03 -05:00
|
|
|
.. js:function:: $.getJSON(href, callback[, errback])
|
2010-03-31 10:15:43 -05:00
|
|
|
|
2010-04-08 14:33:03 -05:00
|
|
|
:param string href: An URI to the location of the resource.
|
2014-01-11 07:52:41 -06:00
|
|
|
:param callback: Gets called with the object.
|
2010-04-08 14:33:03 -05:00
|
|
|
:param errback:
|
2014-01-11 07:52:41 -06:00
|
|
|
Gets called in case the request fails. And a lot of other
|
2010-04-08 14:33:03 -05:00
|
|
|
text so we need multiple lines.
|
|
|
|
:throws SomeError: For whatever reason in that case.
|
2014-01-11 07:52:41 -06:00
|
|
|
:returns: Something.
|
2010-03-31 10:15:43 -05:00
|
|
|
|
2017-02-25 22:26:28 -06:00
|
|
|
.. rst:directive:: .. js:method:: name(signature)
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
This directive is an alias for :rst:dir:`js:function`, however it describes
|
|
|
|
a function that is implemented as a method on a class object.
|
2017-02-25 22:26:28 -06:00
|
|
|
|
|
|
|
.. versionadded:: 1.6
|
|
|
|
|
2010-05-27 06:52:02 -05:00
|
|
|
.. rst:directive:: .. js:class:: name
|
|
|
|
|
2017-11-03 15:20:36 -05:00
|
|
|
Describes a constructor that creates an object. This is basically like a
|
|
|
|
function but will show up with a `class` prefix::
|
2010-05-27 06:52:02 -05:00
|
|
|
|
|
|
|
.. js:class:: MyAnimal(name[, age])
|
|
|
|
|
|
|
|
:param string name: The name of the animal
|
|
|
|
:param number age: an optional age for the animal
|
|
|
|
|
|
|
|
This is rendered as:
|
|
|
|
|
|
|
|
.. js:class:: MyAnimal(name[, age])
|
|
|
|
|
|
|
|
:param string name: The name of the animal
|
|
|
|
:param number age: an optional age for the animal
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. js:data:: name
|
2010-03-30 14:39:18 -05:00
|
|
|
|
2010-03-30 17:22:57 -05:00
|
|
|
Describes a global variable or constant.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. js:attribute:: object.name
|
2010-03-30 17:22:57 -05:00
|
|
|
|
2010-04-08 14:33:03 -05:00
|
|
|
Describes the attribute *name* of *object*.
|
2010-03-30 14:39:18 -05:00
|
|
|
|
2011-01-06 13:44:55 -06:00
|
|
|
.. _js-roles:
|
|
|
|
|
2010-03-30 14:14:01 -05:00
|
|
|
These roles are provided to refer to the described objects:
|
|
|
|
|
2017-02-25 22:26:28 -06:00
|
|
|
.. rst:role:: js:mod
|
|
|
|
js:func
|
|
|
|
js:meth
|
2010-05-27 09:18:38 -05:00
|
|
|
js:class
|
2010-03-30 14:39:18 -05:00
|
|
|
js:data
|
2010-03-30 17:22:57 -05:00
|
|
|
js:attr
|
2010-04-15 14:55:18 -05:00
|
|
|
|
2010-04-17 03:29:14 -05:00
|
|
|
|
2010-04-15 14:55:18 -05:00
|
|
|
The reStructuredText domain
|
|
|
|
---------------------------
|
|
|
|
|
2010-04-17 03:29:14 -05:00
|
|
|
The reStructuredText domain (name **rst**) provides the following directives:
|
2010-04-15 14:55:18 -05:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. rst:directive:: name
|
2010-04-15 14:55:18 -05:00
|
|
|
|
2010-04-17 03:29:14 -05:00
|
|
|
Describes a reST directive. The *name* can be a single directive name or
|
|
|
|
actual directive syntax (`..` prefix and `::` suffix) with arguments that
|
|
|
|
will be rendered differently. For example::
|
2010-04-15 14:55:18 -05:00
|
|
|
|
|
|
|
.. rst:directive:: foo
|
2010-04-17 03:29:14 -05:00
|
|
|
|
|
|
|
Foo description.
|
|
|
|
|
2010-04-15 14:55:18 -05:00
|
|
|
.. rst:directive:: .. bar:: baz
|
2010-04-17 03:29:14 -05:00
|
|
|
|
|
|
|
Bar description.
|
|
|
|
|
2010-04-15 14:55:18 -05:00
|
|
|
will be rendered as:
|
2010-04-17 03:29:14 -05:00
|
|
|
|
2010-04-15 14:55:18 -05:00
|
|
|
.. rst:directive:: foo
|
2010-04-17 03:29:14 -05:00
|
|
|
|
|
|
|
Foo description.
|
|
|
|
|
2010-04-15 14:55:18 -05:00
|
|
|
.. rst:directive:: .. bar:: baz
|
|
|
|
|
2010-04-17 03:29:14 -05:00
|
|
|
Bar description.
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: .. rst:role:: name
|
2010-04-17 03:29:14 -05:00
|
|
|
|
|
|
|
Describes a reST role. For example::
|
|
|
|
|
2010-04-15 14:55:18 -05:00
|
|
|
.. rst:role:: foo
|
2010-04-17 03:29:14 -05:00
|
|
|
|
|
|
|
Foo description.
|
|
|
|
|
2010-04-15 14:55:18 -05:00
|
|
|
will be rendered as:
|
2010-04-17 03:29:14 -05:00
|
|
|
|
2010-04-15 14:55:18 -05:00
|
|
|
.. rst:role:: foo
|
2010-04-17 03:29:14 -05:00
|
|
|
|
|
|
|
Foo description.
|
|
|
|
|
2011-01-06 13:44:55 -06:00
|
|
|
.. _rst-roles:
|
|
|
|
|
2010-04-15 14:55:18 -05:00
|
|
|
These roles are provided to refer to the described objects:
|
|
|
|
|
|
|
|
.. rst:role:: rst:dir
|
|
|
|
rst:role
|
|
|
|
|
2018-07-28 05:54:56 -05:00
|
|
|
.. _math-domain:
|
|
|
|
|
|
|
|
The Math Domain
|
|
|
|
---------------
|
|
|
|
|
|
|
|
The math domain (name **math**) provides the following roles::
|
|
|
|
|
|
|
|
.. rst:role:: math:numref
|
|
|
|
|
|
|
|
Role for cross-referencing equations defined by :rst:dir:`math` directive
|
|
|
|
via their label. Example::
|
|
|
|
|
|
|
|
.. math:: e^{i\pi} + 1 = 0
|
|
|
|
:label: euler
|
|
|
|
|
|
|
|
Euler's identity, equation :math:numref:`euler`, was elected one of the
|
|
|
|
most beautiful mathematical formulas.
|
|
|
|
|
|
|
|
.. versionadded:: 1.8
|
2010-05-24 15:59:02 -05:00
|
|
|
|
|
|
|
More domains
|
|
|
|
------------
|
|
|
|
|
|
|
|
The sphinx-contrib_ repository contains more domains available as extensions;
|
2013-10-08 09:35:32 -05:00
|
|
|
currently Ada_, CoffeeScript_, Erlang_, HTTP_, Lasso_, MATLAB_, PHP_, and Ruby_
|
2015-01-30 15:34:16 -06:00
|
|
|
domains. Also available are domains for `Chapel`_, `Common Lisp`_, dqn_, Go_,
|
|
|
|
Jinja_, Operation_, and Scala_.
|
2010-05-24 15:59:02 -05:00
|
|
|
|
2011-02-05 14:48:54 -06:00
|
|
|
.. _sphinx-contrib: https://bitbucket.org/birkenfeld/sphinx-contrib/
|
2012-11-02 10:52:55 -05:00
|
|
|
|
2018-04-18 21:51:48 -05:00
|
|
|
.. _Ada: https://pypi.org/project/sphinxcontrib-adadomain/
|
|
|
|
.. _Chapel: https://pypi.org/project/sphinxcontrib-chapeldomain/
|
|
|
|
.. _CoffeeScript: https://pypi.org/project/sphinxcontrib-coffee/
|
|
|
|
.. _Common Lisp: https://pypi.org/project/sphinxcontrib-cldomain/
|
|
|
|
.. _dqn: https://pypi.org/project/sphinxcontrib-dqndomain/
|
|
|
|
.. _Erlang: https://pypi.org/project/sphinxcontrib-erlangdomain/
|
|
|
|
.. _Go: https://pypi.org/project/sphinxcontrib-golangdomain/
|
|
|
|
.. _HTTP: https://pypi.org/project/sphinxcontrib-httpdomain/
|
|
|
|
.. _Jinja: https://pypi.org/project/sphinxcontrib-jinjadomain/
|
|
|
|
.. _Lasso: https://pypi.org/project/sphinxcontrib-lassodomain/
|
|
|
|
.. _MATLAB: https://pypi.org/project/sphinxcontrib-matlabdomain/
|
|
|
|
.. _Operation: https://pypi.org/project/sphinxcontrib-operationdomain/
|
|
|
|
.. _PHP: https://pypi.org/project/sphinxcontrib-phpdomain/
|
2014-01-12 17:05:22 -06:00
|
|
|
.. _Ruby: https://bitbucket.org/birkenfeld/sphinx-contrib/src/default/rubydomain
|
2018-04-18 21:51:48 -05:00
|
|
|
.. _Scala: https://pypi.org/project/sphinxcontrib-scaladomain/
|