Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 {
31 std::unique_ptr<Handler> handler;
32 };
33
34 void add(const QString &deviceNode, std::unique_ptr<Handler> handler)
35 {
36 v.push_back({deviceNode, std::move(handler)});
37 }
38
39 bool remove(const QString &deviceNode)
40 {
41 const auto deviceNodeMatches = [&] (const Device &d) { return d.deviceNode == deviceNode; };
42 const auto it = std::find_if(v.cbegin(), v.cend(), deviceNodeMatches);
43 if (it == v.cend())
44 return false;
45 v.erase(it);
46 return true;
47 }
48
49 int count() const noexcept { return static_cast<int>(v.size()); }
50
51 typename std::vector<Device>::const_iterator begin() const noexcept { return v.begin(); }
52 typename std::vector<Device>::const_iterator end() const noexcept { return v.end(); }
53
54private:
55 std::vector<Device> v;
56};
57
58} // QtInputSupport
59
60#endif // QTINPUTSUPPORT_DEVICEHANDLERLIST_P_H
const_iterator cend() const noexcept
Definition qset.h:142
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
void add(const 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)
QSet< QString >::iterator it
GLsizei const GLfloat * v
[13]