Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions doc/developer-guide/internal-libraries/intrusive-list.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Examples
In this example the goal is to have a list of :code:`Message` objects. First the class is declared
along with the internal linkage support.

.. literalinclude:: ../../../src/tscore/unit_tests/test_IntrusiveDList.cc
.. literalinclude:: ../../../src/tscpp/util/unit_tests/test_IntrusiveDList.cc
:lines: 38-63

The struct :code:`Linkage` is used both to provide the descriptor to :class:`IntrusiveDList` and to
Expand All @@ -144,35 +144,35 @@ used only by a specific container class (:code:`Container`) the struct is made p

The implementation of the link accessor methods.

.. literalinclude:: ../../../src/tscore/unit_tests/test_IntrusiveDList.cc
.. literalinclude:: ../../../src/tscpp/util/unit_tests/test_IntrusiveDList.cc
:lines: 65-74

A method to check if the message is in a list.

.. literalinclude:: ../../../src/tscore/unit_tests/test_IntrusiveDList.cc
.. literalinclude:: ../../../src/tscpp/util/unit_tests/test_IntrusiveDList.cc
:lines: 76-80

The container class for the messages could be implemented as

.. literalinclude:: ../../../src/tscore/unit_tests/test_IntrusiveDList.cc
.. literalinclude:: ../../../src/tscpp/util/unit_tests/test_IntrusiveDList.cc
:lines: 82-99

The :code:`debug` method takes a format string (:arg:`fmt`) and an arbitrary set of arguments, formats
the arguments in to the string, and adds the new message to the list.

.. literalinclude:: ../../../src/tscore/unit_tests/test_IntrusiveDList.cc
.. literalinclude:: ../../../src/tscpp/util/unit_tests/test_IntrusiveDList.cc
:lines: 122-131

The :code:`print` method demonstrates the use of the range :code:`for` loop on a list.

.. literalinclude:: ../../../src/tscore/unit_tests/test_IntrusiveDList.cc
.. literalinclude:: ../../../src/tscpp/util/unit_tests/test_IntrusiveDList.cc
:lines: 142-148

The maximum severity level can also be computed even more easily using :code:`std::max_element`.
This find the element with the maximum severity and returns that severity, or :code:`LVL_DEBUG` if
no element is found (which happens if the list is empty).

.. literalinclude:: ../../../src/tscore/unit_tests/test_IntrusiveDList.cc
.. literalinclude:: ../../../src/tscpp/util/unit_tests/test_IntrusiveDList.cc
:lines: 134-140

Other methods for the various severity levels would be implemented in a similar fashion. Because the
Expand All @@ -183,20 +183,20 @@ risky. One approach, illustrated here, is to use :func:`IntrusiveDList::take_hea
element before destroying it. Another option is to allocation the elements in a :class:`MemArena` to
avoid the need for any explicit cleanup.

.. literalinclude:: ../../../src/tscore/unit_tests/test_IntrusiveDList.cc
.. literalinclude:: ../../../src/tscpp/util/unit_tests/test_IntrusiveDList.cc
:lines: 106-114

In some cases the elements of the list are subclasses and the links are declared in a super class
and are therefore of the super class type. For instance, in the unit test a class :code:`Thing` is
defined for testing.

.. literalinclude:: ../../../src/tscore/unit_tests/test_IntrusiveDList.cc
.. literalinclude:: ../../../src/tscpp/util/unit_tests/test_IntrusiveDList.cc
:lines: 159

Later on, to validate use on a subclass, :code:`PrivateThing` is defined as a subclass of
:code:`Thing`.

.. literalinclude:: ../../../src/tscore/unit_tests/test_IntrusiveDList.cc
.. literalinclude:: ../../../src/tscpp/util/unit_tests/test_IntrusiveDList.cc
:lines: 181

However, the link members :code:`_next` and :code:`_prev` are of type :code:`Thing*` but the
Expand All @@ -205,7 +205,7 @@ descriptor for a list of :code:`PrivateThing` must have link accessors that retu
:code:`ts::ptr_ref_cast<X, T>` that converts a member of type :code:`T*` to a reference to a pointer
to :code:`X`, e.g. :code:`X*&`. This is used in the setup for testing :code:`PrivateThing`.

.. literalinclude:: ../../../src/tscore/unit_tests/test_IntrusiveDList.cc
.. literalinclude:: ../../../src/tscpp/util/unit_tests/test_IntrusiveDList.cc
:lines: 190-199

While this can be done directly with :code:`reinterpret_cast<>`, use of :code:`ts::ptr_cast` avoids
Expand Down
Loading