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 #ifndef NATIVE_RDB_VALUES_BUCKET_H 17 #define NATIVE_RDB_VALUES_BUCKET_H 18 19 #include <map> 20 #include <set> 21 22 #include "value_object.h" 23 24 namespace OHOS { 25 class Parcel; 26 namespace NativeRdb { 27 /** 28 * The ValuesBucket class of RDB. 29 */ 30 class API_EXPORT ValuesBucket { 31 public: 32 /** 33 * @brief Constructor. 34 */ 35 API_EXPORT ValuesBucket(); 36 37 /** 38 * @brief Constructor. 39 * 40 * A parameterized constructor used to create a ValuesBucket instance. 41 */ 42 API_EXPORT ValuesBucket(std::map<std::string, ValueObject> values); 43 API_EXPORT ValuesBucket(const ValuesBucket &values); 44 API_EXPORT ValuesBucket &operator =(const ValuesBucket &values); 45 API_EXPORT ValuesBucket(ValuesBucket &&values) noexcept; 46 API_EXPORT ValuesBucket &operator =(ValuesBucket &&values) noexcept; 47 48 /** 49 * @brief Destructor. 50 */ 51 API_EXPORT ~ValuesBucket(); 52 53 /** 54 * @brief Put the string value to this {@code ValuesBucket} object for the given column name. 55 * 56 * @param columnName Indicates the name of the column. 57 * @param value Indicates the string value. 58 */ 59 API_EXPORT void PutString(const std::string &columnName, const std::string &value); 60 61 /** 62 * @brief Put the int value to this {@code ValuesBucket} object for the given column name. 63 * 64 * @param columnName Indicates the name of the column. 65 * @param value Indicates the int value. 66 */ 67 API_EXPORT void PutInt(const std::string &columnName, int value); 68 69 /** 70 * @brief Put the long value to this {@code ValuesBucket} object for the given column name. 71 * 72 * @param columnName Indicates the name of the column. 73 * @param value Indicates the long value. 74 */ 75 API_EXPORT void PutLong(const std::string &columnName, int64_t value); 76 77 /** 78 * @brief Put the double value to this {@code ValuesBucket} object for the given column name. 79 * 80 * @param columnName Indicates the name of the column. 81 * @param value Indicates the double value. 82 */ 83 API_EXPORT void PutDouble(const std::string &columnName, double value); 84 85 /** 86 * @brief Put the bool value to this {@code ValuesBucket} object for the given column name. 87 * 88 * @param columnName Indicates the name of the column. 89 * @param value Indicates the bool value. 90 */ 91 API_EXPORT void PutBool(const std::string &columnName, bool value); 92 93 /** 94 * @brief Put the vector<uint8_t> value to this {@code ValuesBucket} object for the given column name. 95 * 96 * @param columnName Indicates the name of the column. 97 * @param value Indicates the vector<uint8_t> value. 98 */ 99 API_EXPORT void PutBlob(const std::string &columnName, const std::vector<uint8_t> &value); 100 101 /** 102 * @brief Put NULL to this {@code ValuesBucket} object for the given column name. 103 * 104 * @param columnName Indicates the name of the column. 105 */ 106 API_EXPORT void PutNull(const std::string &columnName); 107 108 /** 109 * @brief Put the integer double bool string bytes asset asset and so on 110 * to this {@code ValuesBucket} object for the given column name. 111 * 112 * @param columnName Indicates the name of the column. 113 */ 114 API_EXPORT void Put(const std::string &columnName, const ValueObject &value); 115 116 /** 117 * @brief Delete the ValueObject object for the given column name. 118 * 119 * @param columnName Indicates the name of the column. 120 */ 121 API_EXPORT void Delete(const std::string &columnName); 122 123 /** 124 * @brief Clear the ValuesBucket object's valuesmap. 125 */ 126 API_EXPORT void Clear(); 127 128 /** 129 * @brief Obtains the ValuesBucket object's valuesmap size. 130 */ 131 API_EXPORT int Size() const; 132 133 /** 134 * @brief Checks whether the ValuesBucket object's valuesmap is empty. 135 */ 136 API_EXPORT bool IsEmpty() const; 137 138 /** 139 * @brief Checks whether the ValuesBucket object's valuesmap contain the specified columnName. 140 * 141 * @param columnName Indicates the name of the column. 142 */ 143 API_EXPORT bool HasColumn(const std::string &columnName) const; 144 145 /** 146 * @brief Obtains the specified value for the given column name. 147 * 148 * @param columnName Indicates the name of the column. 149 */ 150 API_EXPORT bool GetObject(const std::string &columnName, ValueObject &value) const; 151 152 /** 153 * @brief Obtains the ValuesBucket object's valuesmap. 154 */ 155 API_EXPORT std::map<std::string, ValueObject> GetAll() const; 156 157 /** 158 * @brief Obtains the ValuesBucket object's valuesmap. 159 */ 160 API_EXPORT void GetAll(std::map<std::string, ValueObject> &output) const; 161 162 /** 163 * @brief set a ValuesBucket object to parcel. 164 */ 165 API_EXPORT bool Marshalling(Parcel &parcel) const; 166 167 /** 168 * @brief Obtains a ValuesBucket object from parcel. 169 */ 170 API_EXPORT static ValuesBucket Unmarshalling(Parcel &parcel); 171 172 std::map<std::string, ValueObject> values_; 173 }; 174 175 } // namespace NativeRdb 176 } // namespace OHOS 177 #endif 178