Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
devicehandlerlist_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QTINPUTSUPPORT_DEVICEHANDLERLIST_P_H
5#define QTINPUTSUPPORT_DEVICEHANDLERLIST_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QString>
19#include <private/qglobal_p.h>
20
21#include <vector>
22#include <memory>
23
24namespace QtInputSupport {
25
26template <typename Handler>
28public:
29 struct Device {
30 #ifndef __cpp_aggregate_paren_init
33 #endif
36 };
37
38 void add(QString deviceNode, std::unique_ptr<Handler> handler)
39 {
40 v.emplace_back(std::move(deviceNode), std::move(handler));
41 }
42
43 bool remove(const QString &deviceNode)
44 {
45 const auto deviceNodeMatches = [&] (const Device &d) { return d.deviceNode == deviceNode; };
46 const auto it = std::find_if(v.cbegin(), v.cend(), deviceNodeMatches);
47 if (it == v.cend())
48 return false;
49 v.erase(it);
50 return true;
51 }
52
53 int count() const noexcept { return static_cast<int>(v.size()); }
54
55 typename std::vector<Device>::const_iterator begin() const noexcept { return v.begin(); }
56 typename std::vector<Device>::const_iterator end() const noexcept { return v.end(); }
57
58private:
59 std::vector<Device> v;
60};
61
62} // QtInputSupport
63
64#endif // QTINPUTSUPPORT_DEVICEHANDLERLIST_P_H
void add(QString deviceNode, std::unique_ptr< Handler > handler)
std::vector< Device >::const_iterator end() const noexcept
std::vector< Device >::const_iterator begin() const noexcept
bool remove(const QString &deviceNode)