key_value_printer.h 735 B

12345678910111213141516171819202122232425262728
  1. #pragma once
  2. #include <util/generic/string.h>
  3. #include <util/generic/typetraits.h>
  4. #include <util/generic/vector.h>
  5. #include <util/string/cast.h>
  6. class TKeyValuePrinter {
  7. private:
  8. TString Sep;
  9. TVector<TString> Keys;
  10. TVector<TString> Values;
  11. TVector<bool> AlignLefts;
  12. public:
  13. TKeyValuePrinter(const TString& sep = TString(": "));
  14. ~TKeyValuePrinter();
  15. template <typename TKey, typename TValue>
  16. void AddRow(const TKey& key, const TValue& value, bool leftAlign = !std::is_integral<TValue>::value) {
  17. return AddRowImpl(ToString(key), ToString(value), leftAlign);
  18. }
  19. TString PrintToString() const;
  20. private:
  21. void AddRowImpl(const TString& key, const TString& value, bool leftAlign);
  22. };