• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)20 PreferencesValue::PreferencesValue(const PreferencesValue &preferencesValue)
21 {
22     if (this == &preferencesValue) {
23         return;
24     }
25     value_ = preferencesValue.value_;
26 }
27 
PreferencesValue(PreferencesValue && preferencesValue)28 PreferencesValue::PreferencesValue(PreferencesValue &&preferencesValue) noexcept
29 {
30     if (this == &preferencesValue) {
31         return;
32     }
33     value_ = std::move(preferencesValue.value_);
34 }
35 
PreferencesValue(int value)36 PreferencesValue::PreferencesValue(int value)
37 {
38     value_ = value;
39 }
40 
PreferencesValue(int64_t value)41 PreferencesValue::PreferencesValue(int64_t value)
42 {
43     value_ = value;
44 }
45 
PreferencesValue(float value)46 PreferencesValue::PreferencesValue(float value)
47 {
48     value_ = value;
49 }
50 
PreferencesValue(double value)51 PreferencesValue::PreferencesValue(double value)
52 {
53     value_ = value;
54 }
55 
PreferencesValue(bool value)56 PreferencesValue::PreferencesValue(bool value)
57 {
58     value_ = value;
59 }
60 
PreferencesValue(const char * value)61 PreferencesValue::PreferencesValue(const char *value)
62 {
63     PreferencesValue(std::string(value));
64 }
65 
PreferencesValue(std::string value)66 PreferencesValue::PreferencesValue(std::string value)
67 {
68     value_ = value;
69 }
70 
PreferencesValue(std::vector<double> value)71 PreferencesValue::PreferencesValue(std::vector<double> value)
72 {
73     value_ = value;
74 }
75 
PreferencesValue(std::vector<std::string> value)76 PreferencesValue::PreferencesValue(std::vector<std::string> value)
77 {
78     value_ = value;
79 }
80 
PreferencesValue(std::vector<bool> value)81 PreferencesValue::PreferencesValue(std::vector<bool> value)
82 {
83     value_ = value;
84 }
85 
PreferencesValue(std::vector<uint8_t> value)86 PreferencesValue::PreferencesValue(std::vector<uint8_t> value)
87 {
88     value_ = value;
89 }
90 
operator =(PreferencesValue && preferencesValue)91 PreferencesValue &PreferencesValue::operator=(PreferencesValue &&preferencesValue) noexcept
92 {
93     if (this == &preferencesValue) {
94         return *this;
95     }
96     value_ = std::move(preferencesValue.value_);
97     return *this;
98 }
99 
operator =(const PreferencesValue & preferencesValue)100 PreferencesValue &PreferencesValue::operator=(const PreferencesValue &preferencesValue)
101 {
102     if (this == &preferencesValue) {
103         return *this;
104     }
105     value_ = preferencesValue.value_;
106     return *this;
107 }
108 
IsInt() const109 bool PreferencesValue::IsInt() const
110 {
111     return std::holds_alternative<int>(value_);
112 }
113 
IsLong() const114 bool PreferencesValue::IsLong() const
115 {
116     return std::holds_alternative<int64_t>(value_);
117 }
118 
IsFloat() const119 bool PreferencesValue::IsFloat() const
120 {
121     return std::holds_alternative<float>(value_);
122 }
123 
IsDouble() const124 bool PreferencesValue::IsDouble() const
125 {
126     return std::holds_alternative<double>(value_);
127 }
128 
IsBool() const129 bool PreferencesValue::IsBool() const
130 {
131     return std::holds_alternative<bool>(value_);
132 }
133 
IsString() const134 bool PreferencesValue::IsString() const
135 {
136     return std::holds_alternative<std::string>(value_);
137 }
138 
IsDoubleArray() const139 bool PreferencesValue::IsDoubleArray() const
140 {
141     return std::holds_alternative<std::vector<double>>(value_);
142 }
143 
IsUint8Array() const144 bool PreferencesValue::IsUint8Array() const
145 {
146     return std::holds_alternative<std::vector<uint8_t>>(value_);
147 }
148 
IsStringArray() const149 bool PreferencesValue::IsStringArray() const
150 {
151     return std::holds_alternative<std::vector<std::string>>(value_);
152 }
153 
IsBoolArray() const154 bool PreferencesValue::IsBoolArray() const
155 {
156     return std::holds_alternative<std::vector<bool>>(value_);
157 }
158 
operator int() const159 PreferencesValue::operator int() const
160 {
161     return std::get<int>(value_);
162 }
163 
operator int64_t() const164 PreferencesValue::operator int64_t() const
165 {
166     return std::get<int64_t>(value_);
167 }
168 
operator float() const169 PreferencesValue::operator float() const
170 {
171     return std::get<float>(value_);
172 }
173 
operator double() const174 PreferencesValue::operator double() const
175 {
176     return std::get<double>(value_);
177 }
178 
operator bool() const179 PreferencesValue::operator bool() const
180 {
181     return std::get<bool>(value_);
182 }
183 
operator std::string() const184 PreferencesValue::operator std::string() const
185 {
186     return std::get<std::string>(value_);
187 }
188 
operator std::vector<double>() const189 PreferencesValue::operator std::vector<double>() const
190 {
191     return std::get<std::vector<double>>(value_);
192 }
193 
operator std::vector<bool>() const194 PreferencesValue::operator std::vector<bool>() const
195 {
196     return std::get<std::vector<bool>>(value_);
197 }
198 
operator std::vector<std::string>() const199 PreferencesValue::operator std::vector<std::string>() const
200 {
201     return std::get<std::vector<std::string>>(value_);
202 }
203 
operator std::vector<uint8_t>() const204 PreferencesValue::operator std::vector<uint8_t>() const
205 {
206     return std::get<std::vector<uint8_t>>(value_);
207 }
208 
operator ==(const PreferencesValue & value)209 bool PreferencesValue::operator==(const PreferencesValue &value)
210 {
211     return (this->value_ == value.value_);
212 }
213 } // End of namespace NativePreferences
214 } // End of namespace OHOS
215