aboutsummaryrefslogtreecommitdiff
path: root/libcutl/compiler/code-stream.txx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-12-16 20:29:05 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-02-24 16:40:04 +0300
commit8e761289a2446367267c6c0d9a26e734f0f78306 (patch)
treefb495d8c18801f271d124ee48731f10df396ca89 /libcutl/compiler/code-stream.txx
parent4c8104756b92b9fa16b3a725e8a6aa620dfd606e (diff)
Get rid of legacy build systems and rename cutl/ to libcutl/
Diffstat (limited to 'libcutl/compiler/code-stream.txx')
-rw-r--r--libcutl/compiler/code-stream.txx93
1 files changed, 93 insertions, 0 deletions
diff --git a/libcutl/compiler/code-stream.txx b/libcutl/compiler/code-stream.txx
new file mode 100644
index 0000000..15fc351
--- /dev/null
+++ b/libcutl/compiler/code-stream.txx
@@ -0,0 +1,93 @@
+// file : libcutl/compiler/code-stream.txx
+// license : MIT; see accompanying LICENSE file
+
+namespace cutl
+{
+ namespace compiler
+ {
+ // code_stream
+ //
+
+ template <typename C>
+ code_stream<C>::~code_stream ()
+ {
+ }
+
+ // from_streambuf_adapter
+ //
+
+ template <typename C>
+ void from_streambuf_adapter<C>::
+ put (C c)
+ {
+ int_type i (stream_.sputc (c));
+
+ if (i == traits_type::eof ())
+ throw eof ();
+ }
+
+ template <typename C>
+ void from_streambuf_adapter<C>::
+ unbuffer ()
+ {
+ if (stream_.pubsync () != 0)
+ throw sync ();
+ }
+
+ // to_streambuf_adapter
+ //
+
+ template <typename C>
+ typename to_streambuf_adapter<C>::int_type to_streambuf_adapter<C>::
+ overflow (int_type i)
+ {
+ try
+ {
+ stream_.put (traits_type::to_char_type (i));
+ return i;
+ }
+ catch (typename from_streambuf_adapter<C>::eof const&)
+ {
+ return traits_type::eof ();
+ }
+ }
+
+ template <typename C>
+ int to_streambuf_adapter<C>::
+ sync ()
+ {
+ return 0;
+ }
+
+ // ostream_filter
+ //
+
+ template <template <typename> class S, typename C>
+ ostream_filter<S, C>::
+ ostream_filter (std::basic_ostream<C>& os)
+ : os_ (os),
+ prev_ (os_.rdbuf ()),
+ from_adapter_ (*prev_),
+ stream_ (from_adapter_),
+ to_adapter_ (stream_)
+ {
+ os_.rdbuf (&to_adapter_);
+ }
+
+ template <template <typename> class S, typename C>
+ ostream_filter<S, C>::
+ ~ostream_filter ()
+ {
+ try
+ {
+ stream_.unbuffer ();
+ }
+ catch (...)
+ {
+ os_.rdbuf (prev_);
+ }
+
+ os_.rdbuf (prev_);
+ }
+ }
+}