1 /*
2 * Copyright (C) 2019 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
17 #ifndef android_hardware_audio_common_HidlSupport_H_
18 #define android_hardware_audio_common_HidlSupport_H_
19
20
21 #include <hidl/HidlSupport.h>
22 #include <algorithm>
23 #include <sstream>
24 #include <string>
25 #include <vector>
26
27 namespace android::hardware::audio::common::utils {
28
29 template <typename Enum>
isValidHidlEnum(Enum e)30 bool isValidHidlEnum(Enum e) {
31 hidl_enum_range<Enum> values;
32 return std::find(values.begin(), values.end(), e) != values.end();
33 }
34
splitString(const std::string & s,char separator)35 static inline std::vector<std::string> splitString(const std::string& s, char separator) {
36 std::istringstream iss(s);
37 std::string t;
38 std::vector<std::string> result;
39 while (std::getline(iss, t, separator)) {
40 result.push_back(std::move(t));
41 }
42 return result;
43 }
44
45 } // namespace android::hardware::audio::common::utils
46
47 #endif // android_hardware_audio_common_HidlSupport_H_
48