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 Put the integer double bool string bytes asset asset and so on 118 * to this {@code ValuesBucket} object for the given column name. 119 * 120 * @param columnName Indicates the name of the column. 121 */ 122 API_EXPORT void Put(const std::string &columnName, ValueObject &&value); 123 124 /** 125 * @brief Delete the ValueObject object for the given column name. 126 * 127 * @param columnName Indicates the name of the column. 128 */ 129 API_EXPORT void Delete(const std::string &columnName); 130 131 /** 132 * @brief Clear the ValuesBucket object's valuesmap. 133 */ 134 API_EXPORT void Clear(); 135 136 /** 137 * @brief Obtains the ValuesBucket object's valuesmap size. 138 */ 139 API_EXPORT int Size() const; 140 141 /** 142 * @brief Checks whether the ValuesBucket object's valuesmap is empty. 143 */ 144 API_EXPORT bool IsEmpty() const; 145 146 /** 147 * @brief Checks whether the ValuesBucket object's valuesmap contain the specified columnName. 148 * 149 * @param columnName Indicates the name of the column. 150 */ 151 API_EXPORT bool HasColumn(const std::string &columnName) const; 152 153 /** 154 * @brief Obtains the specified value for the given column name. 155 * 156 * @param columnName Indicates the name of the column. 157 */ 158 API_EXPORT bool GetObject(const std::string &columnName, ValueObject &value) const; 159 160 /** 161 * @brief Obtains the ValuesBucket object's valuesmap. 162 */ 163 API_EXPORT std::map<std::string, ValueObject> GetAll() const; 164 165 /** 166 * @brief Obtains the ValuesBucket object's valuesmap. 167 */ 168 API_EXPORT void GetAll(std::map<std::string, ValueObject> &output) const; 169 170 /** 171 * @brief set a ValuesBucket object to parcel. 172 */ 173 API_EXPORT bool Marshalling(Parcel &parcel) const; 174 175 /** 176 * @brief Obtains a ValuesBucket object from parcel. 177 */ 178 API_EXPORT static ValuesBucket Unmarshalling(Parcel &parcel); 179 180 std::map<std::string, ValueObject> values_; 181 }; 182 183 } // namespace NativeRdb 184 } // namespace OHOS 185 #endif 186