PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

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