From a15cf65c44d5c224169c32ef5495b68c758134b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 18 May 2014 16:08:14 +0200 Subject: Imported Upstream version 3.3.0.2 --- .../backend-elements/indentation/clip.hxx | 173 +++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 libbackend-elements/backend-elements/indentation/clip.hxx (limited to 'libbackend-elements/backend-elements/indentation/clip.hxx') diff --git a/libbackend-elements/backend-elements/indentation/clip.hxx b/libbackend-elements/backend-elements/indentation/clip.hxx new file mode 100644 index 0000000..068ed0d --- /dev/null +++ b/libbackend-elements/backend-elements/indentation/clip.hxx @@ -0,0 +1,173 @@ +// file : backend-elements/indentation/clip.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Boris Kolpackov +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef BACKEND_ELEMENTS_INDENTATION_CLIP_HXX +#define BACKEND_ELEMENTS_INDENTATION_CLIP_HXX + +#include + +#include + +#include + +namespace BackendElements +{ + namespace Indentation + { + template + class ToStreambufAdapter: public std::basic_streambuf, + public NonCopyable + { + public: + typedef + typename std::basic_streambuf::traits_type + Traits; + + typedef + typename std::basic_streambuf::char_type + AsChar; + + typedef + typename std::basic_streambuf::int_type + AsInt; + + public: + ToStreambufAdapter (Buffer& buffer) + : buffer_ (buffer) + { + } + + virtual AsInt + overflow (AsInt ch) + { + return buffer_.put (Traits::to_char_type (ch)); + } + + virtual Int + sync () + { + return 0; + } + + private: + Buffer& buffer_; + }; + + + template + class FromStreambufAdapter: public Buffer + { + public: + typedef + typename Buffer::Traits + Traits; + + typedef + typename Buffer::AsChar + AsChar; + + typedef + typename Buffer::AsInt + AsInt; + + typedef + typename Buffer::Write + Write; + + public: + FromStreambufAdapter (std::basic_streambuf& b) + : buffer_ (b) + { + } + + virtual AsInt + put (AsChar ch) + { + return buffer_.sputc (ch); + } + + virtual Void + unbuffer () + { + try + { + if (buffer_.pubsync () == 0) return; + } + catch (std::ios_base::failure const&) + { + } + + throw Write (); + } + + private: + std::basic_streambuf& buffer_; + }; + + + template