/src/lib/io/core/filter.e

http://github.com/tybor/Liberty · Specman e · 112 lines · 61 code · 13 blank · 38 comment · 0 complexity · 832f306404678408c50422b84f8da4c7 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. deferred class FILTER
  5. --
  6. -- A filter is something connected to a stream. It allows to add behavior (e.g. compression, encryption
  7. -- and any other codings).
  8. --
  9. -- There are two kinds of filters:
  10. -- * ''input'' filters (see FILTER_INPUT_STREAM)
  11. -- * ''output'' filters (see FILTER_OUTPUT_STREAM)
  12. --
  13. feature {ANY}
  14. connect_to (a_stream: like stream)
  15. -- Connect the filter to some underlying stream.
  16. require
  17. not is_connected
  18. a_stream.is_connected
  19. not a_stream.is_filtered
  20. do
  21. a_stream.set_filter(Current)
  22. stream := a_stream
  23. ensure
  24. is_connected
  25. end
  26. is_connected: BOOLEAN
  27. -- True if the filter is connected to some underlying stream.
  28. do
  29. Result := stream /= Void and then stream.is_connected
  30. end
  31. disconnect
  32. -- Disconnect from the underlying stream.
  33. require
  34. is_connected
  35. can_disconnect
  36. deferred
  37. ensure
  38. not is_connected
  39. stream = Void
  40. end
  41. can_disconnect: BOOLEAN
  42. do
  43. Result := local_can_disconnect and then stream.can_disconnect
  44. end
  45. feature {FILTER}
  46. filtered_descriptor: INTEGER
  47. do
  48. Result := stream.filtered_descriptor
  49. end
  50. filtered_has_descriptor: BOOLEAN
  51. do
  52. Result := stream.filtered_has_descriptor
  53. end
  54. filtered_stream_pointer: POINTER
  55. do
  56. Result := stream.filtered_stream_pointer
  57. end
  58. filtered_has_stream_pointer: BOOLEAN
  59. do
  60. Result := stream.filtered_has_stream_pointer
  61. end
  62. feature {}
  63. local_can_disconnect: BOOLEAN
  64. -- True if this stream can be safely disconnected (without data loss, etc.) without taking into
  65. -- account the state of the underlying stream.
  66. deferred
  67. end
  68. stream: FILTERABLE
  69. -- The underlying stream (i.e. the filtered one)
  70. feature {STREAM}
  71. do_detach
  72. -- Used by the underlying stream to require not to be filtered anymore
  73. deferred
  74. ensure
  75. stream = Void
  76. end
  77. invariant
  78. stream /= Void implies stream.filter = Current
  79. end -- class FILTER
  80. --
  81. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  82. --
  83. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  84. -- of this software and associated documentation files (the "Software"), to deal
  85. -- in the Software without restriction, including without limitation the rights
  86. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  87. -- copies of the Software, and to permit persons to whom the Software is
  88. -- furnished to do so, subject to the following conditions:
  89. --
  90. -- The above copyright notice and this permission notice shall be included in
  91. -- all copies or substantial portions of the Software.
  92. --
  93. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  94. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  95. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  96. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  97. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  98. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  99. -- THE SOFTWARE.