aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/key_value_printer.h
blob: b0277b15b6614e2cd8d64612c9b7195adc318c26 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once

#include <util/generic/string.h>
#include <util/generic/typetraits.h>
#include <util/generic/vector.h>
#include <util/string/cast.h>

class TKeyValuePrinter {
private:
    TString Sep;
    TVector<TString> Keys;
    TVector<TString> Values;
    TVector<bool> AlignLefts;
 
public:
    TKeyValuePrinter(const TString& sep = TString(": "));
    ~TKeyValuePrinter();

    template <typename TKey, typename TValue>
    void AddRow(const TKey& key, const TValue& value, bool leftAlign = !std::is_integral<TValue>::value) {
        return AddRowImpl(ToString(key), ToString(value), leftAlign);
    }

    TString PrintToString() const;

private:
    void AddRowImpl(const TString& key, const TString& value, bool leftAlign);
};