1 /**
2 * @file query_status.h
3 *
4 * @section LICENSE
5 *
6 * The MIT License
7 *
8 * @copyright Copyright (c) 2017-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 QueryStatus enum that maps to tiledb_query_status_t
31 * C-api enum.
32 */
33
34 #ifndef TILEDB_QUERY_STATUS_H
35 #define TILEDB_QUERY_STATUS_H
36
37 #include <cassert>
38
39 #include "tiledb/common/status.h"
40 #include "tiledb/sm/misc/constants.h"
41
42 namespace tiledb {
43 namespace sm {
44
45 /** Defines the query statuses. */
46 enum class QueryStatus : uint8_t {
47 #define TILEDB_QUERY_STATUS_ENUM(id) id
48 #include "tiledb/sm/c_api/tiledb_enum.h"
49 #undef TILEDB_QUERY_STATUS_ENUM
50 };
51
52 /** Returns the string representation of the input querystatus type. */
query_status_str(QueryStatus query_status)53 inline const std::string& query_status_str(QueryStatus query_status) {
54 switch (query_status) {
55 case QueryStatus::FAILED:
56 return constants::query_status_failed_str;
57 case QueryStatus::COMPLETED:
58 return constants::query_status_completed_str;
59 case QueryStatus::INPROGRESS:
60 return constants::query_status_inprogress_str;
61 case QueryStatus::INCOMPLETE:
62 return constants::query_status_incomplete_str;
63 case QueryStatus::UNINITIALIZED:
64 return constants::query_status_uninitialized_str;
65 default:
66 return constants::empty_str;
67 }
68 }
69
70 /** Returns the query status given a string representation. */
query_status_enum(const std::string & query_status_str,QueryStatus * query_status)71 inline Status query_status_enum(
72 const std::string& query_status_str, QueryStatus* query_status) {
73 if (query_status_str == constants::query_status_failed_str)
74 *query_status = QueryStatus::FAILED;
75 else if (query_status_str == constants::query_status_completed_str)
76 *query_status = QueryStatus::COMPLETED;
77 else if (query_status_str == constants::query_status_inprogress_str)
78 *query_status = QueryStatus::INPROGRESS;
79 else if (query_status_str == constants::query_status_incomplete_str)
80 *query_status = QueryStatus::INCOMPLETE;
81 else if (query_status_str == constants::query_status_uninitialized_str)
82 *query_status = QueryStatus::UNINITIALIZED;
83 else {
84 return Status::Error("Invalid QueryStatus " + query_status_str);
85 }
86 return Status::Ok();
87 }
88
89 } // namespace sm
90 } // namespace tiledb
91
92 #endif // TILEDB_QUERY_STATUS_H
93