ItemEnumerator.h
Go to the documentation of this file.
1 /****
2  * ItemEnumerator.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 "Enumerator.h"
23 #include "Item.h"
24 
25 namespace UPnP
26 {
27 class Item;
28 
29 class ItemEnumerator : public Enumerator<Item, ItemEnumerator>
30 {
31 public:
32  ItemEnumerator(Item* head) : head_(head), current_(head)
33  {
34  }
35 
40  ItemEnumerator* clone() override
41  {
42  return new ItemEnumerator(*this);
43  }
44 
48  void reset() override
49  {
50  current_ = head_;
51  }
52 
53  Item* current() override
54  {
55  return current_;
56  }
57 
62  Item* next() override
63  {
64  if(current_ != nullptr) {
65  current_ = current_->next();
66  }
67  return current_;
68  }
69 
70 private:
71  Item* head_;
72  Item* current_{nullptr};
73 };
74 
75 } // namespace UPnP
Abstract class to enumerate items.
Definition: Enumerator.h:38
Definition: ItemEnumerator.h:30
ItemEnumerator * clone() override
Make a copy of this enumerator.
Definition: ItemEnumerator.h:40
Item * next() override
Move to next item in list.
Definition: ItemEnumerator.h:62
ItemEnumerator(Item *head)
Definition: ItemEnumerator.h:32
void reset() override
Reset enumerator to start of list.
Definition: ItemEnumerator.h:48
Item * current() override
Get the current item.
Definition: ItemEnumerator.h:53
Definition: Item.h:39
virtual Item * next() const
Definition: Item.h:55
Definition: ActionRequest.h:25