1 /**
2 * @file layout.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 Layout enum that maps to tiledb_layout_t C-api
31 * enum.
32 */
33
34 #ifndef TILEDB_LAYOUT_H
35 #define TILEDB_LAYOUT_H
36
37 #include "tiledb/common/status.h"
38 #include "tiledb/sm/misc/constants.h"
39
40 #include <cassert>
41
42 using namespace tiledb::common;
43
44 namespace tiledb {
45 namespace sm {
46
47 /** Defines a layout for the cell or tile order. */
48 enum class Layout : uint8_t {
49 #define TILEDB_LAYOUT_ENUM(id) id
50 #include "tiledb/sm/c_api/tiledb_enum.h"
51 #undef TILEDB_LAYOUT_ENUM
52 };
53
54 /** Returns the string representation of the input layout. */
layout_str(Layout layout)55 inline const std::string& layout_str(Layout layout) {
56 switch (layout) {
57 case Layout::COL_MAJOR:
58 return constants::col_major_str;
59 case Layout::ROW_MAJOR:
60 return constants::row_major_str;
61 case Layout::GLOBAL_ORDER:
62 return constants::global_order_str;
63 case Layout::UNORDERED:
64 return constants::unordered_str;
65 case Layout::HILBERT:
66 return constants::hilbert_str;
67 default:
68 return constants::empty_str;
69 }
70 }
71
72 /** Returns the layout enum given a string representation. */
layout_enum(const std::string & layout_str,Layout * layout)73 inline Status layout_enum(const std::string& layout_str, Layout* layout) {
74 if (layout_str == constants::col_major_str)
75 *layout = Layout::COL_MAJOR;
76 else if (layout_str == constants::row_major_str)
77 *layout = Layout::ROW_MAJOR;
78 else if (layout_str == constants::global_order_str)
79 *layout = Layout::GLOBAL_ORDER;
80 else if (layout_str == constants::unordered_str)
81 *layout = Layout::UNORDERED;
82 else if (layout_str == constants::hilbert_str)
83 *layout = Layout::HILBERT;
84 else {
85 return Status::Error("Invalid Layout " + layout_str);
86 }
87 return Status::Ok();
88 }
89
90 } // namespace sm
91 } // namespace tiledb
92
93 #endif // TILEDB_LAYOUT_H
94