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     /**
29      * @brief Constructor.
30      */
31     DataShareValuesBucket() = default;
32     /**
33      * @brief Constructor.
34      *
35      * @param string Specifies the parameter of the type.
36      * @param values is the value of the corresponding type.
37      */
DataShareValuesBucket(std::map<std::string,DataShareValueObject::Type> values)38     explicit DataShareValuesBucket(std::map<std::string, DataShareValueObject::Type> values)
39         : valuesMap(std::move(values)){};
40     /**
41      * @brief Destructor.
42      */
43     ~DataShareValuesBucket() = default;
44     /**
45      * @brief Function of Put.
46      *
47      * @param columnName is name of the corresponding column.
48      * @param value Indicates the value of columnName data to put or update.
49      */
50     void Put(const std::string &columnName, const DataShareValueObject &value = {})
51     {
52         valuesMap.insert(std::make_pair(columnName, value.value));
53     }
54     /**
55      * @brief Function of Clear.
56      */
Clear()57     void Clear()
58     {
59         valuesMap.clear();
60     }
61     /**
62      * @brief Function of IsEmpty.
63      */
IsEmpty()64     bool IsEmpty() const
65     {
66         return valuesMap.empty();
67     }
68     /**
69      * @brief Function of get string type object.
70      *
71      * @param columnName is name of the corresponding column.
72      * @param isValid The obtained value is valid.
73      */
Get(const std::string & columnName,bool & isValid)74     DataShareValueObject Get(const std::string &columnName, bool &isValid) const
75     {
76         auto iter = valuesMap.find(columnName);
77         if (iter == valuesMap.end()) {
78             isValid = false;
79             return {};
80         }
81         isValid = true;
82         return iter->second;
83     }
84 
85     std::map<std::string, DataShareValueObject::Type> valuesMap;
86 };
87 } // namespace DataShare
88 } // namespace OHOS
89 #endif