Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
table-printer.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef IMPALA_UTIL_TABLE_PRINTER_H
17 #define IMPALA_UTIL_TABLE_PRINTER_H
18 
19 #include <boost/uuid/uuid.hpp>
20 
21 #include "gen-cpp/Types_types.h" // for TUniqueId
22 
23 namespace impala {
24 
27 class TablePrinter {
28  public:
29  TablePrinter();
30 
33  void AddColumn(const std::string& label, bool left_align);
34 
37  void set_max_output_width(int width);
38 
40  void AddRow(const std::vector<std::string>& row);
41 
43  std::string ToString(const std::string& prefix = "") const;
44 
45  private:
46  std::vector<std::string> labels_;
48  std::vector<bool> left_align_;
49 
52 
53  std::vector<std::vector<std::string> > rows_;
54  std::vector<int> max_col_widths_;
55 
57  void PrintRow(std::stringstream* ss, const std::vector<std::string>& row,
58  const std::vector<int>& widths) const;
59 };
60 
61 }
62 
63 #endif
std::string ToString(const std::string &prefix="") const
Print to a table with prefix coming before the output.
void AddColumn(const std::string &label, bool left_align)
std::vector< std::vector< std::string > > rows_
Definition: table-printer.h:53
std::vector< bool > left_align_
For each column, true if the value should be left aligned, right aligned otherwise.
Definition: table-printer.h:48
std::vector< std::string > labels_
Definition: table-printer.h:46
int max_output_width_
-1 to indicate unlimited.
Definition: table-printer.h:51
std::vector< int > max_col_widths_
Definition: table-printer.h:54
void AddRow(const std::vector< std::string > &row)
Add a row to the table. This must have the same width as labels.
void set_max_output_width(int width)
void PrintRow(std::stringstream *ss, const std::vector< std::string > &row, const std::vector< int > &widths) const
Helper function to print one row to ss.