1 /**
2  * @file query_condition_op.h
3  *
4  * @section LICENSE
5  *
6  * The MIT License
7  *
8  * @copyright Copyright (c) 2021 TileDB, Inc.
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to deal
12  * in the Software without restriction, including without limitation the rights
13  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26  * THE SOFTWARE.
27  *
28  * @section DESCRIPTION
29  *
30  * This defines the tiledb QueryConditionOp enum that maps to
31  * tiledb_query_condition_op_t C-api enum.
32  */
33 
34 #ifndef TILEDB_QUERY_CONDITION_OP_H
35 #define TILEDB_QUERY_CONDITION_OP_H
36 
37 #include <cassert>
38 
39 #include "tiledb/common/status.h"
40 #include "tiledb/sm/misc/constants.h"
41 
42 using namespace tiledb::common;
43 
44 namespace tiledb {
45 namespace sm {
46 
47 /** Defines the query condition ops. */
48 enum class QueryConditionOp : uint8_t {
49 #define TILEDB_QUERY_CONDITION_OP_ENUM(id) id
50 #include "tiledb/sm/c_api/tiledb_enum.h"
51 #undef TILEDB_QUERY_CONDITION_OP_ENUM
52 };
53 
54 /** Returns the string representation of the input QueryConditionOp type. */
query_condition_op_str(QueryConditionOp query_condition_op)55 inline const std::string& query_condition_op_str(
56     QueryConditionOp query_condition_op) {
57   switch (query_condition_op) {
58     case QueryConditionOp::LT:
59       return constants::query_condition_op_lt_str;
60     case QueryConditionOp::LE:
61       return constants::query_condition_op_le_str;
62     case QueryConditionOp::GT:
63       return constants::query_condition_op_gt_str;
64     case QueryConditionOp::GE:
65       return constants::query_condition_op_ge_str;
66     case QueryConditionOp::EQ:
67       return constants::query_condition_op_eq_str;
68     case QueryConditionOp::NE:
69       return constants::query_condition_op_ne_str;
70     default:
71       return constants::empty_str;
72   }
73 }
74 
75 /** Returns the query condition_op given a string representation. */
query_condition_op_enum(const std::string & query_condition_op_str,QueryConditionOp * query_condition_op)76 inline Status query_condition_op_enum(
77     const std::string& query_condition_op_str,
78     QueryConditionOp* query_condition_op) {
79   if (query_condition_op_str == constants::query_condition_op_lt_str)
80     *query_condition_op = QueryConditionOp::LT;
81   else if (query_condition_op_str == constants::query_condition_op_le_str)
82     *query_condition_op = QueryConditionOp::LE;
83   else if (query_condition_op_str == constants::query_condition_op_gt_str)
84     *query_condition_op = QueryConditionOp::GT;
85   else if (query_condition_op_str == constants::query_condition_op_ge_str)
86     *query_condition_op = QueryConditionOp::GE;
87   else if (query_condition_op_str == constants::query_condition_op_eq_str)
88     *query_condition_op = QueryConditionOp::EQ;
89   else if (query_condition_op_str == constants::query_condition_op_ne_str)
90     *query_condition_op = QueryConditionOp::NE;
91   else {
92     return Status::Error("Invalid QueryConditionOp " + query_condition_op_str);
93   }
94   return Status::Ok();
95 }
96 
97 }  // namespace sm
98 }  // namespace tiledb
99 
100 #endif  // TILEDB_QUERY_CONDITION_OP_H
101