Printers.cpp 912 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright Benoit Blanchon 2014-2015
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. #include "Printers.hpp"
  7. #include <ArduinoJson/JsonArray.hpp>
  8. class StreamPrintAdapter : public Print {
  9. public:
  10. explicit StreamPrintAdapter(std::ostream& os) : _os(os) {}
  11. virtual size_t write(uint8_t c) {
  12. _os << static_cast<char>(c);
  13. return 1;
  14. }
  15. private:
  16. // cannot be assigned
  17. StreamPrintAdapter& operator=(const StreamPrintAdapter&);
  18. std::ostream& _os;
  19. };
  20. std::ostream& ArduinoJson::operator<<(std::ostream& os,
  21. const ArduinoJson::JsonVariant& v) {
  22. StreamPrintAdapter adapter(os);
  23. v.printTo(adapter);
  24. return os;
  25. }
  26. std::ostream& ArduinoJson::operator<<(std::ostream& os,
  27. const ArduinoJson::JsonArray& v) {
  28. StreamPrintAdapter adapter(os);
  29. v.printTo(adapter);
  30. return os;
  31. }