• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef DATASHARE_VALUES_BUCKET_H
17 #define DATASHARE_VALUES_BUCKET_H
18 
19 #include "datashare_value_object.h"
20 
21 #include <map>
22 #include <set>
23 
24 namespace OHOS {
25 namespace DataShare {
26 class DataShareValuesBucket {
27 public:
28     DataShareValuesBucket() = default;
DataShareValuesBucket(std::map<std::string,DataShareValueObject> & values)29     explicit DataShareValuesBucket(std::map<std::string, DataShareValueObject> &values) : valuesMap(values){};
30     ~DataShareValuesBucket() = default;
31 
32     void Put(const std::string &columnName, const DataShareValueObject &value = {})
33     {
34         valuesMap.insert(std::make_pair(columnName, value));
35     }
36 
Clear()37     void Clear()
38     {
39         valuesMap.clear();
40     }
41 
IsEmpty()42     bool IsEmpty() const
43     {
44         return valuesMap.empty();
45     }
46 
Get(const std::string & columnName,bool & isValid)47     DataShareValueObject Get(const std::string &columnName, bool &isValid) const
48     {
49         auto iter = valuesMap.find(columnName);
50         if (iter == valuesMap.end()) {
51             isValid = false;
52             return {};
53         }
54         isValid = true;
55         return iter->second;
56     }
57 
58     std::map<std::string, DataShareValueObject> valuesMap;
59 };
60 } // namespace DataShare
61 } // namespace OHOS
62 #endif
63