54fdcce928be0e1e962c300354a64ab337e49ddb
[platform/core/security/vist.git] / src / vist / query-builder / condition.hpp
1 /*
2  *  Copyright (c) 2017-present Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  */
16
17 #pragma once
18
19 #include "type.hpp"
20
21 namespace vist {
22 namespace tsqb {
23 namespace condition {
24
25 struct Base {};
26
27 template<typename L, typename R>
28 struct And : public Base {
29         L l;
30         R r;
31
32         And(L l, R r) : l(l), r(r) {}
33         operator std::string() const
34         {
35                 return "AND";
36         }
37 };
38
39 template<typename L, typename R>
40 struct Or : public Base {
41         L l;
42         R r;
43
44         Or(L l, R r) : l(l), r(r) {}
45         operator std::string() const
46         {
47                 return "OR";
48         }
49 };
50
51 template<typename L, typename R>
52 struct Binary : public Base {
53         L l;
54         R r;
55
56         Binary(L l, R r) : l(l), r(r)
57         {
58                 using FieldType = typename L::FieldType;
59                 type::assert_compare(FieldType(), r);
60         }
61 };
62
63 template<typename L>
64 struct Binary<L, const char*> : public Base {
65         L l;
66         std::string r;
67
68         Binary(L l, const char* r) : l(l), r(r)
69         {
70                 using FieldType = typename L::FieldType;
71                 type::assert_compare(FieldType(), std::string());
72         }
73 };
74
75 enum class Join : int {
76         INNER,
77         CROSS,
78         LEFT_OUTER,
79         RIGHT_OUTER,
80         FULL_OUTER
81 };
82
83 inline std::string to_string(Join type)
84 {
85         switch (type) {
86         case Join::CROSS: return "CROSS";
87         case Join::LEFT_OUTER: return "LEFT OUTER";
88         case Join::RIGHT_OUTER: return "RIGHT OUTER";
89         case Join::FULL_OUTER: return "FULL OUTER";
90         case Join::INNER:
91         default:
92                 return "INNER";
93         }
94 }
95
96 } // namespace condition
97 } // namespace tsqb
98 } // namespace vist