/src/lib/io/filter/monitored_input_stream.e
Specman e | 87 lines | 49 code | 10 blank | 28 comment | 1 complexity | 3d6582f160f5766892933c60cb76cf5d MD5 | raw file
1-- This file is part of a Liberty Eiffel library. 2-- See the full copyright at the end. 3-- 4class MONITORED_INPUT_STREAM 5 -- 6 -- An input stream monitor. Monitored data goes to another output stream. 7 -- 8 -- See also MONITOR_OUTPUT_STREAM 9 -- 10 11inherit 12 FILTER_INPUT_STREAM 13 rename 14 connect_to as reconnect_to 15 end 16 17create {ANY} 18 connect_to 19 20feature {ANY} 21 monitor: OUTPUT_STREAM 22 23feature {} 24 local_can_disconnect: BOOLEAN True 25 unread_count: INTEGER 26 27feature {FILTER_INPUT_STREAM} 28 filtered_read_character 29 do 30 stream.filtered_read_character 31 if unread_count > 0 then 32 unread_count := unread_count - 1 33 elseif stream.valid_last_character and then monitor.is_connected then 34 monitor.put_character(stream.filtered_last_character) 35 end 36 end 37 38 filtered_unread_character 39 do 40 stream.filtered_unread_character 41 unread_count := unread_count + 1 42 end 43 44 filtered_last_character: CHARACTER 45 do 46 Result := stream.filtered_last_character 47 end 48 49feature {} 50 connect_to (a_stream: like stream; a_monitor: like monitor) 51 require 52 a_stream /= Void 53 a_monitor /= Void 54 do 55 a_stream.set_filter(Current) 56 stream := a_stream 57 monitor := a_monitor 58 ensure 59 stream = a_stream 60 monitor = a_monitor 61 end 62 63invariant 64 stream /= Void 65 monitor /= Void 66 67end -- class MONITORED_INPUT_STREAM 68-- 69-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file. 70-- 71-- Permission is hereby granted, free of charge, to any person obtaining a copy 72-- of this software and associated documentation files (the "Software"), to deal 73-- in the Software without restriction, including without limitation the rights 74-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 75-- copies of the Software, and to permit persons to whom the Software is 76-- furnished to do so, subject to the following conditions: 77-- 78-- The above copyright notice and this permission notice shall be included in 79-- all copies or substantial portions of the Software. 80-- 81-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 82-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 83-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 84-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 85-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 86-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 87-- THE SOFTWARE.