• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 CLOUD_DB_TYPES_H
17 #define CLOUD_DB_TYPES_H
18 
19 #include "cloud/cloud_store_types.h"
20 #include <string>
21 
22 namespace DistributedDB {
23 struct CloudSyncBatch {
24     std::vector<VBucket> record;
25     std::vector<VBucket> extend;
26     std::vector<int64_t> rowid;
27     std::vector<int64_t> timestamp;
28     std::vector<VBucket> assets;
29 };
30 
31 struct CloudSyncData {
32     std::string tableName;
33     CloudSyncBatch insData;
34     CloudSyncBatch updData;
35     CloudSyncBatch delData;
36     bool isCloudForcePushStrategy = false;
37     CloudSyncData() = default;
CloudSyncDataCloudSyncData38     CloudSyncData(const std::string &_tableName) : tableName(_tableName) {};
39 };
40 
41 struct AssetField {
42     DistributedDB::Field field;
43     int64_t index = 0u;
44 };
45 
46 template<typename Tp, typename... Types>
47 struct index_of : std::integral_constant<size_t, 0> {};
48 
49 template<typename Tp, typename... Types>
50 inline static constexpr size_t index_of_v = index_of<Tp, Types...>::value;
51 
52 template<typename Tp, typename First, typename... Rest>
53 struct index_of<Tp, First, Rest...>
54     : std::integral_constant<size_t, std::is_same_v<Tp, First> ? 0 : index_of_v<Tp, Rest...> + 1> {};
55 
56 template<typename... Types>
57 struct variant_size_of {
58     static constexpr size_t value = sizeof...(Types);
59 };
60 
61 template<typename T, typename... Types>
62 struct variant_index_of {
63     static constexpr size_t value = index_of_v<T, Types...>;
64 };
65 
66 template<typename... Types>
67 static variant_size_of<Types...> variant_size_test(const std::variant<Types...> &);
68 
69 template<typename T, typename... Types>
70 static variant_index_of<T, Types...> variant_index_test(const T &, const std::variant<Types...> &);
71 
72 template<typename T>
73 inline constexpr static int32_t TYPE_INDEX =
74     decltype(variant_index_test(std::declval<T>(), std::declval<Type>()))::value;
75 
76 inline constexpr static int32_t TYPE_MAX = decltype(variant_size_test(std::declval<Type>()))::value;
77 
78 } // namespace DistributedDB
79 #endif // CLOUD_DB_TYPES_H
80