// 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