StreamPrintAdapter.hpp 722 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright Benoit Blanchon 2014-2016
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. // If you like this project, please add a star!
  7. #pragma once
  8. #include "../Configuration.hpp"
  9. #if ARDUINOJSON_ENABLE_STD_STREAM
  10. #include "../Arduino/Print.hpp"
  11. #include <ostream>
  12. namespace ArduinoJson {
  13. namespace Internals {
  14. class StreamPrintAdapter : public Print {
  15. public:
  16. explicit StreamPrintAdapter(std::ostream& os) : _os(os) {}
  17. virtual size_t write(uint8_t c) {
  18. _os << static_cast<char>(c);
  19. return 1;
  20. }
  21. private:
  22. // cannot be assigned
  23. StreamPrintAdapter& operator=(const StreamPrintAdapter&);
  24. std::ostream& _os;
  25. };
  26. }
  27. }
  28. #endif // ARDUINOJSON_ENABLE_STD_STREAM