json_spirit_stream_reader.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
  2. #ifndef JSON_SPIRIT_READ_STREAM
  3. #define JSON_SPIRIT_READ_STREAM
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. #include "json_spirit_reader_template.h"
  8. namespace json_spirit
  9. {
  10. template< class Istream_type, class Value_type >
  11. class Stream_reader
  12. {
  13. public:
  14. Stream_reader( Istream_type& is )
  15. : iters_( is )
  16. {
  17. }
  18. bool read_next( Value_type& value )
  19. {
  20. return read_range( iters_.begin_, iters_.end_, value );
  21. }
  22. private:
  23. typedef Multi_pass_iters< Istream_type > Mp_iters;
  24. Mp_iters iters_;
  25. };
  26. template< class Istream_type, class Value_type >
  27. class Stream_reader_thrower
  28. {
  29. public:
  30. Stream_reader_thrower( Istream_type& is )
  31. : iters_( is )
  32. , posn_begin_( iters_.begin_, iters_.end_ )
  33. , posn_end_( iters_.end_, iters_.end_ )
  34. {
  35. }
  36. void read_next( Value_type& value )
  37. {
  38. posn_begin_ = read_range_or_throw( posn_begin_, posn_end_, value );
  39. }
  40. private:
  41. typedef Multi_pass_iters< Istream_type > Mp_iters;
  42. typedef spirit_namespace::position_iterator< typename Mp_iters::Mp_iter > Posn_iter_t;
  43. Mp_iters iters_;
  44. Posn_iter_t posn_begin_, posn_end_;
  45. };
  46. }
  47. #endif