initial code repo
[stor4nfv.git] / src / ceph / src / json_spirit / json_spirit_stream_reader.h
diff --git a/src/ceph/src/json_spirit/json_spirit_stream_reader.h b/src/ceph/src/json_spirit/json_spirit_stream_reader.h
new file mode 100644 (file)
index 0000000..916725c
--- /dev/null
@@ -0,0 +1,70 @@
+#ifndef JSON_SPIRIT_READ_STREAM\r
+#define JSON_SPIRIT_READ_STREAM\r
+\r
+//          Copyright John W. Wilkinson 2007 - 2011\r
+// Distributed under the MIT License, see accompanying file LICENSE.txt\r
+\r
+// json spirit version 4.05\r
+\r
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)\r
+# pragma once\r
+#endif\r
+\r
+#include "json_spirit_reader_template.h"\r
+\r
+namespace json_spirit\r
+{\r
+    // these classes allows you to read multiple top level contiguous values from a stream,\r
+    // the normal stream read functions have a bug that prevent multiple top level values \r
+    // from being read unless they are separated by spaces\r
+\r
+    template< class Istream_type, class Value_type >\r
+    class Stream_reader\r
+    {\r
+    public:\r
+\r
+        Stream_reader( Istream_type& is )\r
+        :   iters_( is )\r
+        {\r
+        }\r
+\r
+        bool read_next( Value_type& value )\r
+        {\r
+            return read_range( iters_.begin_, iters_.end_, value );\r
+        }\r
+\r
+    private:\r
+\r
+        typedef Multi_pass_iters< Istream_type > Mp_iters;\r
+\r
+        Mp_iters iters_;\r
+    };\r
+\r
+    template< class Istream_type, class Value_type >\r
+    class Stream_reader_thrower\r
+    {\r
+    public:\r
+\r
+        Stream_reader_thrower( Istream_type& is )\r
+        :   iters_( is )\r
+        ,    posn_begin_( iters_.begin_, iters_.end_ )\r
+        ,    posn_end_( iters_.end_, iters_.end_ )\r
+        {\r
+        }\r
+\r
+        void read_next( Value_type& value )\r
+        {\r
+            posn_begin_ = read_range_or_throw( posn_begin_, posn_end_, value );\r
+        }\r
+\r
+    private:\r
+\r
+        typedef Multi_pass_iters< Istream_type > Mp_iters;\r
+        typedef spirit_namespace::position_iterator< typename Mp_iters::Mp_iter > Posn_iter_t;\r
+\r
+        Mp_iters iters_;\r
+        Posn_iter_t posn_begin_, posn_end_;\r
+    };\r
+}\r
+\r
+#endif\r