Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2011-11-25 00:21:39 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:28:43 +0300
commitc11367ac7accbbff694befc754132c3da8b76540 (patch)
tree5a106577d6acdc5395e3bfc919e7db3ab17e99de /coding/reader_streambuf.cpp
parent73e02dfa473887e41811da96f84133d790848551 (diff)
Add ReaderStreamBuf and WriterStreamBuf for std::istream and std::ostream interfaces.
Diffstat (limited to 'coding/reader_streambuf.cpp')
-rw-r--r--coding/reader_streambuf.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/coding/reader_streambuf.cpp b/coding/reader_streambuf.cpp
new file mode 100644
index 0000000000..3cfaef1fc8
--- /dev/null
+++ b/coding/reader_streambuf.cpp
@@ -0,0 +1,40 @@
+#include "reader_streambuf.hpp"
+#include "reader.hpp"
+
+#include "../std/algorithm.hpp"
+
+
+ReaderStreamBuf::ReaderStreamBuf(Reader * p)
+: m_p(p), m_pos(0), m_size(p->Size())
+{
+}
+
+ReaderStreamBuf::~ReaderStreamBuf()
+{
+ delete m_p;
+}
+
+std::streamsize ReaderStreamBuf::xsgetn(char_type * s, std::streamsize n)
+{
+ uint64_t const count = min(static_cast<uint64_t>(n), m_size - m_pos);
+ if (count > 0)
+ {
+ m_p->Read(m_pos, s, count);
+ m_pos += count;
+ }
+ return count;
+}
+
+ReaderStreamBuf::int_type ReaderStreamBuf::underflow()
+{
+ std::streamsize s = xsgetn(m_buf, sizeof(m_buf));
+ if (s > 0)
+ {
+ setg(m_buf, m_buf, m_buf + s);
+ return traits_type::to_int_type(m_buf[0]);
+ }
+ else
+ {
+ return traits_type::eof();
+ }
+}