-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample-test.cpp
106 lines (82 loc) · 2.23 KB
/
sample-test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* This file is part of the µOS++ distribution.
* (https://github.com/micro-os-plus/)
* Copyright (c) 2021 Liviu Ionescu. All rights reserved.
*
* Permission to use, copy, modify, and/or distribute this software
* for any purpose is hereby granted, under the terms of the MIT license.
*
* If a copy of the license was not distributed with this file, it can
* be obtained from https://opensource.org/licenses/MIT/.
*/
// ----------------------------------------------------------------------------
#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
#include <micro-os-plus/config.h>
#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
#include <micro-os-plus/platform.h>
#include <micro-os-plus/utils/lists.h>
#include <unistd.h>
#include <stdio.h>
using namespace micro_os_plus;
// ----------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Waggregate-return"
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wc++98-compat"
#endif
class child
{
public:
child (const char* name)
{
name_ = name;
}
const char*
name ()
{
return name_;
}
void
unlink (void)
{
registry_links_.unlink ();
}
protected:
const char* name_;
public:
// Intrusive node used to link this child to the registry list.
// Must be public.
utils::double_list_links registry_links_;
};
using children_list
= utils::intrusive_list<child, decltype (child::registry_links_),
&child::registry_links_>;
int
main ([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
{
// Create an empty registry.
children_list children_registry;
// Add several members.
child marry{ "Marry" };
children_registry.link_tail (marry);
child bob{ "Bob" };
children_registry.link_tail (bob);
child sally{ "Sally" };
children_registry.link_tail (sally);
// List them.
for (auto&& p : children_registry)
{
printf ("%s\n", p.name ());
}
printf ("\n");
// Remove one of them.
bob.unlink ();
// List the remaining ones.
for (auto&& p : children_registry)
{
printf ("%s\n", p.name ());
}
return 0;
}
#pragma GCC diagnostic pop
// ----------------------------------------------------------------------------