MPD: event/PollResultGeneric.hxx Source File

MPD 0.20.15

PollResultGeneric.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_EVENT_POLLRESULT_GENERIC_HXX
21 #define MPD_EVENT_POLLRESULT_GENERIC_HXX
22
23 #include "check.h"
24
25 #include <vector>
26
27 class PollResultGeneric
28 {
29 struct Item
30 {
31 unsigned events;
32 void *obj;
33
34 Item() = default;
35 Item(unsigned _events, void *_obj)
36 : events(_events), obj(_obj) { }
37 };
38
39 std::vector<Item> items;
40 public:
41 int GetSize() const { return items.size(); }
42 unsigned GetEvents(int i) const { return items[i].events; }
43 void *GetObject(int i) const { return items[i].obj; }
44 void Reset() { items.clear(); }
45
46 void Clear(void *obj) {
47 for (auto i = items.begin(); i != items.end(); ++i)
48 if (i->obj == obj)
49 i->events = 0;
50 }
51
52 void Add(unsigned events, void *obj) {
53 items.emplace_back(events, obj);
54 }
55 };
56
57 #endif
check.h
PollResultGeneric::Add
void Add(unsigned events, void *obj)
Definition: PollResultGeneric.hxx:52
PollResultGeneric::Clear
void Clear(void *obj)
Definition: PollResultGeneric.hxx:46
PollResultGeneric::GetEvents
unsigned GetEvents(int i) const
Definition: PollResultGeneric.hxx:42
PollResultGeneric::Reset
void Reset()
Definition: PollResultGeneric.hxx:44
PollResultGeneric::GetObject
void * GetObject(int i) const
Definition: PollResultGeneric.hxx:43
PollResultGeneric
Definition: PollResultGeneric.hxx:27
PollResultGeneric::GetSize
int GetSize() const
Definition: PollResultGeneric.hxx:41