From f0510d2f90467de8e8f260b47d79a9baaf9bef17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2009 07:15:29 +0200 Subject: Start tracking XSD with git --- libxsd/xsd/cxx/zc-istream.hxx | 92 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 libxsd/xsd/cxx/zc-istream.hxx (limited to 'libxsd/xsd/cxx/zc-istream.hxx') diff --git a/libxsd/xsd/cxx/zc-istream.hxx b/libxsd/xsd/cxx/zc-istream.hxx new file mode 100644 index 0000000..2f0c1ed --- /dev/null +++ b/libxsd/xsd/cxx/zc-istream.hxx @@ -0,0 +1,92 @@ +// file : xsd/cxx/zc-istream.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_ZC_ISTREAM_HXX +#define XSD_CXX_ZC_ISTREAM_HXX + +#include +#include + +#include + +namespace xsd +{ + namespace cxx + { + // Input streambuffer that does not copy the underlying + // buffer (zero copy). + // + template + class zc_streambuf: public std::basic_streambuf + { + public: + typedef typename std::basic_streambuf::int_type int_type; + typedef typename std::basic_streambuf::traits_type traits_type; + + public: + zc_streambuf (const ro_string&); + zc_streambuf (const std::basic_string&); + + protected: + virtual std::streamsize + showmanyc (); + + virtual int_type + underflow (); + + private: + void + init (); + + private: + zc_streambuf (const zc_streambuf&); + + zc_streambuf& + operator= (const zc_streambuf&); + + private: + ro_string str_; + }; + + + // Input string stream that does not copy the underlying string. + // + template + class zc_istream_base + { + protected: + zc_istream_base (const ro_string&); + zc_istream_base (const std::basic_string&); + + protected: + zc_streambuf buf_; + }; + + template + class zc_istream: protected zc_istream_base, + public std::basic_istream + { + public: + zc_istream (const ro_string&); + zc_istream (const std::basic_string&); + + bool + exhausted () + { + return this->get () == std::basic_istream::traits_type::eof (); + } + + private: + zc_istream (const zc_istream&); + + zc_istream& + operator= (const zc_istream&); + }; + } +} + +#include + +#endif // XSD_CXX_ZC_ISTREAM_HXX -- cgit v1.1