/src/lib/io/filter/monitored_input_stream.e

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