/src/lib/io/core/file_stream.e

http://github.com/tybor/Liberty · Specman e · 74 lines · 37 code · 7 blank · 30 comment · 1 complexity · 805a3779a02330d18aad4667f0b173ba 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 FILE_STREAM
  5. --
  6. -- Common parent class to all the file-related streams. Provides a common
  7. -- connection interface to the "real" files of the operating system.
  8. --
  9. inherit
  10. STREAM
  11. feature {ANY}
  12. path: STRING
  13. -- Not Void when connected to the corresponding file on the disk.
  14. is_connected: BOOLEAN
  15. -- Is this file connected to some file of the operating system?
  16. do
  17. Result := path /= Void
  18. ensure
  19. definition: Result = (path /= Void)
  20. end
  21. connect_to (new_path: ABSTRACT_STRING)
  22. -- Try to connect to an existing file of the operating system.
  23. require
  24. not is_connected
  25. not_malformed_path: not new_path.is_empty
  26. deferred
  27. ensure
  28. is_connected implies path.same_as(new_path.out)
  29. end
  30. feature {}
  31. set_path (new_path: ABSTRACT_STRING)
  32. do
  33. if path = Void then
  34. path := new_path.out
  35. else
  36. lock_tagged_out
  37. tagged_out_memory.clear_count
  38. new_path.out_in_tagged_out_memory
  39. path.copy(tagged_out_memory)
  40. unlock_tagged_out
  41. end
  42. ensure
  43. path.same_as(new_path.out)
  44. end
  45. invariant
  46. is_connected implies path /= Void
  47. end -- class FILE_STREAM
  48. --
  49. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  50. --
  51. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  52. -- of this software and associated documentation files (the "Software"), to deal
  53. -- in the Software without restriction, including without limitation the rights
  54. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  55. -- copies of the Software, and to permit persons to whom the Software is
  56. -- furnished to do so, subject to the following conditions:
  57. --
  58. -- The above copyright notice and this permission notice shall be included in
  59. -- all copies or substantial portions of the Software.
  60. --
  61. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  62. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  63. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  64. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  65. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  66. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  67. -- THE SOFTWARE.