• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "variant_value.h"
17 
18 namespace OHOS {
19 namespace AccountSA {
VariantValue()20 VariantValue::VariantValue() : type_(ValueType::TYPE_NULL)
21 {}
22 
~VariantValue()23 VariantValue::~VariantValue()
24 {}
25 
VariantValue(int32_t value)26 VariantValue::VariantValue(int32_t value) : type_(ValueType::TYPE_INT)
27 {
28     value_ = value;
29 }
30 
VariantValue(int64_t value)31 VariantValue::VariantValue(int64_t value) : type_(ValueType::TYPE_INT64)
32 {
33     value_ = value;
34 }
35 
VariantValue(const std::string & value)36 VariantValue::VariantValue(const std::string& value) : type_(ValueType::TYPE_STRING)
37 {
38     value_ = value;
39 }
40 
GetType() const41 ValueType VariantValue::GetType() const
42 {
43     return type_;
44 }
45 
GetInt() const46 int32_t VariantValue::GetInt() const
47 {
48     if (type_ != ValueType::TYPE_INT) {
49         return DEFAULT_VALUE;
50     }
51 
52     return std::get<int32_t>(value_);
53 }
54 
GetInt64() const55 int64_t VariantValue::GetInt64() const
56 {
57     if (type_ != ValueType::TYPE_INT64) {
58         return DEFAULT_VALUE;
59     }
60 
61     return std::get<int64_t>(value_);
62 }
63 
GetString() const64 std::string VariantValue::GetString() const
65 {
66     if (type_ != ValueType::TYPE_STRING) {
67         return std::string();
68     }
69 
70     return std::get<std::string>(value_);
71 }
72 } // namespace AccountSA
73 } // namespace OHOS
74