]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/CbDataList.h
a07960e3c3cf48516c6de499d209726363ef01d3
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_CBDATALIST_H
10 #define SQUID_CBDATALIST_H
17 CBDATA_CLASS(CbDataList
);
20 CbDataList(C
const &);
23 /// If element is already in the list, returns false.
24 /// Otherwise, adds the element to the end of the list and returns true.
25 /// Exists to avoid double iteration of find() and push() combo.
26 bool push_back_unique(C
const &element
);
27 bool find(C
const &)const;
28 bool findAndTune(C
const &);
29 /// Iterates the entire list to return the last element holder.
33 bool empty() const { return this == NULL
; }
37 class CbDataListContainer
41 CbDataListContainer();
42 ~CbDataListContainer();
43 CbDataList
<C
> *push_back (C
const &);
51 class CbDataListIterator
54 CbDataListIterator(CbDataListContainer
<C
> const &list
) : next_entry(list
.head
) {}
56 CbDataList
<C
> *entry
= next_entry
;
58 next_entry
= entry
->next
;
59 return entry
->element
;
62 return next_entry
== NULL
;
66 CbDataList
<C
> *next_entry
;
69 /** \cond AUTODOCS_IGNORE */
71 cbdata_type CbDataList
<C
>::CBDATA_CbDataList
= CBDATA_UNKNOWN
;
75 CbDataList
<C
>::CbDataList(C
const &value
) : next(NULL
), element (value
)
79 CbDataList
<C
>::~CbDataList()
87 CbDataList
<C
>::push_back_unique(C
const &toAdd
)
90 for (last
= this; last
->next
; last
= last
->next
) {
91 if (last
->element
== toAdd
)
95 last
->next
= new CbDataList
<C
>(toAdd
);
101 CbDataList
<C
>::tail()
104 for (last
= this; last
->next
; last
= last
->next
);
110 CbDataList
<C
>::find (C
const &toFind
) const
112 CbDataList
<C
> const *node
= NULL
;
114 for (node
= this; node
; node
= node
->next
)
115 if (node
->element
== toFind
)
123 CbDataList
<C
>::findAndTune(C
const & toFind
)
125 CbDataList
<C
> *prev
= NULL
;
127 for (CbDataList
<C
> *node
= this; node
; node
= node
->
129 if (node
->element
== toFind
) {
131 /* shift the element just found to the second position
133 prev
->next
= node
->next
;
134 node
->next
= this->next
;
148 CbDataListContainer
<C
>::CbDataListContainer() : head (NULL
)
152 CbDataListContainer
<C
>::~CbDataListContainer()
160 CbDataListContainer
<C
>::push_back (C
const &element
)
162 CbDataList
<C
> *node
= new CbDataList
<C
> (element
);
165 CbDataList
<C
> *tempNode
= NULL
;
167 for (tempNode
= head
; tempNode
->next
; tempNode
= tempNode
->next
);
168 tempNode
->next
= node
;
177 CbDataListContainer
<C
>::pop_front()
180 C result
= head
->element
;
181 CbDataList
<C
> *node
= head
;
193 CbDataListContainer
<C
>::empty() const
198 #endif /* SQUID_CBDATALIST_H */