CbDataList.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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_SRC_BASE_CBDATALIST_H
10 #define SQUID_SRC_BASE_CBDATALIST_H
11 
12 #include "cbdata.h"
13 
14 template <class C>
16 {
18 
19 public:
20  CbDataList(C const &);
21  ~CbDataList();
22 
26  bool push_back_unique(C const &element);
27  bool find(C const &)const;
28  bool findAndTune(C const &);
30  CbDataList *tail();
33  bool empty() const { return this == NULL; }
34 };
35 
36 template<class C>
38 {
39 
40 public:
43  CbDataList<C> *push_back (C const &);
44  C pop_front();
45  bool empty() const;
46 
48 };
49 
50 template<class C>
52 {
53 public:
55  const C & next() {
56  CbDataList<C> *entry = next_entry;
57  if (entry)
58  next_entry = entry->next;
59  return entry->element;
60  }
61  bool end() {
62  return next_entry == nullptr;
63  }
64 
65 private:
67 };
68 
70 template <class C>
74 template <class C>
75 CbDataList<C>::CbDataList(C const &value) : next(nullptr), element (value)
76 {}
77 
78 template <class C>
80 {
81  if (next)
82  delete next;
83 }
84 
85 template <class C>
86 bool
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 
99 template <class C>
102 {
104  for (last = this; last->next; last = last->next);
105  return last;
106 }
107 
108 template <class C>
109 bool
110 CbDataList<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 
121 template <class C>
122 bool
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 
147 template <class C>
149 {}
150 
151 template <class C>
153 {
154  if (head)
155  delete head;
156 }
157 
158 template <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 
175 template <class C>
176 C
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 
191 template <class C>
192 bool
194 {
195  return head == nullptr;
196 }
197 
198 #endif /* SQUID_SRC_BASE_CBDATALIST_H */
199 
Definition: parse.c:104
CbDataList< C > * next_entry
Definition: CbDataList.h:66
struct squidaio_request_t * next
Definition: aiops.cc:51
struct node * next
Definition: parse.c:105
CbDataList * next
Definition: CbDataList.h:31
bool findAndTune(C const &)
Definition: CbDataList.h:123
CBDATA_CLASS(CbDataList)
static char last
Definition: parse.c:451
bool find(C const &) const
Definition: CbDataList.h:110
CbDataList< C > * push_back(C const &)
Definition: CbDataList.h:160
CbDataList(C const &)
Definition: CbDataList.h:75
static const cbdata_type CBDATA_UNKNOWN
Definition: cbdata.h:196
#define NULL
Definition: types.h:145
int cbdata_type
Definition: cbdata.h:195
bool empty() const
Definition: CbDataList.h:33
static uint32 C
Definition: md4.c:43
const C & next()
Definition: CbDataList.h:55
bool push_back_unique(C const &element)
Definition: CbDataList.h:87
bool empty() const
Definition: CbDataList.h:193
squidaio_request_t * head
Definition: aiops.cc:127
CbDataList< C > * head
Definition: CbDataList.h:47
CbDataListIterator(CbDataListContainer< C > const &list)
Definition: CbDataList.h:54
CbDataList * tail()
Iterates the entire list to return the last element holder.
Definition: CbDataList.h:101

 

Introduction

Documentation

Support

Miscellaneous