column_printer.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 2018 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef TEST_SCENARIO_COLUMN_PRINTER_H_
  11. #define TEST_SCENARIO_COLUMN_PRINTER_H_
  12. #include <functional>
  13. #include <memory>
  14. #include <string>
  15. #include <vector>
  16. #include "rtc_base/constructor_magic.h"
  17. #include "rtc_base/strings/string_builder.h"
  18. #include "test/logging/log_writer.h"
  19. namespace webrtc {
  20. namespace test {
  21. class ColumnPrinter {
  22. public:
  23. ColumnPrinter(const ColumnPrinter&);
  24. ~ColumnPrinter();
  25. static ColumnPrinter Fixed(const char* headers, std::string fields);
  26. static ColumnPrinter Lambda(
  27. const char* headers,
  28. std::function<void(rtc::SimpleStringBuilder&)> printer,
  29. size_t max_length = 256);
  30. protected:
  31. friend class StatesPrinter;
  32. const char* headers_;
  33. std::function<void(rtc::SimpleStringBuilder&)> printer_;
  34. size_t max_length_;
  35. private:
  36. ColumnPrinter(const char* headers,
  37. std::function<void(rtc::SimpleStringBuilder&)> printer,
  38. size_t max_length);
  39. };
  40. class StatesPrinter {
  41. public:
  42. StatesPrinter(std::unique_ptr<RtcEventLogOutput> writer,
  43. std::vector<ColumnPrinter> printers);
  44. RTC_DISALLOW_COPY_AND_ASSIGN(StatesPrinter);
  45. ~StatesPrinter();
  46. void PrintHeaders();
  47. void PrintRow();
  48. private:
  49. const std::unique_ptr<RtcEventLogOutput> writer_;
  50. const std::vector<ColumnPrinter> printers_;
  51. size_t buffer_size_ = 0;
  52. std::vector<char> buffer_;
  53. };
  54. } // namespace test
  55. } // namespace webrtc
  56. #endif // TEST_SCENARIO_COLUMN_PRINTER_H_