Skip to main content

doubly-list-inlines.h File

C++ header file with the inline implementations for the doubly_list_iterator and doubly_list class templates. More...

Namespaces Index

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespaceutils

The µOS++ utilities definitions. More...

Description

C++ header file with the inline implementations for the doubly_list_iterator and doubly_list class templates.

Class definitions are located in doubly-list.h. Inline methods are separated into this file to improve project structure and maintainability.

File Listing

The file content with the documentation metadata removed is:

1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can be
9 * obtained from https://opensource.org/licenses/mit.
10 */
11
12// ----------------------------------------------------------------------------
13
14#if !defined(MICRO_OS_PLUS_UTILS_LISTS_DOUBLY_LIST_H_)
15#error \
16 "Do not include this file directly; use micro-os-plus/utils/doubly-list.h."
17#endif // MICRO_OS_PLUS_UTILS_LISTS_DOUBLY_LIST_H_
18
29
30#ifndef MICRO_OS_PLUS_UTILS_LISTS_INLINES_DOUBLY_LIST_INLINES_H_
31#define MICRO_OS_PLUS_UTILS_LISTS_INLINES_DOUBLY_LIST_INLINES_H_
32
33// ----------------------------------------------------------------------------
34
35#if defined(__cplusplus)
36
37// ----------------------------------------------------------------------------
38
39#if defined(__GNUC__)
40#pragma GCC diagnostic push
41
42#pragma GCC diagnostic ignored "-Waggregate-return"
43#if defined(__clang__)
44#pragma clang diagnostic ignored "-Wc++98-compat"
45#endif // defined(__clang__)
46#endif // defined(__GNUC__)
47
48// ----------------------------------------------------------------------------
49
51{
52 // ==========================================================================
53
66 template <class T, class N, class U>
68 : node_{}
69 {
70 }
71
80 template <class T, class N, class U>
82 iterator_pointer const node) noexcept
83 : node_{ node }
84 {
85 }
86
95 template <class T, class N, class U>
97 reference element) noexcept
98 : node_{ &element }
99 {
100 }
101
110 template <class T, class N, class U>
113 {
114 return get_pointer ();
115 }
116
128 template <class T, class N, class U>
131 {
132 return *get_pointer ();
133 }
134
143 template <class T, class N, class U>
146 {
147 node_ = static_cast<N*> (node_->next ());
148 return *this;
149 }
150
159 template <class T, class N, class U>
162 {
163 const auto tmp = *this;
164 node_ = static_cast<iterator_pointer> (node_->next ());
165 return tmp;
166 }
167
176 template <class T, class N, class U>
179 {
180 node_ = static_cast<iterator_pointer> (node_->previous ());
181 return *this;
182 }
183
192 template <class T, class N, class U>
195 {
196 const auto tmp = *this;
197 node_ = static_cast<iterator_pointer> (node_->previous ());
198 return tmp;
199 }
200
209 template <class T, class N, class U>
210 constexpr bool
212 const doubly_list_iterator& other) const noexcept
213 {
214 return node_ == other.node_;
215 }
216
224 template <class T, class N, class U>
227 {
228 return node_;
229 }
230
237 template <class T, class N, class U>
240 {
241 return static_cast<pointer> (node_);
242 }
243
244 // ==========================================================================
245
269 template <doubly_list_links_node T, doubly_list_links_node L>
271 {
272#if defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_CONSTRUCTORS_ENABLED)
273 trace::printf ("%s() @%p \n", __func__, static_cast<const void*> (this));
274#endif // defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_CONSTRUCTORS_ENABLED)
275
276 if constexpr (is_statically_allocated::value)
277 {
278 // By all means, do not add any code to clear the pointers, since
279 // the links node was statically initialised.
280 }
281 else
282 {
283 clear ();
284 }
285 }
286
299 template <doubly_list_links_node T, doubly_list_links_node L>
301 {
302#if defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_CONSTRUCTORS_ENABLED)
303 trace::printf ("%s() @%p \n", __func__, static_cast<const void*> (this));
304#endif // defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_CONSTRUCTORS_ENABLED)
305
306 // Perhaps enable it for non statically allocated lists.
307 // assert (empty ());
308#if defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
309 if (!empty ())
310 {
311 trace::printf ("%s() @%p list not empty\n", __func__,
312 static_cast<const void*> (this));
313 }
314#endif // defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
315 }
316
325 template <doubly_list_links_node T, doubly_list_links_node L>
326 bool
327 doubly_list<T, L>::initialised (void) const noexcept
328 {
329 if constexpr (is_statically_allocated::value)
330 {
331 return links_.initialised ();
332 }
333 else
334 {
335 return true;
336 }
337 }
338
351 template <doubly_list_links_node T, doubly_list_links_node L>
352 bool
354 {
355#if defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
356 trace::printf ("%s() @%p\n", __func__, static_cast<const void*> (this));
357#endif // defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
358
359 if constexpr (is_statically_allocated::value)
360 {
361 return links_.initialise_once ();
362 }
363 else
364 {
365 return false;
366 }
367 }
368
376 template <doubly_list_links_node T, doubly_list_links_node L>
377 [[nodiscard]] constexpr bool
378 doubly_list<T, L>::empty (void) const noexcept
379 {
380 // If the links node is not linked, the list is empty.
381 return !links_.linked ();
382 }
383
392 template <doubly_list_links_node T, doubly_list_links_node L>
393 void
395 {
396#if defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
397 trace::printf ("%s() @%p\n", __func__, static_cast<const void*> (this));
398#endif // defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
399
400 links_.initialise ();
401 }
411 template <doubly_list_links_node T, doubly_list_links_node L>
412 constexpr typename doubly_list<T, L>::pointer
413 doubly_list<T, L>::head (void) const noexcept
414 {
415 return static_cast<pointer> (links_.next ());
416 }
417
426 template <doubly_list_links_node T, doubly_list_links_node L>
427 constexpr typename doubly_list<T, L>::pointer
428 doubly_list<T, L>::tail (void) const noexcept
429 {
430 return static_cast<pointer> (links_.previous ());
431 }
441 template <doubly_list_links_node T, doubly_list_links_node L>
442 void
444 {
445#if defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
446 trace::printf ("%s() @%p %p\n", __func__, static_cast<const void*> (this),
447 static_cast<const void*> (&node));
448#endif // defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
449
450 if constexpr (is_statically_allocated::value)
451 {
452 assert (links_.initialised ());
453 }
454
455 // Add new node at the end of the list.
456 tail ()->link_next (&node);
457 }
467 template <doubly_list_links_node T, doubly_list_links_node L>
468 void
470 {
471#if defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
472 trace::printf ("%s() @%p %p\n", __func__, static_cast<const void*> (this),
473 static_cast<const void*> (&node));
474#endif // defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
475
476 if constexpr (is_statically_allocated::value)
477 {
478 assert (links_.initialised ());
479 }
480
481 // Add the new node at the head of the list.
482 head ()->link_previous (&node);
483 }
493 template <doubly_list_links_node T, doubly_list_links_node L>
495 doubly_list<T, L>::begin () const noexcept
496 {
497#if defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
498 trace::printf ("%s() @%p\n", __func__, static_cast<const void*> (this));
499#endif // defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
500
501 if constexpr (is_statically_allocated::value)
502 {
503 assert (links_.initialised ());
504 }
505
506 return iterator{ static_cast<iterator_pointer> (links_.next ()) };
507 }
508
517 template <doubly_list_links_node T, doubly_list_links_node L>
519 doubly_list<T, L>::end () const noexcept
520 {
521#if defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
522 trace::printf ("%s() @%p\n", __func__, static_cast<const void*> (this));
523#endif // defined(MICRO_OS_PLUS_UTILS_LISTS_TRACE_ENABLED)
524
525 // The assert would probably be redundant, since it was
526 // already tested in `begin()`.
527
528 return iterator{ reinterpret_cast<iterator_pointer> (
529 const_cast<links_type*> (&links_)) };
530 }
531
538 template <doubly_list_links_node T, doubly_list_links_node L>
540 doubly_list<T, L>::rbegin () const noexcept
541 {
542 return reverse_iterator{ end () };
543 }
544
551 template <doubly_list_links_node T, doubly_list_links_node L>
553 doubly_list<T, L>::rend () const noexcept
554 {
555 return reverse_iterator{ begin () };
556 }
557
565 template <doubly_list_links_node T, doubly_list_links_node L>
566 constexpr const typename doubly_list<T, L>::links_type*
568 {
569 return &links_;
570 }
571
572 // --------------------------------------------------------------------------
573} // namespace micro_os_plus::utils
574
575#if defined(__GNUC__)
576#pragma GCC diagnostic pop
577#endif // defined(__GNUC__)
578
579// ----------------------------------------------------------------------------
580
581#endif // defined(__cplusplus)
582
583// ----------------------------------------------------------------------------
584
585#endif // MICRO_OS_PLUS_UTILS_LISTS_INLINES_DOUBLY_LIST_INLINES_H_
586
587// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.