1 /**
2  * @file  info_command.h
3  *
4  * @section LICENSE
5  *
6  * The MIT License
7  *
8  * @copyright Copyright (c) 2018-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 file declares the info command.
31  */
32 
33 #ifndef TILEDB_CLI_INFO_COMMAND_H
34 #define TILEDB_CLI_INFO_COMMAND_H
35 
36 #include "commands/command.h"
37 
38 #include "tiledb/sm/array_schema/domain.h"
39 #include "tiledb/sm/enums/datatype.h"
40 #include "tiledb/sm/misc/types.h"
41 
42 namespace tiledb {
43 namespace cli {
44 
45 /**
46  * Command that can display information about TileDB arrays.
47  */
48 class InfoCommand : public Command {
49  public:
50   /** Get the CLI for this command instance. */
51   clipp::group get_cli();
52 
53   /** Runs this info command. */
54   void run();
55 
56  private:
57   /** Types of information that can be displayed. */
58   enum class InfoType { None, TileSizes, SVGMBRs, DumpMBRs, ArraySchema };
59 
60   /** Type of information to display. */
61   InfoType type_ = InfoType::None;
62 
63   /** Array to print info for. */
64   std::string array_uri_;
65 
66   /** Path to write any output. */
67   std::string output_path_ = "";
68 
69   /** Width of output SVG. */
70   unsigned svg_width_ = 600;
71 
72   /** Height of output SVG. */
73   unsigned svg_height_ = 600;
74 
75   /** Prints information about the array's tile sizes. */
76   void print_tile_sizes() const;
77 
78   /** Prints basic information about the array schema. */
79   void print_schema_info() const;
80 
81   /** Dumps array MBRs to SVG. */
82   void write_svg_mbrs() const;
83 
84   /** Dumps array MBRs to text. */
85   void write_text_mbrs() const;
86 
87   /** Converts an opaque MBR to a 2D (double) rectangle. */
88   std::tuple<double, double, double, double> get_mbr(
89       const sm::NDRange& mbr, const tiledb::sm::Domain* domain) const;
90 
91   /**
92    * Converts an opaque MBR to a string vector. The vector contents are strings:
93    * [dim0_min, dim0_max, dim1_min, dim1_max, ...]
94    *
95    * @param mbr MBR to convert.
96    * @param domain The array domain.
97    * @return String vector representation of MBR.
98    */
99   std::vector<std::string> mbr_to_string(
100       const sm::NDRange& mbr, const tiledb::sm::Domain* domain) const;
101 };
102 
103 }  // namespace cli
104 }  // namespace tiledb
105 
106 #endif
107