-
Notifications
You must be signed in to change notification settings - Fork 506
/
button_maps.cpp
59 lines (50 loc) · 1.71 KB
/
button_maps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright (c) 2021 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
*/
#include "button_maps.h"
ButtonMapRef BM_ButtonMapRefForHash(uint32_t buttonMapNameHash, const std::vector<ButtonMap> &buttonMaps)
{
const auto bm = std::find_if(buttonMaps.cbegin(), buttonMaps.cend(),
[buttonMapNameHash](const auto &bm) { return bm.buttonMapRef.hash == buttonMapNameHash; });
if (bm != buttonMaps.cend())
{
return bm->buttonMapRef;
}
return {};
}
const ButtonMap *BM_ButtonMapForRef(ButtonMapRef ref, const std::vector<ButtonMap> &buttonMaps)
{
if (isValid(ref) && ref.index < buttonMaps.size())
{
const ButtonMap &bm = buttonMaps[ref.index];
if (bm.buttonMapRef.hash == ref.hash)
{
return &bm;
}
}
return nullptr;
}
const ButtonMap *BM_ButtonMapForProduct(ProductIdHash productHash, const std::vector<ButtonMap> &buttonMaps,
const std::vector<ButtonProduct> &buttonProductMap)
{
ButtonMapRef buttonMapHash{};
{
const auto mapping = std::find_if(buttonProductMap.cbegin(), buttonProductMap.cend(),
[productHash](const auto &i) { return i.productHash == productHash; });
if (mapping != buttonProductMap.cend())
{
buttonMapHash = mapping->buttonMapRef;
}
}
if (isValid(buttonMapHash))
{
return BM_ButtonMapForRef(buttonMapHash, buttonMaps);
}
return nullptr;
}