author | František Kučera <franta-hg@frantovo.cz> |
Sun, 09 Sep 2018 21:01:33 +0200 | |
branch | v_0 |
changeset 6 | fc1e746e26a5 |
parent 5 | 911ec74cce33 |
child 7 | 2057919937fa |
permissions | -rw-r--r-- |
5
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
#pragma once |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
#include <string> |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
#include <vector> |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
#include <iostream> |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
#include <sstream> |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
#include <locale> |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
#include <codecvt> |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
#include <regex> |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
#include <relpipe/reader/typedefs.h> |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
#include <relpipe/reader/TypeId.h> |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
#include <relpipe/reader/handlers/RelationalReaderStringHandler.h> |
6
fc1e746e26a5
use AttributeMetadata instead of std::pair for relation header
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
14 |
#include <relpipe/reader/handlers/AttributeMetadata.h> |
5
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
namespace relpipe { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
namespace out { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
namespace tabular { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
using namespace relpipe::reader; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
class TabularPrefetchingHandler : public handlers::RelationalReaderStringHadler { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
private: |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
const char* INDENTATION = " "; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
const char* ESC_BRIGHT = "\u001b[1m"; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
const char* ESC_RED = "\u001b[31m"; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
const char* ESC_GREEN = "\u001b[32m"; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
const char* ESC_YELLOW = "\u001b[33m"; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
const char* ESC_CYAN = "\u001b[36m"; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
const char* ESC_RESET = "\u001b[0m"; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
const char* ESC_HEADER = ESC_BRIGHT; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
const char* ESC_BORDER = ESC_GREEN; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
const char* ESC_VALUE = ESC_CYAN; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
const char* ESC_REPLACEMENT = ESC_RED; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
const char* INDENT = " "; // table indent from the left |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
std::ostream &output; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
std::vector<TypeId> columnTypes; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
std::vector<string_t> columnTypeCodes; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
std::vector<string_t> columnNames; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
std::vector<integer_t> columnWidths; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
std::vector<string_t> values; // all values are saved here and processed at the end of the relation |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
integer_t columnCount = 0; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
const string_t colorizeReplacement(const string_t &replacement, const char* valueColor) { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
return convertor.from_bytes(ESC_RESET) + convertor.from_bytes(ESC_REPLACEMENT) + replacement + convertor.from_bytes(ESC_RESET) + convertor.from_bytes(valueColor); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
/** |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
* Sanitizes whitespace that could broke table layout. |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
* |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
* TODO: sanitize also escape sequences and emoji (resp. properly measure their width) |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
* |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
* @param value original value |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
* @param color value foreground color |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
* @return value with replaced whitespaces |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
*/ |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
const string_t formatValue(const string_t &value, const char* color) { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
std::wstringstream result; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
result << convertor.from_bytes(color); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
66 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
67 |
for (auto & ch : value) { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
68 |
switch (ch) { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
case L'\n': result << colorizeReplacement(L"↲", color); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
70 |
break; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
71 |
case L'\r': result << colorizeReplacement(L"⏎", color); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
72 |
break; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
73 |
case L'\t': result << colorizeReplacement(L"↹", color); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
74 |
break; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
75 |
case L' ': result << colorizeReplacement(L"⎵", color); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
76 |
break; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
77 |
default: result << ch; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
79 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
80 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
81 |
result << convertor.from_bytes(ESC_RESET); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
82 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
83 |
return result.str(); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
84 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
85 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
86 |
void printHorizontalLine(const string_t &left, const string_t &middle, const string_t &right) { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
87 |
const string_t bar = L"─"; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
88 |
// TODO: support also ASCII nostalgia: |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
89 |
// border = border.replaceAll("─", "-"); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
90 |
// border = border.replaceAll("│", "|"); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
91 |
// border = border.replaceAll("[╭┬╮├┼┤╰┴╯]", "+"); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
92 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
93 |
output << INDENT << ESC_BORDER; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
94 |
output << convertor.to_bytes(left); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
95 |
for (size_t c = 0; c < columnCount; c++) { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
96 |
integer_t width = columnWidths[c]; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
97 |
for (integer_t w = 0; w < (width + 2); w++) output << convertor.to_bytes(bar); // 2 = left and right padding of the value |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
98 |
if (c < (columnCount - 1)) output << convertor.to_bytes(middle); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
99 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
100 |
output << convertor.to_bytes(right); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
101 |
output << ESC_RESET << std::endl; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
102 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
103 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
104 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
105 |
void printCachedData() { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
106 |
// Compute column widths and paddings: |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
107 |
vector<integer_t> paddings(columnCount); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
108 |
for (size_t i = 0; i < columnCount; i++) { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
109 |
string_t typeCode = columnTypeCodes[i]; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
110 |
string_t columnName = columnNames[i]; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
111 |
integer_t minWidth = columnName.size() + typeCode.size() + 3; // 3 = " ()" in "columnName (typeCode)" |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
112 |
columnWidths[i] = max(columnWidths[i], minWidth); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
113 |
paddings[i] = columnWidths[i] - minWidth; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
114 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
115 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
116 |
printHorizontalLine(L"╭", L"┬", L"╮"); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
117 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
118 |
// Print column headers: |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
119 |
output << INDENT << ESC_BORDER << "│" << ESC_RESET; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
120 |
for (size_t i = 0; i < columnCount; i++) { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
121 |
output << " " << convertor.to_bytes(formatValue(columnNames[i], ESC_HEADER)); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
122 |
for (integer_t p = 0; p < paddings[i]; p++) { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
123 |
output << " "; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
124 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
125 |
output << " (" << convertor.to_bytes(columnTypeCodes[i]) << ")"; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
126 |
output << ESC_BORDER << " │" << ESC_RESET; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
127 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
128 |
output << std::endl; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
129 |
printHorizontalLine(L"├", L"┼", L"┤"); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
130 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
131 |
// Print particular rows: |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
132 |
for (size_t i = 0; i < values.size(); i++) { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
133 |
integer_t columnIndex = i % columnCount; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
134 |
if (columnIndex == 0) output << INDENT << ESC_BORDER << "│" << ESC_RESET; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
135 |
string_t stringValue = values[i]; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
136 |
integer_t padding = columnWidths[columnIndex] - stringValue.size(); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
137 |
boolean_t alignRight = columnTypes[columnIndex] == TypeId::BOOLEAN || columnTypes[columnIndex] == TypeId::INTEGER; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
138 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
139 |
if (alignRight) for (integer_t p = 0; p < padding; p++) output << " "; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
140 |
output << " " << convertor.to_bytes(formatValue(stringValue, ESC_VALUE)); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
141 |
if (!alignRight) for (integer_t p = 0; p < padding; p++) output << " "; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
142 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
143 |
output << ESC_BORDER << " │" << ESC_RESET; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
144 |
if (columnIndex == (columnCount - 1)) output << std::endl; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
145 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
146 |
printHorizontalLine(L"╰", L"┴", L"╯"); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
147 |
integer_t recordCount = values.size() / columnCount; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
148 |
output << ESC_YELLOW << "Record count: " << ESC_RESET << recordCount << std::endl; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
149 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
150 |
values.clear(); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
151 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
152 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
153 |
public: |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
154 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
155 |
TabularPrefetchingHandler(std::ostream& output) : output(output) { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
156 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
157 |
|
6
fc1e746e26a5
use AttributeMetadata instead of std::pair for relation header
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
158 |
void startRelation(string_t name, std::vector<handlers::AttributeMetadata> attributes) override { |
5
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
159 |
if (columnCount) printCachedData(); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
160 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
161 |
output << ESC_RED << convertor.to_bytes(name) << ":" << ESC_RESET << endl; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
162 |
columnCount = attributes.size(); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
163 |
columnTypes.resize(columnCount); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
164 |
columnTypeCodes.resize(columnCount); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
165 |
columnNames.resize(columnCount); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
166 |
columnWidths.resize(columnCount, 0); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
167 |
for (int i = 0; i < attributes.size(); i++) { |
6
fc1e746e26a5
use AttributeMetadata instead of std::pair for relation header
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
168 |
columnNames[i] = attributes[i].attributeName; |
fc1e746e26a5
use AttributeMetadata instead of std::pair for relation header
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
169 |
columnTypes[i] = attributes[i].typeId; |
fc1e746e26a5
use AttributeMetadata instead of std::pair for relation header
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
170 |
columnTypeCodes[i] = attributes[i].typeName; |
5
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
171 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
172 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
173 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
174 |
void attribute(const string_t& value) override { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
175 |
integer_t i = values.size() % columnCount; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
176 |
values.push_back(value); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
177 |
columnWidths[i] = max(columnWidths[i], value.length()); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
178 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
179 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
180 |
void endOfPipe() { |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
181 |
if (columnCount) printCachedData(); |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
182 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
183 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
184 |
}; |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
185 |
|
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
186 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
187 |
} |
911ec74cce33
tabular handler, based on the prototype code
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
188 |
} |