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 #include "preferences_value.h" 17 18 namespace OHOS { 19 namespace NativePreferences { PreferencesValue(int value)20PreferencesValue::PreferencesValue(int value) 21 { 22 data_ = value; 23 } 24 PreferencesValue(int64_t value)25PreferencesValue::PreferencesValue(int64_t value) 26 { 27 data_ = value; 28 } 29 PreferencesValue(float value)30PreferencesValue::PreferencesValue(float value) 31 { 32 data_ = value; 33 } 34 PreferencesValue(double value)35PreferencesValue::PreferencesValue(double value) 36 { 37 data_ = value; 38 } 39 PreferencesValue(bool value)40PreferencesValue::PreferencesValue(bool value) 41 { 42 data_ = value; 43 } 44 PreferencesValue(std::string value)45PreferencesValue::PreferencesValue(std::string value) 46 { 47 data_ = value; 48 } 49 PreferencesValue(std::set<std::string> value)50PreferencesValue::PreferencesValue(std::set<std::string> value) 51 { 52 data_ = std::move(value); 53 } 54 IsInt() const55bool PreferencesValue::IsInt() const 56 { 57 auto pVal = std::get_if<int>(&data_); 58 return (pVal != nullptr); 59 } 60 IsLong() const61bool PreferencesValue::IsLong() const 62 { 63 auto pVal = std::get_if<int64_t>(&data_); 64 return (pVal != nullptr); 65 } 66 IsFloat() const67bool PreferencesValue::IsFloat() const 68 { 69 auto pVal = std::get_if<float>(&data_); 70 return (pVal != nullptr); 71 } 72 IsDouble() const73bool PreferencesValue::IsDouble() const 74 { 75 auto pVal = std::get_if<double>(&data_); 76 return (pVal != nullptr); 77 } 78 IsBool() const79bool PreferencesValue::IsBool() const 80 { 81 auto pVal = std::get_if<bool>(&data_); 82 return (pVal != nullptr); 83 } 84 IsString() const85bool PreferencesValue::IsString() const 86 { 87 auto pVal = std::get_if<std::string>(&data_); 88 return (pVal != nullptr); 89 } 90 IsSet() const91bool PreferencesValue::IsSet() const 92 { 93 auto pVal = std::get_if<std::set<std::string>>(&data_); 94 return (pVal != nullptr); 95 } 96 operator int()97PreferencesValue::operator int() 98 { 99 return std::get<int>(data_); 100 } 101 operator int64_t()102PreferencesValue::operator int64_t() 103 { 104 return std::get<int64_t>(data_); 105 } 106 operator float()107PreferencesValue::operator float() 108 { 109 return std::get<float>(data_); 110 } 111 operator double()112PreferencesValue::operator double() 113 { 114 return std::get<double>(data_); 115 } 116 operator bool()117PreferencesValue::operator bool() 118 { 119 return std::get<bool>(data_); 120 } 121 operator std::string()122PreferencesValue::operator std::string() 123 { 124 return std::get<std::string>(data_); 125 } 126 operator std::set<std::string>()127PreferencesValue::operator std::set<std::string>() 128 { 129 return std::get<std::set<std::string>>(data_); 130 } 131 operator ==(const PreferencesValue & value)132bool PreferencesValue::operator == (const PreferencesValue &value) 133 { 134 return (this->data_ == value.data_); 135 } 136 } // End of namespace NativePreferences 137 } // End of namespace OHOS 138