blob: a3ea01f699a9bc4f60b7812b6c69e8d406635f83 [file] [log] [blame]
Ram Mohan9c477192023-03-28 05:54:11 +05301/*
2 * Copyright (C) 2023 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#pragma once
18
19#include <algorithm>
20#include <tuple>
21#include <utility>
22#include <vector>
23
24namespace aidl::android::hardware::audio::effect {
25
26template <typename T>
27bool isInRange(const T& value, const T& low, const T& high) {
28 return (value >= low) && (value <= high);
29}
30
31template <typename T, std::size_t... Is>
32bool isTupleInRange(const T& test, const T& min, const T& max, std::index_sequence<Is...>) {
33 return (isInRange(std::get<Is>(test), std::get<Is>(min), std::get<Is>(max)) && ...);
34}
35
36template <typename T, std::size_t TupSize = std::tuple_size_v<T>>
37bool isTupleInRange(const T& test, const T& min, const T& max) {
38 return isTupleInRange(test, min, max, std::make_index_sequence<TupSize>{});
39}
40
41template <typename T, typename F>
42bool isTupleInRange(const std::vector<T>& cfgs, const T& min, const T& max, const F& func) {
43 auto minT = func(min), maxT = func(max);
44 return std::all_of(cfgs.cbegin(), cfgs.cend(),
45 [&](const T& cfg) { return isTupleInRange(func(cfg), minT, maxT); });
46}
47
48} // namespace aidl::android::hardware::audio::effect