diff options
author | boris <boris@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-07-29 21:02:57 +0000 |
---|---|---|
committer | boris <boris@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-07-29 21:02:57 +0000 |
commit | 8e74d5c4835d2697a751d14f34e8fce8dd2bb815 (patch) | |
tree | 91f29899344d7aa43f3fb4f19411a74d51b4f5ab /TAO/CIAO/CCF/CCF/CodeGenerationKit/IndentationImplanter.hpp | |
parent | ae9e3373f3b5f62634d2df1f13748cc29f42246b (diff) | |
download | ATCD-8e74d5c4835d2697a751d14f34e8fce8dd2bb815.tar.gz |
Initial revision
Diffstat (limited to 'TAO/CIAO/CCF/CCF/CodeGenerationKit/IndentationImplanter.hpp')
-rw-r--r-- | TAO/CIAO/CCF/CCF/CodeGenerationKit/IndentationImplanter.hpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/TAO/CIAO/CCF/CCF/CodeGenerationKit/IndentationImplanter.hpp b/TAO/CIAO/CCF/CCF/CodeGenerationKit/IndentationImplanter.hpp new file mode 100644 index 00000000000..2688396360e --- /dev/null +++ b/TAO/CIAO/CCF/CCF/CodeGenerationKit/IndentationImplanter.hpp @@ -0,0 +1,117 @@ +#ifndef CCF_CODE_GENERATION_KIT_INDENTATION_IMPLANTER +#define CCF_CODE_GENERATION_KIT_INDENTATION_IMPLANTER + +#include <ostream> + +#include "CCF/CodeGenerationKit/IndentationBuffer.hpp" + +namespace Indentation +{ + class ToStreamBufAdapter : public std::streambuf + { + public: + ToStreamBufAdapter (Buffer& buffer) + : buffer_ (buffer) + { + } + + virtual int_type + overflow (int_type c) + { + return buffer_.put (Buffer::traits_type::to_char_type (c)); + } + + virtual int + sync () + { + return 0; + } + + private: + Buffer& buffer_; + }; + + class FromStreamBufAdapter : public Buffer + { + public: + FromStreamBufAdapter (std::streambuf& buffer) + : buffer_ (buffer) + { + } + + virtual int_type + put (char_type c) throw (Exception, ExH::System::Exception) + { + return buffer_.sputc (traits_type::to_int_type (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::streambuf& buffer_; + }; + + template <typename Buffer> + class Implanter + { + public: + Implanter (std::ostream& os) + : os_ (os), + prev_ (os_.rdbuf ()), + from_adapter_ (*prev_), + buffer_ (from_adapter_), + to_adapter_ (buffer_) + { + os_.rdbuf (&to_adapter_); + } + + template <typename Arg0> + Implanter (std::ostream& os, Arg0 a0) + : os_ (os), + prev_ (os_.rdbuf ()), + from_adapter_ (*prev_), + buffer_ (from_adapter_, a0), + to_adapter_ (buffer_) + { + os_.rdbuf (&to_adapter_); + } + + ~Implanter () + { + try + { + buffer_.unbuffer (); + } + catch (...) + { + // there is nothing I can do... + } + + os_.rdbuf (prev_); + } + + private: + std::ostream& os_; + std::streambuf* prev_; + + FromStreamBufAdapter from_adapter_; + + Buffer buffer_; + + ToStreamBufAdapter to_adapter_; + }; +} + +#endif // CCF_CODE_GENERATION_KIT_INDENTATION_IMPLANTER |