work in progress | any

Class GENERAL

Halstenbach Eiffel 3.1


indexing
   description: "Platform-independent universal properties.",
                "This class is an ancestor to all developer-written classes."

class interface
   GENERAL

feature -- Access

   generator: STRING
      -- Name of current object's generating class
      -- (base class of the type of which it is a direct instance)
        
feature -- Comparison

   frozen deep_equal (some: GENERAL; other: like some): BOOLEAN
      -- Are some and other either both void
      -- or attached to isomorphic object structures?
      ensure
         shallow_implies_deep: standard_equal (some, other) implies Result;
         both_or_none_void: (some = void) implies (Result = (other = void));
         same_type: (Result and (some /= void)) implies some.same_type (other);
         symmetric: Result implies deep_equal (other, some)

   frozen equal (some: GENERAL; other: like some): BOOLEAN
      -- Are some and other either both void or attached
      -- to objects considered equal?
      ensure
         definition: Result = (some = void and other = void) or else ((some /= void and other /= void) and then some.is_equal (other))

   is_equal (other: like Current): BOOLEAN
      -- Is other attached to an object considered
      -- equal to current object?
      require
         other_not_void: other /= void
      ensure
         symmetric: Result implies other.is_equal (Current);
         consistent: standard_is_equal (other) implies Result

   frozen standard_equal (some: GENERAL; other: like some): BOOLEAN
      -- Are some and other either both void or attached to
      -- field-by-field identical objects of the same type?
      -- Always uses default object comparison criterion.
      ensure
         definition: Result = (some = void and other = void) or else ((some /= void and other /= void) and then some.standard_is_equal (other))

   frozen standard_is_equal (other: like Current): BOOLEAN
      -- Is other attached to an object of the same type
      -- as current object, and field-by-field identical to it?
      require
         other_not_void: other /= void
      ensure
         same_type: Result implies same_type (other);
         symmetric: Result implies other.standard_is_equal (Current)
        
feature -- Status report

   conforms_to (other: GENERAL): BOOLEAN
      -- Does type of current object conform to type
      -- of other (as per Eiffel: The Language, chapter 13)?
      require
         other_not_void: other /= void

   consistent (other: like Current): BOOLEAN
      -- Is current object in a consistent state so that other
      -- may be copied onto it? (Default answer: yes).

   same_type (other: GENERAL): BOOLEAN
      -- Is type of current object identical to type of other?
      require
         other_not_void: other /= void
      ensure
         definition: Result = (conforms_to (other) and other.conforms_to (Current))
        
feature -- Duplication

   frozen clone (other: GENERAL): like other
      -- Void if other is void; otherwise new object
      -- equal to other
      --
      -- For non-void other, clone calls copy;
      -- to change copying/cloning semantics, redefine copy.
      ensure
         equal: equal (Result, other)

   copy (other: like Current)
      -- Update current object using fields of object attached
      -- to other, so as to yield equal objects.
      require
         other_not_void: other /= void;
         type_identity: same_type (other)
      ensure
         is_equal: is_equal (other)

   frozen deep_clone (other: GENERAL): like other
      -- Void if other is void: otherwise, new object structure
      -- recursively duplicated from the one attached to other
      ensure
         deep_equal: deep_equal (other, Result)

   frozen deep_copy (other: like Current)
      -- Effect equivalent to that of:
      --              temp := deep_clone (other);
      --              copy (temp)
      require
         other_not_void: other /= void
      ensure
         deep_equal: deep_equal (Current, other)

   setup (other: like Current)
      -- Assuming current object has just been created, perform
      -- actions necessary to ensure that contents of other
      -- can be safely copied onto it.
      ensure
         consistent (other)

   frozen standard_clone (other: GENERAL): like other
      -- Void if other is void; otherwise new object
      -- field-by-field identical to other.
      -- Always uses default copying semantics.
      ensure
         equal: standard_equal (Result, other)

   frozen standard_copy (other: like Current)
      -- Copy every field of other onto corresponding field
      -- of current object.
      require
         other_not_void: other /= void;
         type_identity: same_type (other)
      ensure
         is_standard_equal: standard_is_equal (other)
        
feature -- Output

   Io: STD_FILES
      -- Handle to standard file setup

   out: STRING
      -- New string containing terse printable representation
      -- of current object
      -- Was declared in GENERAL as synonym of out and tagged_out.

   print (some: GENERAL)
      -- Write terse external representation of some
      -- on standard output.

   print_line (some: GENERAL)
      -- Print some on standard output followed by a new line.

   frozen tagged_out: STRING
      -- New string containing terse printable representation
      -- of current object
      -- Was declared in GENERAL as synonym of out and tagged_out.
        
feature -- Basic operations

   frozen default: like Current
      -- Default value of object's type

   frozen Default_pointer: POINTER
      -- Default value of type POINTER
      -- (Avoid the need to write p.default for
      -- some p of type POINTER.)

   frozen do_nothing
      -- Execute a null action.

   frozen void: NONE
      -- Void reference
        
feature {GENERAL} -- Implementation

   c_standard_clone (other: POINTER): GENERAL
      -- New object of same dynamic type as other
        
invariant

   reflexive_equality: standard_is_equal (Current);
   reflexive_conformance: conforms_to (Current);

end -- class GENERAL