CbDataList.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_CBDATALIST_H
10#define SQUID_CBDATALIST_H
11
12#include "cbdata.h"
13
14template <class C>
16{
18
19public:
20 CbDataList(C const &);
22
27 bool find(C const &)const;
28 bool findAndTune(C const &);
33 bool empty() const { return this == NULL; }
34};
35
36template<class C>
38{
39
40public:
45 bool empty() const;
46
48};
49
50template<class C>
52{
53public:
55 const C & next() {
57 if (entry)
58 next_entry = entry->next;
59 return entry->element;
60 }
61 bool end() {
62 return next_entry == nullptr;
63 }
64
65private:
67};
68
70template <class C>
74template <class C>
75CbDataList<C>::CbDataList(C const &value) : next(nullptr), element (value)
76{}
77
78template <class C>
80{
81 if (next)
82 delete next;
83}
84
85template <class C>
86bool
88{
90 for (last = this; last->next; last = last->next) {
91 if (last->element == toAdd)
92 return false;
93 }
94
95 last->next = new CbDataList<C>(toAdd);
96 return true;
97}
98
99template <class C>
102{
104 for (last = this; last->next; last = last->next);
105 return last;
106}
107
108template <class C>
109bool
110CbDataList<C>::find (C const &toFind) const
111{
112 CbDataList<C> const *node = nullptr;
113
114 for (node = this; node; node = node->next)
115 if (node->element == toFind)
116 return true;
117
118 return false;
119}
120
121template <class C>
122bool
124{
125 CbDataList<C> *prev = NULL;
126
127 for (CbDataList<C> *node = this; node; node = node->
128 next) {
129 if (node->element == toFind) {
130 if (prev != NULL) {
131 /* shift the element just found to the second position
132 * in the list */
133 prev->next = node->next;
134 node->next = this->next;
135 this->next = node;
136 }
137
138 return true;
139 }
140
141 prev = node;
142 }
143
144 return false;
145}
146
147template <class C>
149{}
150
151template <class C>
153{
154 if (head)
155 delete head;
156}
157
158template <class C>
161{
162 CbDataList<C> *node = new CbDataList<C> (element);
163
164 if (head) {
165 CbDataList<C> *tempNode = nullptr;
166
167 for (tempNode = head; tempNode->next; tempNode = tempNode->next);
168 tempNode->next = node;
169 } else
170 head = node;
171
172 return node;
173}
174
175template <class C>
176C
178{
179 if (head) {
180 C result = head->element;
182 head = head->next;
183 node->next = NULL;
184 delete node;
185 return result;
186 }
187
188 return C();
189}
190
191template <class C>
192bool
194{
195 return head == nullptr;
196}
197
198#endif /* SQUID_CBDATALIST_H */
199
squidaio_request_t * head
Definition: aiops.cc:126
static const cbdata_type CBDATA_UNKNOWN
Definition: cbdata.h:196
int cbdata_type
Definition: cbdata.h:195
bool empty() const
Definition: CbDataList.h:193
CbDataList< C > * head
Definition: CbDataList.h:47
CbDataList< C > * push_back(C const &)
Definition: CbDataList.h:160
CbDataListIterator(CbDataListContainer< C > const &list)
Definition: CbDataList.h:54
const C & next()
Definition: CbDataList.h:55
CbDataList< C > * next_entry
Definition: CbDataList.h:66
bool push_back_unique(C const &element)
Definition: CbDataList.h:87
bool find(C const &) const
Definition: CbDataList.h:110
CbDataList * next
Definition: CbDataList.h:31
bool empty() const
Definition: CbDataList.h:33
CbDataList * tail()
Iterates the entire list to return the last element holder.
Definition: CbDataList.h:101
CbDataList(C const &)
Definition: CbDataList.h:75
bool findAndTune(C const &)
Definition: CbDataList.h:123
CBDATA_CLASS(CbDataList)
static uint32 C
Definition: md4.c:43
static char last
Definition: parse.c:451
Definition: parse.c:104
struct node * next
Definition: parse.c:105
struct squidaio_request_t * next
Definition: aiops.cc:50
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors