Skip to main content

The lists.h File Reference

The file with the declarations of the µOS++ lists classes. More...

Included Headers

#include <cstdint>
#include <cstddef>
#include <cassert>
#include <iterator>
#include "inlines.h"

Classes

class

A class template for a doubly linked list of nodes. More...

class

A class template for a doubly linked list forward iterator. More...

class

A class for the core of a doubly linked list (pointers to neighbours). More...

class

A base class for a doubly linked list. More...

class

A class template for a list of nodes which store the links inside themselves as intrusive nodes. More...

class

A class template for the intrusive list iterator. More...

class

A class for the core of a statically allocated doubly linked list (pointers to neighbours). More...

Namespaces

namespace

The top µOS++ namespace.

namespace

The µOS++ utilities definitions.

Description

The lists.h header file contains the C++ declarations of the µOS++ Intrusive Lists classes, delivering an efficient and lightweight linked list management system tailored for embedded applications.

The classes implementations are in the lists.cpp and inlines.h files.

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.com/).
3 * Copyright (c) 2016 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any 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
10 */
11
49
50#ifndef MICRO_OS_PLUS_UTILS_LISTS_H_
51#define MICRO_OS_PLUS_UTILS_LISTS_H_
52
53// ----------------------------------------------------------------------------
54
55#ifdef __cplusplus
56
57// ----------------------------------------------------------------------------
58
59#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
60#include <micro-os-plus/config.h>
61#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
62
63#include <cstdint>
64#include <cstddef>
65#include <cassert>
66#include <iterator>
67
68// ----------------------------------------------------------------------------
69
70#if defined(__GNUC__)
71#pragma GCC diagnostic push
72
73#pragma GCC diagnostic ignored "-Waggregate-return"
74#if defined(__clang__)
75#pragma clang diagnostic ignored "-Wc++98-compat"
76#endif
77#endif
78
94{
95 // ==========================================================================
96
112 {
113 public:
117 constexpr double_list_links_base ();
118
122
123 // The rule of five.
127 operator= (const double_list_links_base&)
128 = delete;
130 operator= (double_list_links_base&&)
131 = delete;
132
136
140 constexpr ~double_list_links_base ();
141
149 bool
150 uninitialized (void) const;
151
159 constexpr void
160 initialize (void);
161
169 void
170 initialize_once (void);
171
179 void
181
189 void
191
197 void
198 unlink (void);
199
205 bool
206 linked (void) const;
207
212 constexpr double_list_links_base*
213 next (void) const;
214
219 constexpr double_list_links_base*
220 previous (void) const;
221
222 protected:
227
232 };
233
234 // ==========================================================================
235
251 {
252 public:
257 using is_statically_allocated = std::false_type;
258
262 constexpr double_list_links ();
263
267
268 // The rule of five.
269 double_list_links (const double_list_links&) = delete;
272 operator= (const double_list_links&)
273 = delete;
275 operator= (double_list_links&&)
276 = delete;
277
281
285 constexpr ~double_list_links ();
286 };
287
288 // ==========================================================================
289
324 {
325 public:
329 using is_statically_allocated = std::true_type;
330
335 constexpr static_double_list_links ();
336
340
341 // The rule of five.
345 operator= (const static_double_list_links&)
346 = delete;
348 operator= (static_double_list_links&&)
349 = delete;
350
354
358 constexpr ~static_double_list_links ();
359
367 void
368 nullify (void);
369 };
370
371 // ==========================================================================
372
387 template <class T, class N = T, class U = T>
389 {
390 public:
394 using value_type = U;
395
400
405
409 using iterator_pointer = N*;
410
414 using difference_type = ptrdiff_t;
415
419 using iterator_category = std::forward_iterator_tag;
420
421 // ------------------------------------------------------------------------
423
424 constexpr explicit double_list_iterator (iterator_pointer const node);
425
426 constexpr explicit double_list_iterator (reference element);
427
428 // DO NOT delete the copy constructors, since the default ones are
429 // used.
430
431 constexpr pointer
432 operator->() const;
433
434 constexpr reference
435 operator* () const;
436
437 constexpr double_list_iterator&
439
440 constexpr double_list_iterator
442
443 constexpr double_list_iterator&
445
446 constexpr double_list_iterator
448
449 constexpr bool
450 operator== (const double_list_iterator& other) const;
451
452 constexpr bool
453 operator!= (const double_list_iterator& other) const;
454
455 constexpr pointer
456 get_pointer () const;
457
458 constexpr iterator_pointer
460
461 protected:
466 };
467
468 // ==========================================================================
469
500 template <class T, class L = double_list_links>
502 {
503 public:
504 static_assert (std::is_base_of<double_list_links_base, L>::value == true,
505 "L must be derived from double_list_links_base!");
506 static_assert (std::is_base_of<double_list_links_base, T>::value == true,
507 "T must be derived from double_list_links_base!");
508
513 using links_type = L;
514
518 using value_type = T;
519
524
529
534
539
544 typename links_type::is_statically_allocated;
545
549 double_list ();
550
554
555 // The rule of five.
556 double_list (const double_list&) = delete;
557 double_list (double_list&&) = delete;
559 operator= (const double_list&)
560 = delete;
562 operator= (double_list&&)
563 = delete;
564
568
572 constexpr ~double_list ();
573
574 public:
583 bool
584 uninitialized (void) const;
585
593 void
594 initialize_once (void);
595
603 bool
604 empty (void) const;
605
613 void
614 clear (void);
615
622 constexpr pointer
623 head (void) const;
624
631 constexpr pointer
632 tail (void) const;
633
637 void
638 link_tail (reference node);
639
643 void
644 link_head (reference node);
645
646 // ------------------------------------------------------------------------
647
653 begin () const;
654
660 end () const;
661
662 // Required in derived class iterator end(), where direct
663 // access to member fails.
668 constexpr const links_type*
670 {
671 return &links_;
672 }
673
674 // ------------------------------------------------------------------------
675
676 protected:
689 };
690
691 // ==========================================================================
692
708 template <class T, class N, N T::*MP, class U = T>
710 {
711 public:
715 using value_type = U;
716
721
726
730 using iterator_pointer = N*;
731
735 using difference_type = ptrdiff_t;
736
740 using iterator_category = std::forward_iterator_tag;
741
742 // ------------------------------------------------------------------------
744
745 constexpr explicit intrusive_list_iterator (iterator_pointer const node);
746
747 constexpr explicit intrusive_list_iterator (reference element);
748
749 // DO NOT delete the copy constructors, since the default ones are
750 // used.
751
753 operator->() const;
754
756 operator* () const;
757
760
763
766
769
770 bool
772
773 bool
775
781 get_pointer (void) const;
782
785
786 protected:
791 };
792
793 // ==========================================================================
794
795#if defined(__clang__)
796#pragma clang diagnostic push
797#pragma clang diagnostic ignored "-Wdocumentation"
798#endif
832#if defined(__clang__)
833#pragma clang diagnostic pop
834#endif
835
836 template <class T, class N, N T::*MP, class L = double_list_links,
837 class U = T>
838 class intrusive_list : public double_list<N, L>
839 {
840 public:
841 static_assert (std::is_base_of<double_list_links_base, L>::value == true,
842 "L must be derived from double_list_links_base!");
843 static_assert (std::is_base_of<double_list_links_base, N>::value == true,
844 "N must be derived from double_list_links_base!");
845
850 using links_type = L;
851
855 using value_type = U;
856
861
866
871
876 typename links_type::is_statically_allocated;
877
881 using iterator_pointer = N*;
882
886 using difference_type = ptrdiff_t;
887
891 constexpr intrusive_list ();
892
896
897 // The rule of five.
898 intrusive_list (const intrusive_list&) = delete;
899 intrusive_list (intrusive_list&&) = delete;
901 operator= (const intrusive_list&)
902 = delete;
904 operator= (intrusive_list&&)
905 = delete;
906
910
914 constexpr ~intrusive_list ();
915
916 public:
924 void
925 initialize_once (void);
926
934 constexpr bool
935 empty (void) const;
936
943 void
944 link_tail (reference node);
945
952 void
953 link_head (reference node);
954
960 unlink_tail (void);
961
967 unlink_head (void);
968
969 // ------------------------------------------------------------------------
970
976 begin () const;
977
983 end () const;
984
985 // ------------------------------------------------------------------------
986 protected:
992 get_pointer (iterator_pointer node) const;
993 };
994
995 // --------------------------------------------------------------------------
996} // namespace micro_os_plus::utils
997
998#if defined(__GNUC__)
999#pragma GCC diagnostic pop
1000#endif
1001
1002// ----------------------------------------------------------------------------
1003
1004#endif // __cplusplus
1005
1006// ===== Inline & template implementations ====================================
1007
1008// All other inlines.
1009#include "inlines.h"
1010
1011// ----------------------------------------------------------------------------
1012
1013#endif // MICRO_OS_PLUS_UTILS_LISTS_H_
1014
1015// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.13.2