aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlnaz Nizametdinov <i.nizametdinov@gmail.com>2022-02-10 17:55:56 +0300
committerIlnaz Nizametdinov <i.nizametdinov@gmail.com>2022-02-10 17:55:56 +0300
commitc6af0bf45be29629c5dd6ec5f948f678aadce664 (patch)
treeea424a3063a301ec2f04f9aa0ac5a7a196c90636
parentdf6fbc0ac15dc095975d8e1b2029450c8fdd0e3e (diff)
downloadydb-c6af0bf45be29629c5dd6ec5f948f678aadce664.tar.gz
Cosmetic changes
ref:b568fd59170131358d9f9cc4ead6ec6ed323a33c
-rw-r--r--ydb/public/lib/ydb_cli/common/pretty_table.cpp3
-rw-r--r--ydb/public/lib/ydb_cli/common/pretty_table.h21
2 files changed, 16 insertions, 8 deletions
diff --git a/ydb/public/lib/ydb_cli/common/pretty_table.cpp b/ydb/public/lib/ydb_cli/common/pretty_table.cpp
index d376454198..dd9489dfab 100644
--- a/ydb/public/lib/ydb_cli/common/pretty_table.cpp
+++ b/ydb/public/lib/ydb_cli/common/pretty_table.cpp
@@ -81,8 +81,7 @@ void TPrettyTable::TRow::PrintFreeText(IOutputStream& o, size_t width) const {
}
TPrettyTable::TRow& TPrettyTable::AddRow() {
- Rows.push_back(TRow(Columns));
- return Rows.back();
+ return Rows.emplace_back(Columns);
}
static void PrintDelim(IOutputStream& o, const TVector<size_t>& widths,
diff --git a/ydb/public/lib/ydb_cli/common/pretty_table.h b/ydb/public/lib/ydb_cli/common/pretty_table.h
index f39411d902..21b5e70dec 100644
--- a/ydb/public/lib/ydb_cli/common/pretty_table.h
+++ b/ydb/public/lib/ydb_cli/common/pretty_table.h
@@ -32,18 +32,24 @@ class TPrettyTable {
public:
class TRow {
friend class TPrettyTable;
+ friend class std::allocator<TRow>; // for emplace_back()
+ // header row ctor
explicit TRow(const TVector<TString>& columnNames) {
+ Columns.reserve(columnNames.size());
for (const auto& name : columnNames) {
Columns.push_back({name});
}
}
+ // generic row ctor
explicit TRow(size_t nColumns);
public:
template <typename T>
TRow& Column(size_t index, const T& data) {
+ Y_VERIFY(index < Columns.size());
+
TString lines = TStringBuilder() << data;
for (auto& line : StringSplitter(lines).Split('\n')) {
@@ -57,7 +63,12 @@ public:
return *this;
}
- TRow& FreeText(TString text) {
+ inline TRow& FreeText(const TString& text) {
+ Text = text;
+ return *this;
+ }
+
+ inline TRow& FreeText(TString&& text) {
Text = std::move(text);
return *this;
}
@@ -71,16 +82,15 @@ public:
private:
TVector<TVector<TString>> Columns;
TString Text;
-
};
public:
- explicit TPrettyTable(const TVector<TString>& columnNames, const TPrettyTableConfig& config = TPrettyTableConfig())
+ explicit TPrettyTable(const TVector<TString>& columnNames, const TPrettyTableConfig& config = {})
: Columns(columnNames.size())
, Config(config)
{
if (Config.Header) {
- Rows.push_back(TRow(columnNames));
+ Rows.emplace_back(columnNames);
}
}
@@ -100,7 +110,6 @@ private:
}
}
-template <>
-inline void Out<NYdb::NConsoleClient::TPrettyTable>(IOutputStream& o, const NYdb::NConsoleClient::TPrettyTable& x) {
+Y_DECLARE_OUT_SPEC(inline, NYdb::NConsoleClient::TPrettyTable, o, x) {
return x.Print(o);
}