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