1 /*
2  * Copyright (C) 2017 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_VINTF_KERNEL_CONFIG_H
18 #define ANDROID_VINTF_KERNEL_CONFIG_H
19 
20 #include <string>
21 
22 #include "KernelConfigType.h"
23 #include "Tristate.h"
24 
25 namespace android {
26 namespace vintf {
27 
28 using KernelConfigIntValue = int64_t;
29 using KernelConfigRangeValue = std::pair<uint64_t, uint64_t>;
30 
31 // compatibility-matrix.kernel.config.value item.
32 struct KernelConfigTypedValue {
33 
34     const static KernelConfigTypedValue gMissingConfig;
35 
36     // Construct with empty string value
37     KernelConfigTypedValue();
38 
39     KernelConfigTypedValue(std::string &&s);
40     KernelConfigTypedValue(KernelConfigIntValue v);
41     KernelConfigTypedValue(KernelConfigRangeValue &&v);
42     KernelConfigTypedValue(Tristate t);
43 
44     bool operator==(const KernelConfigTypedValue &other) const;
45 
46     bool matchValue(const std::string &) const;
47 
48 private:
49     friend struct KernelConfigTypedValueConverter;
50     friend std::ostream &operator<<(std::ostream &os, const KernelConfigTypedValue &kctv);
51     friend bool parseKernelConfigValue(const std::string &s, KernelConfigTypedValue *kctv);
52     friend bool parseKernelConfigTypedValue(const std::string& s, KernelConfigTypedValue* kctv);
53 
54     std::string mStringValue;
55     KernelConfigIntValue mIntegerValue;
56     KernelConfigRangeValue mRangeValue;
57     Tristate mTristateValue;
58     KernelConfigType mType;
59 
60 };
61 
62 } // namespace vintf
63 } // namespace android
64 
65 #endif // ANDROID_VINTF_KERNEL_CONFIG_H
66