DeviceList.h
Go to the documentation of this file.
1 /****
2  * DeviceList.h
3  *
4  * Copyright 2019 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the HueEmulator 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 "Device.h"
23 #include <WVector.h>
24 
25 namespace Hue
26 {
28 
29 class DeviceListEnumerator : public Device::Enumerator
30 {
31 public:
32  DeviceListEnumerator(DeviceList& list) : list(list)
33  {
34  }
35 
36  Device::Enumerator* clone() override
37  {
38  return new DeviceListEnumerator(*this);
39  }
40 
41  void reset() override
42  {
43  index = 0;
44  }
45 
46  Device* current() override
47  {
48  return (size_t(index) < list.count()) ? &list[index] : nullptr;
49  }
50 
51  Device* next() override
52  {
53  return (size_t(index) < list.count()) ? &list[index++] : nullptr;
54  }
55 
56 private:
57  DeviceList& list;
58  int index{-1};
59 };
60 
61 } // namespace Hue
void reset() override
Reset enumerator to start of list.
Definition: DeviceList.h:58
unsigned int count() const override
Definition: WVector.h:148
Device * current() override
Get the current item.
Definition: DeviceList.h:63
Vector< Device > DeviceList
Definition: DeviceList.h:44
Device * next() override
Get next item.
Definition: DeviceList.h:68
Device::Enumerator * clone() override
Make a copy of this enumerator.
Definition: DeviceList.h:53
DeviceListEnumerator(DeviceList &list)
Definition: DeviceList.h:49
Definition: Bridge.h:29
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:92
Vector class template.
Definition: WVector.h:31