1 /* 2 * Copyright (c) 2024 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_BUCKETS_H 17 #define NATIVE_RDB_VALUES_BUCKETS_H 18 19 #include <map> 20 #include <memory> 21 #include <set> 22 23 #include "value_object.h" 24 #include "values_bucket.h" 25 26 namespace OHOS { 27 namespace NativeRdb { 28 class API_EXPORT ValuesBuckets { 29 public: 30 using FieldsType = std::shared_ptr<std::set<std::string>>; 31 using ValuesType = std::shared_ptr<std::set<ValueObject>>; 32 using FieldType = std::reference_wrapper<const std::string>; 33 using ValueType = std::reference_wrapper<ValueObject>; 34 using BucketType = std::map<FieldType, ValueType, std::less<std::string>>; 35 36 API_EXPORT ValuesBuckets(); 37 API_EXPORT ValuesBuckets(const std::vector<ValuesBucket> &rows); 38 API_EXPORT ValuesBuckets(std::vector<ValuesBucket> &&rows) noexcept; 39 40 API_EXPORT size_t RowSize() const; 41 API_EXPORT std::pair<FieldsType, ValuesType> GetFieldsAndValues() const; 42 43 API_EXPORT void Reserve(int32_t size); 44 API_EXPORT void Put(const ValuesBucket &bucket); 45 API_EXPORT void Put(ValuesBucket &&bucket); 46 API_EXPORT std::pair<int, ValueType> Get(size_t row, const FieldType &field) const; 47 48 API_EXPORT void Clear(); 49 50 private: 51 FieldsType fields_; 52 ValuesType values_; 53 std::vector<BucketType> buckets_; 54 }; 55 56 } // namespace NativeRdb 57 } // namespace OHOS 58 #endif 59