1fc0b0055Sopenharmony_ci/* 2fc0b0055Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3fc0b0055Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fc0b0055Sopenharmony_ci * you may not use this file except in compliance with the License. 5fc0b0055Sopenharmony_ci * You may obtain a copy of the License at 6fc0b0055Sopenharmony_ci * 7fc0b0055Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fc0b0055Sopenharmony_ci * 9fc0b0055Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fc0b0055Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fc0b0055Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fc0b0055Sopenharmony_ci * See the License for the specific language governing permissions and 13fc0b0055Sopenharmony_ci * limitations under the License. 14fc0b0055Sopenharmony_ci */ 15fc0b0055Sopenharmony_ci 16fc0b0055Sopenharmony_ci#include "generic_values.h" 17fc0b0055Sopenharmony_ci 18fc0b0055Sopenharmony_cinamespace OHOS { 19fc0b0055Sopenharmony_cinamespace Security { 20fc0b0055Sopenharmony_cinamespace AccessToken { 21fc0b0055Sopenharmony_civoid GenericValues::Put(const std::string& key, int32_t value) 22fc0b0055Sopenharmony_ci{ 23fc0b0055Sopenharmony_ci map_.insert(std::make_pair(key, VariantValue(value))); 24fc0b0055Sopenharmony_ci} 25fc0b0055Sopenharmony_ci 26fc0b0055Sopenharmony_civoid GenericValues::Put(const std::string& key, int64_t value) 27fc0b0055Sopenharmony_ci{ 28fc0b0055Sopenharmony_ci map_.insert(std::make_pair(key, VariantValue(value))); 29fc0b0055Sopenharmony_ci} 30fc0b0055Sopenharmony_ci 31fc0b0055Sopenharmony_civoid GenericValues::Put(const std::string& key, const std::string& value) 32fc0b0055Sopenharmony_ci{ 33fc0b0055Sopenharmony_ci map_.insert(std::make_pair(key, VariantValue(value))); 34fc0b0055Sopenharmony_ci} 35fc0b0055Sopenharmony_ci 36fc0b0055Sopenharmony_civoid GenericValues::Put(const std::string& key, const VariantValue& value) 37fc0b0055Sopenharmony_ci{ 38fc0b0055Sopenharmony_ci map_.insert(std::make_pair(key, value)); 39fc0b0055Sopenharmony_ci} 40fc0b0055Sopenharmony_ci 41fc0b0055Sopenharmony_ciVariantValue GenericValues::Get(const std::string& key) const 42fc0b0055Sopenharmony_ci{ 43fc0b0055Sopenharmony_ci auto iter = map_.find(key); 44fc0b0055Sopenharmony_ci if (iter == map_.end()) { 45fc0b0055Sopenharmony_ci return VariantValue(); 46fc0b0055Sopenharmony_ci } 47fc0b0055Sopenharmony_ci return iter->second; 48fc0b0055Sopenharmony_ci} 49fc0b0055Sopenharmony_ci 50fc0b0055Sopenharmony_ciint32_t GenericValues::GetInt(const std::string& key) const 51fc0b0055Sopenharmony_ci{ 52fc0b0055Sopenharmony_ci auto it = map_.find(key); 53fc0b0055Sopenharmony_ci if (it == map_.end()) { 54fc0b0055Sopenharmony_ci return VariantValue::DEFAULT_VALUE; 55fc0b0055Sopenharmony_ci } 56fc0b0055Sopenharmony_ci return it->second.GetInt(); 57fc0b0055Sopenharmony_ci} 58fc0b0055Sopenharmony_ci 59fc0b0055Sopenharmony_ciint64_t GenericValues::GetInt64(const std::string& key) const 60fc0b0055Sopenharmony_ci{ 61fc0b0055Sopenharmony_ci auto it = map_.find(key); 62fc0b0055Sopenharmony_ci if (it == map_.end()) { 63fc0b0055Sopenharmony_ci return VariantValue::DEFAULT_VALUE; 64fc0b0055Sopenharmony_ci } 65fc0b0055Sopenharmony_ci return it->second.GetInt64(); 66fc0b0055Sopenharmony_ci} 67fc0b0055Sopenharmony_ci 68fc0b0055Sopenharmony_cistd::string GenericValues::GetString(const std::string& key) const 69fc0b0055Sopenharmony_ci{ 70fc0b0055Sopenharmony_ci auto it = map_.find(key); 71fc0b0055Sopenharmony_ci if (it == map_.end()) { 72fc0b0055Sopenharmony_ci return std::string(); 73fc0b0055Sopenharmony_ci } 74fc0b0055Sopenharmony_ci return it->second.GetString(); 75fc0b0055Sopenharmony_ci} 76fc0b0055Sopenharmony_ci 77fc0b0055Sopenharmony_cistd::vector<std::string> GenericValues::GetAllKeys() const 78fc0b0055Sopenharmony_ci{ 79fc0b0055Sopenharmony_ci std::vector<std::string> keys; 80fc0b0055Sopenharmony_ci for (auto it = map_.begin(); it != map_.end(); ++it) { 81fc0b0055Sopenharmony_ci keys.emplace_back(it->first); 82fc0b0055Sopenharmony_ci } 83fc0b0055Sopenharmony_ci return keys; 84fc0b0055Sopenharmony_ci} 85fc0b0055Sopenharmony_ci 86fc0b0055Sopenharmony_civoid GenericValues::Remove(const std::string& key) 87fc0b0055Sopenharmony_ci{ 88fc0b0055Sopenharmony_ci if (map_.count(key) > 0) { 89fc0b0055Sopenharmony_ci map_.erase(key); 90fc0b0055Sopenharmony_ci } 91fc0b0055Sopenharmony_ci} 92fc0b0055Sopenharmony_ci} // namespace AccessToken 93fc0b0055Sopenharmony_ci} // namespace Security 94fc0b0055Sopenharmony_ci} // namespace OHOS 95