PageRenderTime 23ms CodeModel.GetById 17ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/src/lib/io/tools/standard_streams.e

http://github.com/tybor/Liberty
Specman e | 95 lines | 53 code | 13 blank | 29 comment | 0 complexity | 9b4062ad64ab33fc1c7cc55ad782dc4d MD5 | raw file
 1-- This file is part of a Liberty Eiffel library.
 2-- See the full copyright at the end.
 3--
 4class STANDARD_STREAMS
 5   --
 6   -- Thanks to this `standard_streams' singleton object, you can redirect `std_input_stream',
 7   -- `std_output_stream' as well as `std_error_stream'.
 8   --
 9   -- See also the examples from our tutorial/io directory.
10   --
11
12insert
13   SINGLETON
14      rename io as any_io,
15         std_input as any_std_input,
16         std_output as any_std_output,
17         std_error as any_std_error
18      end
19
20create {ANY}
21   make
22
23feature {ANY}
24   std_input: INPUT_STREAM
25
26   std_output: OUTPUT_STREAM
27
28   std_error: OUTPUT_STREAM
29
30feature {ANY}
31   set_std_input (a_std_input: like std_input)
32      require
33         a_std_input.is_connected
34      do
35         std_input := a_std_input
36      end
37
38   restore_std_input
39      do
40         set_std_input(any_std_input)
41      end
42
43   set_std_output (a_std_output: like std_output)
44      require
45         a_std_output.is_connected
46      do
47         std_output := a_std_output
48      end
49
50   restore_std_output
51      do
52         set_std_output(any_std_output)
53      end
54
55   set_std_error (a_std_error: like std_error)
56      require
57         a_std_error.is_connected
58      do
59         std_error := a_std_error
60      end
61
62   restore_std_error
63      do
64         set_std_error(any_std_error)
65      end
66
67feature {}
68   make
69      do
70         restore_std_input
71         restore_std_output
72         restore_std_error
73      end
74
75end -- class STANDARD_STREAMS
76--
77-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
78--
79-- Permission is hereby granted, free of charge, to any person obtaining a copy
80-- of this software and associated documentation files (the "Software"), to deal
81-- in the Software without restriction, including without limitation the rights
82-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
83-- copies of the Software, and to permit persons to whom the Software is
84-- furnished to do so, subject to the following conditions:
85--
86-- The above copyright notice and this permission notice shall be included in
87-- all copies or substantial portions of the Software.
88--
89-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
90-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
91-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
92-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
93-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
94-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
95-- THE SOFTWARE.