blob: 9ef1351a8c39089ae6d2f849375e23386beec4eb [file] [log] [blame]
Tomasz Wasilczyk6301e8f2021-10-18 16:53:40 -07001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include <hidl/HidlSupport.h>
19
20namespace android::hardware::radio::compat {
21
22/**
23 * Converts hidl_vec<T> HIDL list to std::vector<T> AIDL list.
24 *
25 * To convert values, the template uses toAidl functions for a given type T, assuming it's defined.
26 *
27 * \param inp vector to convert
28 */
29template <typename T>
30auto toAidl(const hidl_vec<T>& inp) {
31 std::vector<decltype(toAidl(T{}))> out(inp.size());
32 for (size_t i = 0; i < inp.size(); i++) {
33 out[i] = toAidl(inp[i]);
34 }
35 return out;
36}
37
38/**
39 * Converts std::vector<T> AIDL list to hidl_vec<T> HIDL list.
40 *
41 * To convert values, the template uses toHidl functions for a given type T, assuming it's defined.
42 *
43 * \param inp vector to convert
44 */
45template <typename T>
46auto toHidl(const std::vector<T>& inp) {
47 hidl_vec<decltype(toHidl(T{}))> out(inp.size());
48 for (size_t i = 0; i < inp.size(); i++) {
49 out[i] = toHidl(inp[i]);
50 }
51 return out;
52}
53
54} // namespace android::hardware::radio::compat