/src/lib/io/internal/path_joiner.e
Specman e | 108 lines | 51 code | 9 blank | 48 comment | 0 complexity | 31eab8dac09d39280f93e89dbe16677a MD5 | raw file
1-- This file is part of a Liberty Eiffel library. 2-- See the full copyright at the end. 3-- 4deferred class PATH_JOINER 5 -- A protocol for PATH_NAMEs to describe themselves to other objects. 6 -- 7 -- A typical session goes like this: 8 -- # call `start_join' describing you drive (if any) and whether you are absolute or relative 9 -- # Repeatedly call the `join_xxx' procedures to describe yourself, more significant elements first (i.e. 10 -- generally left-to-right) 11 -- # call `end_join' 12 -- 13 -- Caveat: the only way to make sure that the target is not changed at all is by not starting a session. A 14 -- call to `start_join' (even with `drive'=Void and absoluteness=0) immediately followed by a call to 15 -- `end_join' can have some benign side-effect on the target (including some amount of normalization being performed). 16 17feature {PATH_JOINER} 18 start_join (drive: STRING; absoluteness: INTEGER) 19 -- Start joining an absolute path to `Current' 20 -- 21 -- `drive' is optional 22 -- `absoluteness' is, e.g., the number of leading slashes: 23 -- 0 for relative paths 24 -- 1 for absolute paths 25 -- more for super-absolute paths (for instance, network-wide) 26 require 27 absoluteness >= 0 28 deferred 29 end 30 31 join_directory (element: STRING) 32 -- Add a directory to the end of the path 33 require 34 element /= Void 35 do 36 join_element(element) 37 ensure 38 old join_error implies join_error 39 end 40 41 join_up 42 -- Go up one directory 43 deferred 44 ensure 45 old join_error implies join_error 46 end 47 48 join_file (element: STRING) 49 -- Add a file to the end of the path 50 require 51 element /= Void 52 do 53 join_element(element) 54 ensure 55 old join_error implies join_error 56 end 57 58 join_element (element: STRING) 59 -- Add an unspecified element (directory or file) to the end of the path 60 require 61 element /= Void 62 deferred 63 ensure 64 old join_error implies join_error 65 end 66 67 join_extension (an_extension: STRING) 68 -- Add an extension to the last element of the path 69 require 70 an_extension /= Void 71 deferred 72 ensure 73 old join_error implies join_error 74 end 75 76 end_join 77 -- Finish joining the path 78 deferred 79 ensure 80 old join_error implies join_error 81 end 82 83 join_error: BOOLEAN 84 -- Did an error occur during joining 85 deferred 86 end 87 88end -- class PATH_JOINER 89-- 90-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file. 91-- 92-- Permission is hereby granted, free of charge, to any person obtaining a copy 93-- of this software and associated documentation files (the "Software"), to deal 94-- in the Software without restriction, including without limitation the rights 95-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 96-- copies of the Software, and to permit persons to whom the Software is 97-- furnished to do so, subject to the following conditions: 98-- 99-- The above copyright notice and this permission notice shall be included in 100-- all copies or substantial portions of the Software. 101-- 102-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 103-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 104-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 105-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 106-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 107-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 108-- THE SOFTWARE.