/src/lib/io/core/stream.e

http://github.com/tybor/Liberty · Specman e · 202 lines · 128 code · 21 blank · 53 comment · 4 complexity · f0f4ec4d36ed05e3e7a81b652896899f 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 STREAM
  5. --
  6. -- A stream of characters.
  7. --
  8. -- There are two kinds of streams:
  9. -- + input streams (see INPUT_STREAM)
  10. -- + output_streams (see OUTPUT_STREAM)
  11. --
  12. -- Streams can:
  13. -- + be connected (e.g. to some system object)
  14. -- + be used to read or write characters, only if they are connected
  15. -- + be filtered (see FILTER)
  16. --
  17. insert
  18. RECYCLABLE
  19. DISPOSABLE
  20. feature {ANY}
  21. is_connected: BOOLEAN
  22. -- True if the stream is connected. Only in that case can data be transferred via this stream.
  23. deferred
  24. end
  25. disconnect
  26. -- Try to disconnect the stream. Note that it *does not* ensure that the stream will effectively be
  27. -- disconnected (some terminal streams, for instance, are always connected) but the feature can be
  28. -- used to "shake off" filters.
  29. require
  30. is_connected
  31. can_disconnect
  32. deferred
  33. end
  34. descriptor: INTEGER
  35. -- Some OS-dependent descriptor. Mainly used by the sequencer library (see READY_CONDITION).
  36. require
  37. is_connected
  38. has_descriptor
  39. do
  40. Result := filtered_descriptor
  41. end
  42. has_descriptor: BOOLEAN
  43. -- True if that stream can be associated to some OS-meaningful descriptor.
  44. require
  45. is_connected
  46. do
  47. Result := filtered_has_descriptor
  48. end
  49. can_disconnect: BOOLEAN
  50. -- True if the stream can be safely disconnected (without data loss, etc.)
  51. require
  52. is_connected
  53. deferred
  54. end
  55. frozen url: URL
  56. -- The URL to this stream as resource
  57. do
  58. Result := url_memory
  59. if Result = Void then
  60. Result := new_url
  61. url_memory := Result
  62. end
  63. ensure
  64. not_void: Result /= Void
  65. always_the_same: Result = url
  66. end
  67. feature {}
  68. url_memory: URL
  69. new_url: URL
  70. deferred
  71. ensure
  72. Result /= Void
  73. end
  74. feature {STREAM_HANDLER}
  75. stream_pointer: POINTER
  76. -- Some Back-end-dependent pointer (FILE* in C, InputStream or OutputStream in Java)
  77. require
  78. is_connected
  79. has_stream_pointer
  80. do
  81. Result := filtered_stream_pointer
  82. end
  83. has_stream_pointer: BOOLEAN
  84. -- True if that stream can be associated to some Back-end-meaningful stream pointer.
  85. require
  86. is_connected
  87. do
  88. Result := filtered_has_stream_pointer
  89. end
  90. feature {FILTER}
  91. filtered_descriptor: INTEGER
  92. -- Find the descriptor of the terminal stream... Filters do not have descriptors of their own
  93. require
  94. is_connected
  95. filtered_has_descriptor
  96. deferred
  97. end
  98. filtered_has_descriptor: BOOLEAN
  99. -- True if the underlying terminal stream has a descriptor
  100. require
  101. is_connected
  102. deferred
  103. end
  104. filtered_stream_pointer: POINTER
  105. -- Find the pointer of the terminal stream... Filters do not have pointers of their own
  106. require
  107. is_connected
  108. filtered_has_stream_pointer
  109. deferred
  110. end
  111. filtered_has_stream_pointer: BOOLEAN
  112. -- True if the underlying terminal stream has a pointer
  113. require
  114. is_connected
  115. deferred
  116. end
  117. feature {ANY}
  118. event_exception: EVENT_DESCRIPTOR
  119. do
  120. Result := stream_exception
  121. if Result = Void then
  122. create stream_exception.make(Current)
  123. Result := stream_exception
  124. end
  125. end
  126. feature {}
  127. stream_exception: STREAM_EXCEPTION
  128. feature {RECYCLING_POOL}
  129. recycle
  130. do
  131. if is_connected then
  132. disconnect
  133. check
  134. -- Because the previous code is just here to catch
  135. -- non-clean usage of STREAMs:
  136. disconnect_file_after_use: False
  137. end
  138. end
  139. end
  140. feature {}
  141. dispose
  142. do
  143. if is_connected and then can_disconnect then
  144. check
  145. -- Because the previous code is just here to catch
  146. -- non-clean usage of STREAMs:
  147. disconnect_file_after_use: False
  148. end
  149. disconnect
  150. end
  151. end
  152. feature {}
  153. sequencer_descriptor (file: POINTER): INTEGER
  154. external "plug_in"
  155. alias "{
  156. location: "${sys}/plugins"
  157. module_name: "sequencer"
  158. feature_name: "sequencer_descriptor"
  159. }"
  160. end
  161. end -- class STREAM
  162. --
  163. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  164. --
  165. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  166. -- of this software and associated documentation files (the "Software"), to deal
  167. -- in the Software without restriction, including without limitation the rights
  168. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  169. -- copies of the Software, and to permit persons to whom the Software is
  170. -- furnished to do so, subject to the following conditions:
  171. --
  172. -- The above copyright notice and this permission notice shall be included in
  173. -- all copies or substantial portions of the Software.
  174. --
  175. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  176. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  177. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  178. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  179. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  180. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  181. -- THE SOFTWARE.