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 
30 {
31 public:
32  DeviceListEnumerator(DeviceList& list) : list(list)
33  {
34  }
35 
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
Definition: DeviceList.h:30
Device::Enumerator * clone() override
Make a copy of this enumerator.
Definition: DeviceList.h:36
void reset() override
Reset enumerator to start of list.
Definition: DeviceList.h:41
Device * current() override
Get the current item.
Definition: DeviceList.h:46
Device * next() override
Get next item.
Definition: DeviceList.h:51
DeviceListEnumerator(DeviceList &list)
Definition: DeviceList.h:32
Abstract class to manage a list of devices.
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:126
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:93
Vector class template.
Definition: WVector.h:32
unsigned int count() const override
Definition: WVector.h:160
Definition: Bridge.h:30