json_binder_parser.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. namespace json {
  13. class value;
  14. namespace binder { template <typename, typename> class visitor; }
  15. namespace parser {
  16. template <typename T, typename S>
  17. void parse(binder::visitor<T, S>&, char const*, options opts = allow_all);
  18. template <typename T, typename S>
  19. void parse(binder::visitor<T, S>&& v, std::string const& s, options opts = allow_all) {
  20. parse(static_cast<binder::visitor<T, S>&>(v), s.c_str(), opts);
  21. }
  22. template <typename T, typename S>
  23. void parse(binder::visitor<T, S>&& v, std::istream & in, options opts = allow_all) {
  24. if (!in) return;
  25. in.seekg(0, std::ios_base::end);
  26. std::istream::pos_type end = in.tellg();
  27. std::unique_ptr<char[]> data{new char[end]};
  28. in.seekg(0);
  29. in.read(data.get(), end);
  30. parse(static_cast<binder::visitor<T, S>&>(v), data.get(), opts);
  31. }
  32. }
  33. }
  34. #endif /* json_parser_h */