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 Security { 20 namespace AccessToken { VariantValue()21VariantValue::VariantValue() : type_(ValueType::TYPE_NULL) 22 {} 23 ~VariantValue()24VariantValue::~VariantValue() 25 {} 26 VariantValue(int32_t value)27VariantValue::VariantValue(int32_t value) : type_(ValueType::TYPE_INT) 28 { 29 value_ = value; 30 } 31 VariantValue(int64_t value)32VariantValue::VariantValue(int64_t value) : type_(ValueType::TYPE_INT64) 33 { 34 value_ = value; 35 } 36 VariantValue(const std::string & value)37VariantValue::VariantValue(const std::string& value) : type_(ValueType::TYPE_STRING) 38 { 39 value_ = value; 40 } 41 GetType() const42ValueType VariantValue::GetType() const 43 { 44 return type_; 45 } 46 GetInt() const47int32_t VariantValue::GetInt() const 48 { 49 if (type_ != ValueType::TYPE_INT) { 50 return DEFAULT_VALUE; 51 } 52 53 return std::get<int32_t>(value_); 54 } 55 GetInt64() const56int64_t VariantValue::GetInt64() const 57 { 58 if (type_ != ValueType::TYPE_INT64) { 59 return DEFAULT_VALUE; 60 } 61 62 return std::get<int64_t>(value_); 63 } 64 GetString() const65std::string VariantValue::GetString() const 66 { 67 if (type_ != ValueType::TYPE_STRING) { 68 return std::string(); 69 } 70 71 return std::get<std::string>(value_); 72 } 73 } // namespace AccessToken 74 } // namespace Security 75 } // namespace OHOS 76