Automatic generation produced by ISE Eiffel

Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:
indexing description: "Directory name abstraction" status: "See notice at end of class" date: "$Date: 2001/11/16 20:34:11 $" revision: "$Revision: 1.1.1.1 $" class DIRECTORY_NAME create make, make_from_string feature -- Initialization make is -- Create path name object. -- (from PATH_NAME) do string_make (0) end make_from_string (p: STRING) is -- Create path name object and initialize it with the -- path name p -- (from PATH_NAME) do count := 0 string_make (0) append (p) ensure -- from PATH_NAME valid_file_name: is_valid end feature {NONE} -- Initialization adapt (s: STRING): like Current is -- Object of a type conforming to the type of s, -- initialized with attributes from s -- (from STRING) do create Result.string_make (0) Result.share (s) end from_c (c_string: POINTER) is -- Reset contents of string from contents of c_string, -- a string created by some external C function. -- (from STRING) require -- from STRING c_string_exists: c_string /= default_pointer local length: INTEGER do length := str_len (c_string) if capacity < length then make_area (length + 1) end; ($area).memory_copy (c_string, length) count := length ensure -- from STRING no_zero_byte: not has ('%U') end from_c_substring (c_string: POINTER; start_pos, end_pos: INTEGER) is -- Reset contents of string from substring of c_string, -- a string created by some external C function. -- (from STRING) require -- from STRING c_string_exists: c_string /= default_pointer start_position_big_enough: start_pos >= 1 end_position_big_enough: start_pos <= end_pos + 1 local length: INTEGER do length := end_pos - start_pos + 1 if capacity < length then make_area (length + 1) end; ($area).memory_copy (c_string + (start_pos - 1), (end_pos - start_pos + 1)) count := length ensure -- from STRING valid_count: count = end_pos - start_pos + 1 end string_make (n: INTEGER) is -- Allocate space for at least n characters. -- (from STRING) require -- from STRING non_negative_size: n >= 0 do count := 0 if n = 0 then area := empty_area else make_area (n + 1) end ensure -- from STRING empty_string: count = 0 area_allocated: capacity >= n end make_area (n: INTEGER) is -- Creates a special object for n entries. -- (from TO_SPECIAL) require -- from TO_SPECIAL non_negative_argument: n >= 0 do create area.make (n) ensure -- from TO_SPECIAL area_allocated: area /= void and then area.count = n end make_from_c (c_string: POINTER) is -- Initialize from contents of c_string, -- a string created by some external C function -- (from STRING) require -- from STRING c_string_exists: c_string /= default_pointer local length: INTEGER do length := str_len (c_string) make_area (length + 1); ($area).memory_copy (c_string, length) count := length end string_make_from_string (s: STRING) is -- Initialize from the characters of s. -- (Useful in proper descendants of class STRING, -- to initialize a string-like object from a manifest string.) -- (from STRING) require -- from STRING string_exists: s /= void do area := s.area count := s.count ensure -- from STRING shared_implementation: shared_with (s) end remake (n: INTEGER) is obsolete "Use `make' instead" -- Allocate space for at least n characters. -- (from STRING) require -- from STRING non_negative_size: n >= 0 do count := 0 string_make (n) ensure -- from STRING empty_string: count = 0 area_allocated: capacity >= n end feature {NONE} -- Access False_constant: STRING is "false" -- Constant string "false" -- (from STRING) fuzzy_index (other: STRING; start: INTEGER; fuzz: INTEGER): INTEGER is -- Position of first occurrence of other at or after start -- with 0..fuzz mismatches between the string and other. -- 0 if there are no fuzzy matches -- (from STRING) require -- from STRING other_exists: other /= void other_not_empty: not other.is_empty start_large_enough: start >= 1 start_small_enough: start <= count acceptable_fuzzy: fuzz <= other.count local a: ANY do a := other.area Result := str_str ($area, $a, count, other.count, start, fuzz) end has (c: CHARACTER): BOOLEAN is -- Does string include c? -- (from STRING) local counter: INTEGER do if not is_empty then from counter := 1 until counter > count or else (item (counter) = c) loop counter := counter + 1 end Result := (counter <= count) end ensure -- from CONTAINER not_found_in_empty: Result implies not is_empty end hash_code: INTEGER is -- Hash code value -- (from STRING) do Result := hashcode ($area, count) ensure -- from HASHABLE good_hash_value: Result >= 0 end index_of (c: CHARACTER; start: INTEGER): INTEGER is -- Position of first occurrence of c at or after start; -- 0 if none. -- (from STRING) require -- from STRING start_large_enough: start >= 1 start_small_enough: start <= count + 1 local a: like area i, nb: INTEGER do nb := count if start <= nb then from i := start - 1 nb := nb - 1 a := area until i > nb or else a.item (i) = c loop i := i + 1 end if i <= nb then Result := i + 1 end end ensure -- from STRING correct_place: Result > 0 implies item (Result) = c end item (i: INTEGER): CHARACTER is -- Character at position i -- Was declared in STRING as synonym of @. -- (from STRING) require -- from TABLE valid_key: valid_index (k) do Result := area.item (i - 1) end item_code (i: INTEGER): INTEGER is -- Numeric code of character at position i -- (from STRING) require -- from STRING index_small_enough: i <= count index_large_enough: i > 0 do Result := area.item (i - 1).code end last_index_of (c: CHARACTER; start_index_from_end: INTEGER): INTEGER is -- Position of last occurence of c. -- 0 if none -- (from STRING) require -- from STRING start_index_small_enough: start_index_from_end <= count start_index_large_enough: start_index_from_end >= 1 local a: like area i: INTEGER do from i := start_index_from_end - 1 a := area until i < 0 or else a.item (i) = c loop i := i - 1 end if i >= 0 then Result := i + 1 end ensure -- from STRING correct_place: Result > 0 implies item (Result) = c end shared_with (other: like Current): BOOLEAN is -- Does string share the text of other? -- (from STRING) do Result := (other /= void) and then (area = other.area) end substring_index (other: STRING; start: INTEGER): INTEGER is -- Position of first occurrence of other at or after start; -- 0 if none. -- (from STRING) require -- from STRING other_nonvoid: other /= void other_notempty: not other.is_empty start_large_enough: start >= 1 start_small_enough: start <= count local a: ANY do a := other.area Result := str_str ($area, $a, count, other.count, start, 0) ensure -- from STRING correct_place: Result > 0 implies substring (Result, Result + other.count - 1).is_equal (other) end True_constant: STRING is "true" -- Constant string "true" -- (from STRING) infix "@" (i: INTEGER): CHARACTER is -- Character at position i -- Was declared in STRING as synonym of item. -- (from STRING) require -- from TABLE valid_key: valid_index (k) do Result := area.item (i - 1) end feature {PATH_NAME} -- Access area: SPECIAL [CHARACTER] -- Special data zone -- (from TO_SPECIAL) feature {NONE} -- Measurement additional_space: INTEGER is -- Proposed number of additional items -- (from RESIZABLE) do Result := (capacity * growth_percentage // 100).max (minimal_increase) ensure -- from RESIZABLE at_least_one: Result >= 1 end capacity: INTEGER is -- Allocated space -- (from STRING) do Result := area.count - 1 end Growth_percentage: INTEGER is 50 -- Percentage by which structure will grow automatically -- (from RESIZABLE) index_set: INTEGER_INTERVAL is -- Range of acceptable indexes -- (from STRING) do create Result.make (1, count) ensure -- from INDEXABLE not_void: Result /= void ensure then -- from STRING Result.count = count end Minimal_increase: INTEGER is 5 -- Minimal number of additional items -- (from RESIZABLE) occurrences (c: CHARACTER): INTEGER is -- Number of times c appears in the string -- (from STRING) local counter, nb: INTEGER a: SPECIAL [CHARACTER] do from counter := 0 nb := count - 1 a := area until counter > nb loop if a.item (counter) = c then Result := Result + 1 end counter := counter + 1 end ensure -- from BAG non_negative_occurrences: Result >= 0 end feature {PATH_NAME} -- Measurement count: INTEGER -- Actual number of characters making up the string -- (from STRING) feature -- Comparison is_equal (other: like Current): BOOLEAN is -- Is the path name equal to other? -- (from PATH_NAME) require -- from ANY other_not_void: other /= void local o_area: like area do if other = Current then Result := True elseif other.count = count then o_area := other.area; Result := eif_path_name_compare ($area, $o_area, count) end ensure -- from ANY symmetric: Result implies other.is_equal (Current) consistent: standard_is_equal (other) implies Result ensure then -- from COMPARABLE trichotomy: Result = (not (Current < other) and not (other < Current)) end feature {NONE} -- Comparison max (other: like Current): like Current is -- The greater of current object and other -- (from COMPARABLE) require -- from COMPARABLE other_exists: other /= void do if Current >= other then Result := Current else Result := other end ensure -- from COMPARABLE current_if_not_smaller: Current >= other implies Result = Current other_if_smaller: Current < other implies Result = other end min (other: like Current): like Current is -- The smaller of current object and other -- (from COMPARABLE) require -- from COMPARABLE other_exists: other /= void do if Current <= other then Result := Current else Result := other end ensure -- from COMPARABLE current_if_not_greater: Current <= other implies Result = Current other_if_greater: Current > other implies Result = other end three_way_comparison (other: like Current): INTEGER is -- If current object equal to other, 0; -- if smaller, -1; if greater, 1 -- (from COMPARABLE) require -- from COMPARABLE other_exists: other /= void do if Current < other then Result := - 1 elseif other < Current then Result := 1 end ensure -- from COMPARABLE equal_zero: (Result = 0) = is_equal (other) smaller_negative: (Result = - 1) = (Current < other) greater_positive: (Result = 1) = (Current > other) end infix "<" (other: like Current): BOOLEAN is -- Is string lexicographically lower than other? -- (from STRING) require -- from PART_COMPARABLE other_exists: other /= void local other_area: like area other_count: INTEGER current_count: INTEGER do other_area := other.area other_count := other.count current_count := count if other_count = current_count then Result := str_strict_cmp ($other_area, $area, other_count) > 0 else if current_count < other_count then Result := str_strict_cmp ($other_area, $area, current_count) >= 0 else Result := str_strict_cmp ($other_area, $area, other_count) > 0 end end ensure then -- from COMPARABLE asymmetric: Result implies not (other < Current) end infix "<=" (other: like Current): BOOLEAN is -- Is current object less than or equal to other? -- (from COMPARABLE) require -- from PART_COMPARABLE other_exists: other /= void do Result := not (other < Current) ensure then -- from COMPARABLE definition: Result = ((Current < other) or is_equal (other)) end infix ">" (other: like Current): BOOLEAN is -- Is current object greater than other? -- (from COMPARABLE) require -- from PART_COMPARABLE other_exists: other /= void do Result := other < Current ensure then -- from COMPARABLE definition: Result = (other < Current) end infix ">=" (other: like Current): BOOLEAN is -- Is current object greater than or equal to other? -- (from COMPARABLE) require -- from PART_COMPARABLE other_exists: other /= void do Result := not (Current < other) ensure then -- from COMPARABLE definition: Result = (other <= Current) end feature -- Status report is_directory_name_valid (dir_name: STRING): BOOLEAN is -- Is dir_name a valid subdirectory part for the operating system? -- (from PATH_NAME) require -- from PATH_NAME exists: dir_name /= void local any: ANY do any := dir_name.to_c Result := eif_is_directory_name_valid ($any) end is_volume_name_valid (vol_name: STRING): BOOLEAN is -- Is vol_name a valid volume name for the operating system? -- (from PATH_NAME) require -- from PATH_NAME exists: vol_name /= void local any: ANY do any := vol_name.to_c Result := eif_is_volume_name_valid ($any) end feature {NONE} -- Status report Changeable_comparison_criterion: BOOLEAN is False -- (from STRING) Extendible: BOOLEAN is True -- May new items be added? (Answer: yes.) -- (from STRING) full: BOOLEAN is -- Is structure full? -- (from BOUNDED) do Result := (count = capacity) end is_boolean: BOOLEAN is -- Does Current represent a BOOLEAN? -- (from STRING) local s: STRING do s := clone (Current) s.right_adjust s.left_adjust s.to_lower Result := s.is_equal (true_constant) or else s.is_equal (false_constant) end is_double: BOOLEAN is -- Does Current represent a DOUBLE? -- (from STRING) do Result := str_isd ($area, count) end is_hashable: BOOLEAN is -- May current object be hashed? -- (True if it is not its type's default.) -- (from HASHABLE) do Result := (Current /= default) ensure -- from HASHABLE ok_if_not_default: Result implies (Current /= default) end is_inserted (v: CHARACTER): BOOLEAN is -- Has v been inserted by the most recent insertion? -- (By default, the value returned is equivalent to calling -- `has (v)'. However, descendants might be able to provide more -- efficient implementations.) -- (from COLLECTION) do Result := has (v) end is_integer: BOOLEAN is -- Does Current represent an INTEGER? -- (from STRING) do Result := str_isi ($area, count) end is_real: BOOLEAN is -- Does Current represent a REAL? -- (from STRING) do Result := str_isr ($area, count) end object_comparison: BOOLEAN -- Must search operations use equal rather than = -- for comparing references? (Default: no, use =.) -- (from CONTAINER) prunable: BOOLEAN is -- May items be removed? (Answer: yes.) -- (from STRING) do Result := True end resizable: BOOLEAN is -- May capacity be changed? (Answer: yes.) -- (from RESIZABLE) do Result := True end valid_index (i: INTEGER): BOOLEAN is -- Is i within the bounds of the string? -- (from STRING) do Result := (i > 0) and (i <= count) ensure then -- from INDEXABLE only_if_in_index_set: Result implies ((i >= index_set.lower) and (i <= index_set.upper)) end feature -- Status report empty: BOOLEAN is obsolete "ELKS 2000: Use `is_empty' instead" -- Is there no element? -- (from CONTAINER) do Result := is_empty end is_empty: BOOLEAN is -- Is structure empty? -- (from FINITE) do Result := (count = 0) end feature -- Status setting extend (directory_name: STRING) is -- Append the subdirectory directory_name to the path name. -- Was declared in PATH_NAME as synonym of set_subdirectory. -- (from PATH_NAME) require -- from PATH_NAME string_exists: directory_name /= void valid_directory_name: is_directory_name_valid (directory_name) local new_size: INTEGER str1, str2: ANY do new_size := count + directory_name.count + 5 if capacity < new_size then resize (new_size) end str1 := to_c str2 := directory_name.to_c eif_append_directory ($Current, $str1, $str2) ensure -- from PATH_NAME valid_file_name: is_valid end extend_from_array (directories: ARRAY [STRING]) is -- Append the subdirectories from directories to the path name. -- (from PATH_NAME) require -- from PATH_NAME array_exists: directories /= void and then not (directories.is_empty) local i, nb: INTEGER do from i := directories.lower nb := directories.upper until i > nb loop extend (directories.