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(const PreferencesValue & preferencesValue)20PreferencesValue::PreferencesValue(const PreferencesValue &preferencesValue) 21 { 22 if (this == &preferencesValue) { 23 return; 24 } 25 value_ = preferencesValue.value_; 26 } 27 PreferencesValue(PreferencesValue && preferencesValue)28PreferencesValue::PreferencesValue(PreferencesValue &&preferencesValue) noexcept 29 { 30 if (this == &preferencesValue) { 31 return; 32 } 33 value_ = std::move(preferencesValue.value_); 34 } 35 PreferencesValue(int value)36PreferencesValue::PreferencesValue(int value) 37 { 38 value_ = value; 39 } 40 PreferencesValue(int64_t value)41PreferencesValue::PreferencesValue(int64_t value) 42 { 43 value_ = value; 44 } 45 PreferencesValue(float value)46PreferencesValue::PreferencesValue(float value) 47 { 48 value_ = value; 49 } 50 PreferencesValue(double value)51PreferencesValue::PreferencesValue(double value) 52 { 53 value_ = value; 54 } 55 PreferencesValue(bool value)56PreferencesValue::PreferencesValue(bool value) 57 { 58 value_ = value; 59 } 60 PreferencesValue(const char * value)61PreferencesValue::PreferencesValue(const char *value) 62 { 63 PreferencesValue(std::string(value)); 64 } 65 PreferencesValue(std::string value)66PreferencesValue::PreferencesValue(std::string value) 67 { 68 value_ = value; 69 } 70 PreferencesValue(std::vector<double> value)71PreferencesValue::PreferencesValue(std::vector<double> value) 72 { 73 value_ = value; 74 } 75 PreferencesValue(std::vector<std::string> value)76PreferencesValue::PreferencesValue(std::vector<std::string> value) 77 { 78 value_ = value; 79 } 80 PreferencesValue(std::vector<bool> value)81PreferencesValue::PreferencesValue(std::vector<bool> value) 82 { 83 value_ = value; 84 } 85 operator =(PreferencesValue && preferencesValue)86PreferencesValue &PreferencesValue::operator=(PreferencesValue &&preferencesValue) noexcept 87 { 88 if (this == &preferencesValue) { 89 return *this; 90 } 91 value_ = std::move(preferencesValue.value_); 92 return *this; 93 } 94 operator =(const PreferencesValue & preferencesValue)95PreferencesValue &PreferencesValue::operator=(const PreferencesValue &preferencesValue) 96 { 97 if (this == &preferencesValue) { 98 return *this; 99 } 100 value_ = preferencesValue.value_; 101 return *this; 102 } 103 IsInt() const104bool PreferencesValue::IsInt() const 105 { 106 return std::holds_alternative<int>(value_); 107 } 108 IsLong() const109bool PreferencesValue::IsLong() const 110 { 111 return std::holds_alternative<int64_t>(value_); 112 } 113 IsFloat() const114bool PreferencesValue::IsFloat() const 115 { 116 return std::holds_alternative<float>(value_); 117 } 118 IsDouble() const119bool PreferencesValue::IsDouble() const 120 { 121 return std::holds_alternative<double>(value_); 122 } 123 IsBool() const124bool PreferencesValue::IsBool() const 125 { 126 return std::holds_alternative<bool>(value_); 127 } 128 IsString() const129bool PreferencesValue::IsString() const 130 { 131 return std::holds_alternative<std::string>(value_); 132 } 133 IsDoubleArray() const134bool PreferencesValue::IsDoubleArray() const 135 { 136 return std::holds_alternative<std::vector<double>>(value_); 137 } 138 IsStringArray() const139bool PreferencesValue::IsStringArray() const 140 { 141 return std::holds_alternative<std::vector<std::string>>(value_); 142 } 143 IsBoolArray() const144bool PreferencesValue::IsBoolArray() const 145 { 146 return std::holds_alternative<std::vector<bool>>(value_); 147 } 148 operator int() const149PreferencesValue::operator int() const 150 { 151 return std::get<int>(value_); 152 } 153 operator int64_t() const154PreferencesValue::operator int64_t() const 155 { 156 return std::get<int64_t>(value_); 157 } 158 operator float() const159PreferencesValue::operator float() const 160 { 161 return std::get<float>(value_); 162 } 163 operator double() const164PreferencesValue::operator double() const 165 { 166 return std::get<double>(value_); 167 } 168 operator bool() const169PreferencesValue::operator bool() const 170 { 171 return std::get<bool>(value_); 172 } 173 operator std::string() const174PreferencesValue::operator std::string() const 175 { 176 return std::get<std::string>(value_); 177 } 178 operator std::vector<double>() const179PreferencesValue::operator std::vector<double>() const 180 { 181 return std::get<std::vector<double>>(value_); 182 } 183 operator std::vector<bool>() const184PreferencesValue::operator std::vector<bool>() const 185 { 186 return std::get<std::vector<bool>>(value_); 187 } 188 operator std::vector<std::string>() const189PreferencesValue::operator std::vector<std::string>() const 190 { 191 return std::get<std::vector<std::string>>(value_); 192 } 193 operator ==(const PreferencesValue & value)194bool PreferencesValue::operator==(const PreferencesValue &value) 195 { 196 return (this->value_ == value.value_); 197 } 198 } // End of namespace NativePreferences 199 } // End of namespace OHOS 200