1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PREFERENCES_VALUE_H 17 #define PREFERENCES_VALUE_H 18 19 #include <string> 20 #include <variant> 21 #include <vector> 22 23 namespace OHOS { 24 namespace NativePreferences { 25 class PreferencesValue { 26 public: ~PreferencesValue()27 ~PreferencesValue() 28 { 29 } 30 31 PreferencesValue(PreferencesValue &&preferencesValue) noexcept; 32 PreferencesValue(const PreferencesValue &preferencesValue); 33 34 PreferencesValue(int value); 35 PreferencesValue(int64_t value); 36 PreferencesValue(float value); 37 PreferencesValue(double value); 38 PreferencesValue(bool value); 39 PreferencesValue(std::string value); 40 PreferencesValue(const char *value); 41 PreferencesValue(std::vector<double> value); 42 PreferencesValue(std::vector<std::string> value); 43 PreferencesValue(std::vector<bool> value); 44 PreferencesValue &operator=(PreferencesValue &&preferencesValue) noexcept; 45 PreferencesValue &operator=(const PreferencesValue &preferencesValue); 46 47 bool IsInt() const; 48 bool IsLong() const; 49 bool IsFloat() const; 50 bool IsDouble() const; 51 bool IsBool() const; 52 bool IsString() const; 53 bool IsStringArray() const; 54 bool IsBoolArray() const; 55 bool IsDoubleArray() const; 56 57 operator int() const; 58 operator float() const; 59 operator double() const; 60 operator bool() const; 61 operator int64_t() const; 62 operator std::string() const; 63 operator std::vector<double>() const; 64 operator std::vector<bool>() const; 65 operator std::vector<std::string>() const; 66 67 bool operator==(const PreferencesValue &value); 68 69 private: 70 std::variant<int, int64_t, float, double, bool, std::string, std::vector<std::string>, std::vector<bool>, 71 std::vector<double>> 72 value_; 73 }; 74 } // End of namespace NativePreferences 75 } // End of namespace OHOS 76 #endif // End of #ifndef PREFERENCES_VALUE_H 77