1 /* 2 * Copyright (c) 2023 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 Security::SecurityGuard { VariantValue()20VariantValue::VariantValue() : type_(ValueType::TYPE_NULL) 21 {} 22 ~VariantValue()23VariantValue::~VariantValue() 24 {} 25 VariantValue(int32_t value)26VariantValue::VariantValue(int32_t value) : type_(ValueType::TYPE_INT) 27 { 28 value_ = value; 29 } 30 VariantValue(int64_t value)31VariantValue::VariantValue(int64_t value) : type_(ValueType::TYPE_INT64) 32 { 33 value_ = value; 34 } 35 VariantValue(const std::string & value)36VariantValue::VariantValue(const std::string &value) : type_(ValueType::TYPE_STRING) 37 { 38 value_ = value; 39 } 40 GetType() const41ValueType VariantValue::GetType() const 42 { 43 return type_; 44 } 45 GetInt() const46int32_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() const55int64_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() const64std::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 Security::SecurityGuard 73 } // namespace OHOS 74