aboutsummaryrefslogtreecommitdiff
path: root/cutl/compiler/code-stream.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-09-13 11:52:46 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-09-13 11:52:46 +0200
commit0143e511f7a5f3595907787a832bee4e3cd03daf (patch)
tree141d76fb8c18a8258eaa7d20035e22875f1bf0a3 /cutl/compiler/code-stream.txx
parentcb9ea47e7825b5073d4d645afb94f6326cb7cf4d (diff)
Add code stream interface and SLOC counter
Diffstat (limited to 'cutl/compiler/code-stream.txx')
-rw-r--r--cutl/compiler/code-stream.txx96
1 files changed, 96 insertions, 0 deletions
diff --git a/cutl/compiler/code-stream.txx b/cutl/compiler/code-stream.txx
new file mode 100644
index 0000000..e834da7
--- /dev/null
+++ b/cutl/compiler/code-stream.txx
@@ -0,0 +1,96 @@
+// file : cutl/compiler/code-stream.txx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// 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_);
+ throw;
+ }
+
+ os_.rdbuf (prev_);
+ }
+ }
+}