Skip to main content

lists.h File

Main C++ header file with the declarations for the µOS++ lists classes. More...

Included Headers

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

Namespaces Index

namespacemicro_os_plus

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

namespaceutils

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

Classes Index

classdouble_list<T, L>

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

classdouble_list_iterator<T, N, U>

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

classdouble_list_links

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

classdouble_list_links_base

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

classintrusive_list<T, N, MP, L, U>

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

classintrusive_list_iterator<T, N, MP, U>

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

classstatic_double_list_links

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

Description

Main C++ header file with the declarations for the µOS++ lists classes.

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 lists-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-2026 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
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
25
54
55#ifndef MICRO_OS_PLUS_UTILS_LISTS_H_
56#define MICRO_OS_PLUS_UTILS_LISTS_H_
57
58// ----------------------------------------------------------------------------
59
60#ifdef __cplusplus
61
62// ----------------------------------------------------------------------------
63
64#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
65#include <micro-os-plus/config.h>
66#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
67
68#include <cstdint>
69#include <cstddef>
70#include <cassert>
71#include <iterator>
72
73// ----------------------------------------------------------------------------
74
75#if defined(__GNUC__)
76#pragma GCC diagnostic push
77
78#pragma GCC diagnostic ignored "-Waggregate-return"
79#if defined(__clang__)
80#pragma clang diagnostic ignored "-Wc++98-compat"
81#endif
82#endif
83
99{
100 // ==========================================================================
101
118 {
119 public:
123 constexpr double_list_links_base ();
124
125 // This class follows the rule of five.
126
136
145
156 = delete;
157
167 = delete;
168
172 constexpr ~double_list_links_base ();
173
182 bool
183 uninitialized (void) const;
184
193 constexpr void
194 initialize (void);
195
204 void
205 initialize_once (void);
206
214 void
216
224 void
226
235 void
236 unlink (void);
237
246 bool
247 linked (void) const;
248
256 constexpr double_list_links_base*
257 next (void) const;
258
266 constexpr double_list_links_base*
267 previous (void) const;
268
269 protected:
274
279 };
280
281 // ==========================================================================
282
301 {
302 public:
307 using is_statically_allocated = std::false_type;
308
312 constexpr double_list_links ();
313
314 // This class follows the rule of five.
315
325
334
345 = delete;
346
356 = delete;
357
365 constexpr ~double_list_links ();
366 };
367
368 // ==========================================================================
369
401 {
402 public:
406 using is_statically_allocated = std::true_type;
407
412 constexpr static_double_list_links ();
413
423
433
444 = delete;
445
455 = delete;
456
460 constexpr ~static_double_list_links ();
461
470 void
471 nullify (void);
472 };
473
474 // ==========================================================================
475
493 template <class T, class N = T, class U = T>
495 {
496 public:
500 using value_type = U;
501
506
511
515 using iterator_pointer = N*;
516
520 using difference_type = ptrdiff_t;
521
525 using iterator_category = std::forward_iterator_tag;
526
527 // ------------------------------------------------------------------------
528
534
540 constexpr explicit double_list_iterator (iterator_pointer const node);
541
548 constexpr explicit double_list_iterator (reference element);
549
550 // DO NOT delete the copy constructors, since the default ones are
551 // used.
552
558 constexpr pointer
559 operator->() const;
560
566 constexpr reference
567 operator*() const;
568
574 constexpr double_list_iterator&
576
582 constexpr double_list_iterator
584
590 constexpr double_list_iterator&
592
598 constexpr double_list_iterator
600
608 constexpr bool
609 operator==(const double_list_iterator& other) const;
610
618 constexpr bool
619 operator!=(const double_list_iterator& other) const;
620
628 constexpr pointer
629 get_pointer (void) const;
630
638 constexpr iterator_pointer
640
641 protected:
646 };
647
648 // ==========================================================================
649
678 template <class T, class L = double_list_links>
680 {
681 public:
682 static_assert (std::is_base_of<double_list_links_base, L>::value == true,
683 "L must be derived from double_list_links_base!");
684 static_assert (std::is_base_of<double_list_links_base, T>::value == true,
685 "T must be derived from double_list_links_base!");
686
691 using links_type = L;
692
696 using value_type = T;
697
702
707
712
717
722 typename links_type::is_statically_allocated;
723
727 double_list ();
728
737 double_list (const double_list&) = delete;
738
748
759 = delete;
760
770 = delete;
771
775 constexpr ~double_list ();
776
777 public:
787 bool
788 uninitialized (void) const;
789
798 void
799 initialize_once (void);
800
809 bool
810 empty (void) const;
811
820 void
821 clear (void);
822
830 constexpr pointer
831 head (void) const;
832
840 constexpr pointer
841 tail (void) const;
842
850 void
851 link_tail (reference node);
852
860 void
861 link_head (reference node);
862
863 // ------------------------------------------------------------------------
864
871 begin () const;
872
879 end () const;
880
881 // Required in derived class iterator end(), where direct
882 // access to member fails.
890 constexpr const links_type*
891 links_pointer (void) const
892 {
893 return &links_;
894 }
895
896 // ------------------------------------------------------------------------
897
898 protected:
910 };
911
912 // ==========================================================================
913
932 template <class T, class N, N T::* MP, class U = T>
934 {
935 public:
939 using value_type = U;
940
945
950
954 using iterator_pointer = N*;
955
959 using difference_type = ptrdiff_t;
960
964 using iterator_category = std::forward_iterator_tag;
965
966 // ------------------------------------------------------------------------
967
973
979 constexpr explicit intrusive_list_iterator (iterator_pointer const node);
980
987 constexpr explicit intrusive_list_iterator (reference element);
988
989 // DO NOT delete the copy constructors, since this implies that
990 // the default ones will be used.
991
998 operator->() const;
999
1006 operator*() const;
1007
1015
1023
1031
1039
1047 bool
1049
1056 bool
1058
1066 pointer
1067 get_pointer (void) const;
1068
1078
1079 protected:
1087 };
1088
1089 // ==========================================================================
1090
1091#if defined(__clang__)
1092#pragma clang diagnostic push
1093#pragma clang diagnostic ignored "-Wdocumentation"
1094#endif
1134#if defined(__clang__)
1135#pragma clang diagnostic pop
1136#endif
1137
1138 template <class T, class N, N T::* MP, class L = double_list_links,
1139 class U = T>
1140 class intrusive_list : public double_list<N, L>
1141 {
1142 public:
1143 static_assert (std::is_base_of<double_list_links_base, L>::value == true,
1144 "L must be derived from double_list_links_base!");
1145 static_assert (std::is_base_of<double_list_links_base, N>::value == true,
1146 "N must be derived from double_list_links_base!");
1147
1152 using links_type = L;
1153
1157 using value_type = U;
1158
1163
1168
1173
1178 typename links_type::is_statically_allocated;
1179
1184
1188 using difference_type = ptrdiff_t;
1189
1193 constexpr intrusive_list ();
1194
1195 // This class follows the rule of five.
1196
1206
1216
1227 = delete;
1228
1238 = delete;
1239
1243 constexpr ~intrusive_list ();
1244
1245 public:
1254 void
1255 initialize_once (void);
1256
1265 constexpr bool
1266 empty (void) const;
1267
1275 void
1276 link_tail (reference node);
1277
1285 void
1286 link_head (reference node);
1287
1295 pointer
1296 unlink_tail (void);
1297
1305 pointer
1306 unlink_head (void);
1307
1308 // ------------------------------------------------------------------------
1309
1316 begin () const;
1317
1324 end () const;
1325
1326 // ------------------------------------------------------------------------
1327 protected:
1334 pointer
1335 get_pointer (iterator_pointer node) const;
1336 };
1337
1338 // --------------------------------------------------------------------------
1339} // namespace micro_os_plus::utils
1340
1341#if defined(__GNUC__)
1342#pragma GCC diagnostic pop
1343#endif
1344
1345// ----------------------------------------------------------------------------
1346
1347#endif // __cplusplus
1348
1349// ===== Inline & template implementations ====================================
1350
1351// All other inlines.
1352#include "lists-inlines.h"
1353
1354// ----------------------------------------------------------------------------
1355
1356#endif // MICRO_OS_PLUS_UTILS_LISTS_H_
1357
1358// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.14.0.