cmStdIoConsole.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #ifdef _WIN32
  6. # include <memory>
  7. #endif
  8. namespace cm {
  9. namespace StdIo {
  10. /**
  11. * On Windows, enables I/O with `cin`, `cout`, and `cerr` in UTF-8 encoding.
  12. * On non-Windows platforms, does nothing.
  13. *
  14. * Construct an instance of this at the beginning of `main`:
  15. *
  16. * * If `cin`, `cout`, or `cerr` is attached to a Windows Console whose
  17. * input/output code page is not UTF-8, this replaces its `streambuf`
  18. * with one that reads/writes from/to the console using wide-character
  19. * Windows APIs to avoid limitations of the code page's narrow encoding.
  20. *
  21. * * If `cin`, `cout`, or `cerr` is not attached to a Windows Console,
  22. * this sets its stream to binary mode for consistency with the case
  23. * that it's attached to a console.
  24. *
  25. * Destroy the instance of this to restore the original `streambuf`s.
  26. */
  27. class Console
  28. {
  29. #ifdef _WIN32
  30. class Impl;
  31. std::unique_ptr<Impl> Impl_;
  32. #endif
  33. public:
  34. Console();
  35. ~Console(); // NOLINT(performance-trivially-destructible)
  36. Console(Console&&) noexcept;
  37. Console(Console const&) = delete;
  38. Console& operator=(Console&&) noexcept;
  39. Console& operator=(Console const&) = delete;
  40. };
  41. }
  42. }