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 <set>
21 #include <memory>
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 
38     API_EXPORT size_t RowSize() const;
39     API_EXPORT std::pair<FieldsType, ValuesType> GetFieldsAndValues() const;
40 
41     API_EXPORT void Put(const ValuesBucket &bucket);
42     API_EXPORT std::pair<int, ValueType> Get(size_t row, const FieldType &field) const;
43 
44 private:
45     FieldsType fields_;
46     ValuesType values_;
47     std::vector<BucketType> buckets_;
48 };
49 
50 } // namespace NativeRdb
51 } // namespace OHOS
52 #endif
53