• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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 TABLE_FILTER_CONSTRAINTS_H
17 #define TABLE_FILTER_CONSTRAINTS_H
18 
19 #include <string>
20 #include <vector>
21 #include "sqlite3.h"
22 
23 namespace SysTuning {
24 namespace TraceStreamer {
25 class FilterConstraints {
26 public:
27     struct Constraint {
28         int32_t idxInaConstraint; // index in sqlite3_index_info.aConstraint[]
29         int32_t col;              // Column this constraint refers to
30         unsigned char op;         // SQLite op for the constraint
31         bool isSupport = false;
32     };
33     using OrderBy = sqlite3_index_info::sqlite3_index_orderby;
34 
FilterConstraints()35     FilterConstraints() {}
~FilterConstraints()36     ~FilterConstraints() {}
37     void AddConstraint(int32_t idx, int32_t col, unsigned char op, bool isSupport = false);
38     void UpdateConstraint(int32_t idx, bool isSupport);
39     void AddOrderBy(int32_t col, unsigned char desc);
40     void Clear();
41 
GetOrderBys()42     const std::vector<OrderBy> &GetOrderBys() const
43     {
44         return orderBys_;
45     }
46 
GetConstraints()47     const std::vector<Constraint> &GetConstraints() const
48     {
49         return constraints_;
50     }
51 
52     // idxStr format: C<N> col1 op1 ... colN opN O<M> col1 desc1 ... colM descM
53     // like as "C2 0 2 1 4 O1 0 1"
54     void ToString(std::string &idxStr) const;
55     void FromString(const std::string &idxStr);
56 
57 private:
58     void GetColAndOp(const char **p, char **pNext, int32_t &col, unsigned char &op);
59 
60 private:
61     std::vector<Constraint> constraints_;
62     std::vector<OrderBy> orderBys_;
63     const std::size_t idxStrSize_ = 512;
64 };
65 } // namespace TraceStreamer
66 } // namespace SysTuning
67 
68 #endif // TABLE_FILTER_CONSTRAINTS_H
69