json_spirit_stream_reader.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef JSON_SPIRIT_READ_STREAM
  2. #define JSON_SPIRIT_READ_STREAM
  3. // Copyright John W. Wilkinson 2007 - 2009.
  4. // Distributed under the MIT License, see accompanying file LICENSE.txt
  5. // json spirit version 4.03
  6. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  7. # pragma once
  8. #endif
  9. #include "json_spirit_reader_template.h"
  10. namespace json_spirit
  11. {
  12. // these classes allows you to read multiple top level contiguous values from a stream,
  13. // the normal stream read functions have a bug that prevent multiple top level values
  14. // from being read unless they are separated by spaces
  15. template< class Istream_type, class Value_type >
  16. class Stream_reader
  17. {
  18. public:
  19. Stream_reader( Istream_type& is )
  20. : iters_( is )
  21. {
  22. }
  23. bool read_next( Value_type& value )
  24. {
  25. return read_range( iters_.begin_, iters_.end_, value );
  26. }
  27. private:
  28. typedef Multi_pass_iters< Istream_type > Mp_iters;
  29. Mp_iters iters_;
  30. };
  31. template< class Istream_type, class Value_type >
  32. class Stream_reader_thrower
  33. {
  34. public:
  35. Stream_reader_thrower( Istream_type& is )
  36. : iters_( is )
  37. , posn_begin_( iters_.begin_, iters_.end_ )
  38. , posn_end_( iters_.end_, iters_.end_ )
  39. {
  40. }
  41. void read_next( Value_type& value )
  42. {
  43. posn_begin_ = read_range_or_throw( posn_begin_, posn_end_, value );
  44. }
  45. private:
  46. typedef Multi_pass_iters< Istream_type > Mp_iters;
  47. typedef spirit_namespace::position_iterator< typename Mp_iters::Mp_iter > Posn_iter_t;
  48. Mp_iters iters_;
  49. Posn_iter_t posn_begin_, posn_end_;
  50. };
  51. }
  52. #endif