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 "generic_values.h"
17
18 namespace OHOS {
19 namespace Security {
20 namespace Permission {
Put(const std::string & key,int value)21 void GenericValues::Put(const std::string& key, int value)
22 {
23 map_.insert(std::make_pair(key, VariantValue(value)));
24 }
25
Put(const std::string & key,const std::string & value)26 void GenericValues::Put(const std::string& key, const std::string& value)
27 {
28 map_.insert(std::make_pair(key, VariantValue(value)));
29 }
30
Put(const std::string & key,const VariantValue & value)31 void GenericValues::Put(const std::string& key, const VariantValue& value)
32 {
33 map_.insert(std::make_pair(key, value));
34 }
35
Get(const std::string & key) const36 VariantValue GenericValues::Get(const std::string& key) const
37 {
38 auto iter = map_.find(key);
39 if (iter == map_.end()) {
40 return VariantValue();
41 }
42 return iter->second;
43 }
44
GetInt(const std::string & key) const45 int GenericValues::GetInt(const std::string& key) const
46 {
47 auto it = map_.find(key);
48 if (it == map_.end()) {
49 return VariantValue::DEFAULT_VALUE;
50 }
51 return it->second.GetInt();
52 }
53
GetString(const std::string & key) const54 std::string GenericValues::GetString(const std::string& key) const
55 {
56 auto it = map_.find(key);
57 if (it == map_.end()) {
58 return std::string();
59 }
60 return it->second.GetString();
61 }
62
GetAllKeys() const63 std::vector<std::string> GenericValues::GetAllKeys() const
64 {
65 std::vector<std::string> keys;
66 for (auto it = map_.begin(); it != map_.end(); ++it) {
67 keys.emplace_back(it->first);
68 }
69 return keys;
70 }
71 } // namespace Permission
72 } // namespace Security
73 } // namespace OHOS