json_binder_parser.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // json_binder.h
  3. // json
  4. //
  5. // Created by Sam Jaffe on 1/31/16.
  6. // Copyright © 2016 Sam Jaffe. All rights reserved.
  7. //
  8. #ifndef json_parser_h
  9. #define json_parser_h
  10. #pragma once
  11. #include <iostream>
  12. #include <memory>
  13. #include "json/json_common.hpp"
  14. namespace json {
  15. class value;
  16. namespace binder {
  17. template <typename, typename> class visitor;
  18. }
  19. namespace parser {
  20. template <typename T, typename S>
  21. void parse(binder::visitor<T, S> &, char const *, options opts = allow_all);
  22. template <typename T, typename S>
  23. void parse(binder::visitor<T, S> && v, std::string const & s,
  24. options opts = allow_all) {
  25. parse(static_cast<binder::visitor<T, S> &>(v), s.c_str(), opts);
  26. }
  27. template <typename T, typename S>
  28. void parse(binder::visitor<T, S> && v, std::istream & in,
  29. options opts = allow_all) {
  30. if (!in) return;
  31. in.seekg(0, std::ios_base::end);
  32. std::istream::pos_type end = in.tellg();
  33. std::unique_ptr<char[]> data{new char[end]};
  34. in.seekg(0);
  35. in.read(data.get(), end);
  36. parse(static_cast<binder::visitor<T, S> &>(v), data.get(), opts);
  37. }
  38. }
  39. }
  40. #endif /* json_parser_h */