UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
list.cpp
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2014-2023 CESNET, z. s. p. o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <list>
39
40#include "utils/list.h"
41
42using std::list;
43
45 list <void *> l;
46};
47
48struct sll_it {
49 list <void *>::iterator end;
50 list <void *>::iterator it;
51};
52
54{
55 return new simple_linked_list();
56}
57
59{
60 delete l;
61}
62
64{
65 l->l.push_front(data);
66}
67
69{
70 l->l.push_back(data);
71}
72
73bool simple_linked_list_append_if_less(struct simple_linked_list *l, void *data, int max_size)
74{
75 if (l->l.size() >= (unsigned) max_size) {
76 return false;
77 }
78 l->l.push_back(data);
79 return true;
80}
81
83{
84 if (simple_linked_list_size(l) == 0) {
85 return nullptr;
86 }
87 void *ret = l->l.front();
88 l->l.pop_front();
89
90 return ret;
91}
92
94{
95 return l->l.size();
96}
97
99{
100 return l->l.front();
101}
102
104{
105 return l->l.back();
106}
107
109{
110 if (l->l.size() == 0) {
111 return nullptr;
112 }
113 auto ret = new sll_it();
114 ret->it = l->l.begin();
115 ret->end = l->l.end();
116 return ret;
117}
118
120{
121 auto sit = (sll_it *) *i;
122
123 void *ret = *sit->it;
124 ++sit->it;
125 if (sit->it == sit->end) {
126 delete sit;
127 *i = nullptr;
128 }
129 return ret;
130}
131
133{
134 const auto *sit = static_cast<const sll_it *>(it);
135
136 return *sit->it;
137}
138
140{
141 delete (sll_it *) i;
142}
143
145{
146 for (auto it = l->l.begin(); it != l->l.end(); ++it) {
147 if (*it == item) {
148 l->l.erase(it);
149 return true;
150 }
151 }
152 return false;
153}
154
156{
157 int i = 0;
158 for (auto it = l->l.begin(); it != l->l.end(); ++it) {
159 if (i++ == index) {
160 void *ret = *it;
161 l->l.erase(it);
162 return ret;
163 }
164 }
165 return nullptr;
166}
167
void simple_linked_list_append(struct simple_linked_list *l, void *data)
Definition list.cpp:68
void simple_linked_list_prepend(struct simple_linked_list *l, void *data)
Definition list.cpp:63
void * simple_linked_list_it_peek_next(const void *it)
Definition list.cpp:132
void * simple_linked_list_it_next(void **i)
Definition list.cpp:119
bool simple_linked_list_remove(struct simple_linked_list *l, void *item)
Definition list.cpp:144
int simple_linked_list_size(struct simple_linked_list *l)
Definition list.cpp:93
void * simple_linked_list_last(struct simple_linked_list *l)
returns last element of list, UB if empty
Definition list.cpp:103
struct simple_linked_list * simple_linked_list_init(void)
Definition list.cpp:53
void simple_linked_list_destroy(struct simple_linked_list *l)
Definition list.cpp:58
void * simple_linked_list_first(struct simple_linked_list *l)
returns first element of list, UB if empty
Definition list.cpp:98
bool simple_linked_list_append_if_less(struct simple_linked_list *l, void *data, int max_size)
Definition list.cpp:73
void simple_linked_list_it_destroy(void *i)
Should be used when it != NULL, eg. when leaving the loop before the end.
Definition list.cpp:139
void * simple_linked_list_pop(struct simple_linked_list *l)
Definition list.cpp:82
void * simple_linked_list_remove_index(struct simple_linked_list *l, int index)
Definition list.cpp:155
void * simple_linked_list_it_init(struct simple_linked_list *l)
Definition list.cpp:108
Definition hd-rum.c:27
list< void * > l
Definition list.cpp:45
list< void * >::iterator it
Definition list.cpp:50
list< void * >::iterator end
Definition list.cpp:49