// file : CCF/CodeGenerationKit/IndentationImplanter.hpp // author : Boris Kolpackov // cvs-id : $Id$ #ifndef CCF_CODE_GENERATION_KIT_INDENTATION_IMPLANTER #define CCF_CODE_GENERATION_KIT_INDENTATION_IMPLANTER #include #include "CCF/CodeGenerationKit/IndentationBuffer.hpp" namespace Indentation { template class ToStreamBufAdapter : public std::basic_streambuf { public: typedef typename std::basic_streambuf::traits_type traits_type; typedef typename std::basic_streambuf::char_type char_type; typedef typename std::basic_streambuf::int_type int_type; public: ToStreamBufAdapter (Buffer& b) : buffer_ (b) { } virtual int_type overflow (int_type c) { return buffer_.put (traits_type::to_char_type (c)); } virtual int sync () { return 0; } private: Buffer& buffer_; }; template class FromStreamBufAdapter : public Buffer { public: typedef typename Buffer::traits_type traits_type; typedef typename Buffer::char_type char_type; typedef typename Buffer::int_type int_type; typedef typename Buffer::Exception Exception; public: FromStreamBufAdapter (std::basic_streambuf& b) : buffer_ (b) { } virtual int_type put (char_type c) throw (Exception, ExH::System::Exception) { return buffer_.sputc (c); } virtual void unbuffer () throw (ExH::System::Exception) { try { if (buffer_.pubsync () == 0) return; } catch (std::ios_base::failure const&) { } throw Exception ("underlying std::streambuf::sync failed"); } private: std::basic_streambuf& buffer_; }; template