LinkedItemList.h
Go to the documentation of this file.
1 /****
2  * LinkedItemList.h
3  *
4  * Copyright 2019 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the Sming UPnP Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include "LinkedItem.h"
23 
24 namespace UPnP
25 {
31 {
32 public:
33  bool add(LinkedItem* item);
34 
35  bool add(const LinkedItem* item)
36  {
37  return add(const_cast<LinkedItem*>(item));
38  }
39 
40  bool remove(LinkedItem* item);
41 
42  void clear()
43  {
44  head_ = nullptr;
45  }
46 
48  {
49  return head_;
50  }
51 
52  const LinkedItem* head() const
53  {
54  return head_;
55  }
56 
58  {
59  auto p = head_;
60  while(p != nullptr && p != item) {
61  p = p->getNext();
62  }
63  return p;
64  }
65 
66  const LinkedItem* find(LinkedItem* item) const
67  {
68  return const_cast<LinkedItemList*>(this)->find(item);
69  }
70 
71  bool contains(LinkedItem* item) const
72  {
73  return find(item) != nullptr;
74  }
75 
76 private:
77  LinkedItem* head_{nullptr};
78 };
79 
80 } // namespace UPnP
Singly-linked list of items.
Definition: LinkedItemList.h:31
const LinkedItem * head() const
Definition: LinkedItemList.h:52
LinkedItem * find(LinkedItem *item)
Definition: LinkedItemList.h:57
bool contains(LinkedItem *item) const
Definition: LinkedItemList.h:71
const LinkedItem * find(LinkedItem *item) const
Definition: LinkedItemList.h:66
bool add(LinkedItem *item)
bool add(const LinkedItem *item)
Definition: LinkedItemList.h:35
void clear()
Definition: LinkedItemList.h:42
bool remove(LinkedItem *item)
LinkedItem * head()
Definition: LinkedItemList.h:47
Base class template for items in a list.
Definition: LinkedItem.h:32
LinkedItem * getNext() const
Definition: LinkedItem.h:39
Definition: ActionRequest.h:25