Debian Codegraph @

cutl/compiler/code-stream.txx

raw
1 // file : cutl/compiler/code-stream.txx
2 // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
3 // license : MIT; see accompanying LICENSE file
4
5 namespace cutl
6 {
7 namespace compiler
8 {
9 // code_stream
10 //
11
12 template <typename C>
13 code_stream<C>::~code_stream ()
14 {
15 }
16
17 // from_streambuf_adapter
18 //
19
20 template <typename C>
21 void from_streambuf_adapter<C>::
22 put (C c)
23 {
24 int_type i (stream_.sputc (c));
25
26 if (i == traits_type::eof ())
27 throw eof ();
28 }
29
30 template <typename C>
31 void from_streambuf_adapter<C>::
32 unbuffer ()
33 {
34 if (stream_.pubsync () != 0)
35 throw sync ();
36 }
37
38 // to_streambuf_adapter
39 //
40
41 template <typename C>
42 typename to_streambuf_adapter<C>::int_type to_streambuf_adapter<C>::
43 overflow (int_type i)
44 {
45 try
46 {
47 stream_.put (traits_type::to_char_type (i));
48 return i;
49 }
50 catch (typename from_streambuf_adapter<C>::eof const&)
51 {
52 return traits_type::eof ();
53 }
54 }
55
56 template <typename C>
57 int to_streambuf_adapter<C>::
58 sync ()
59 {
60 return 0;
61 }
62
63 // ostream_filter
64 //
65
66 template <template <typename> class S, typename C>
67 ostream_filter<S, C>::
68 ostream_filter (std::basic_ostream<C>& os)
69 : os_ (os),
70 prev_ (os_.rdbuf ()),
71 from_adapter_ (*prev_),
72 stream_ (from_adapter_),
73 to_adapter_ (stream_)
74 {
75 os_.rdbuf (&to_adapter_);
76 }
77
78 template <template <typename> class S, typename C>
79 ostream_filter<S, C>::
80 ~ostream_filter ()
81 {
82 try
83 {
84 stream_.unbuffer ();
85 }
86 catch (...)
87 {
88 os_.rdbuf (prev_);
89 throw;
90 }
91
92 os_.rdbuf (prev_);
93 }
94 }
95 }