note
	description: "Store all information about a mismatch in a type."
	legal: "See notice at end of class."
	status: "See notice at end of class."
	date: "$Date: 2020-05-19 14:29:33 +0000 (Tue, 19 May 2020) $"
	revision: "$Revision: 104259 $"

class 
	SED_TYPE_MISMATCH

create 
	make

feature {NONE} -- Initialization

	default_create
			-- Process instances of classes with no creation clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	make (a_type_id: INTEGER_32)
			-- Mismatch for dynamic type a_type_id in retrieving system.
		require
			type_id_non_negative: a_type_id >= 0
		local
			l_attribute_count: INTEGER_32
		do
			type_id := a_type_id
			l_attribute_count := Internal.field_count_of_type (type_id)
			create mismatches_by_name.make (l_attribute_count)
			create mismatches_by_stored_position.make (l_attribute_count)
		ensure
			type_id_set: type_id = a_type_id
		end
	
feature -- Access

	attribute_info: TUPLE [old_name: STRING_8; new_name: STRING_8; old_attribute_type: INTEGER_32; new_attribute_type: INTEGER_32; old_position: INTEGER_32; new_position: INTEGER_32; is_changed: BOOLEAN; is_removed: BOOLEAN; is_attachment_check_required: BOOLEAN]
			-- For typing purposes.
		require
			callable: False
		do
			check
					False
			then
			end
		end

	generating_type: TYPE [detachable SED_TYPE_MISMATCH]
			-- Type of current object
			-- (type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generating_type_not_void: Result /= Void
		end

	generator: STRING_8
			-- Name of current object's generating class
			-- (base class of the type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generator_not_void: Result /= Void
			generator_not_empty: not Result.is_empty
		end

	mismatches_by_name: HASH_TABLE [like attribute_info, STRING_8]
			-- Store information about mismatch based on the attribute name.

	mismatches_by_stored_position: HASH_TABLE [like attribute_info, INTEGER_32]
			-- Store information about mismatch based on the store position.

	new_count: INTEGER_32
			-- Number of attributes in original system and retrieving system.

	new_version: detachable IMMUTABLE_STRING_8
			-- Version in stored system and retrieving system.

	old_count: INTEGER_32
			-- Number of attributes in original system and retrieving system.

	old_version: detachable IMMUTABLE_STRING_8
			-- Version in stored system and retrieving system.

	type_id: INTEGER_32
			-- Type ID for type having the mismatch
	
feature -- Comparison

	frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_deep_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			shallow_implies_deep: standard_equal (a, b) implies Result
			both_or_none_void: (a = Void) implies (Result = (b = Void))
			same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
			symmetric: Result implies deep_equal (b, a)
		end

	frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))
		end

	frozen is_deep_equal alias "≡≡≡" (other: SED_TYPE_MISMATCH): BOOLEAN
			-- Are Current and other attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			shallow_implies_deep: standard_is_equal (other) implies Result
			same_type: Result implies same_type (other)
			symmetric: Result implies other.is_deep_equal (Current)
		end

	is_equal (other: SED_TYPE_MISMATCH): BOOLEAN
			-- Is other attached to an object considered
			-- equal to current object?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			symmetric: Result implies other ~ Current
			consistent: standard_is_equal (other) implies Result
		end

	frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.standard_is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))
		end

	frozen standard_is_equal alias "" (other: SED_TYPE_MISMATCH): BOOLEAN
			-- Is other attached to an object of the same type
			-- as current object, and field-by-field identical to it?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
		end
	
feature -- Status report

	conforms_to (other: ANY): BOOLEAN
			-- Does type of current object conform to type
			-- of other (as per Eiffel: The Language, chapter 13)?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		end

	has_new_attached_attribute: BOOLEAN
			-- Do we have new attached attributes that did not exist in the stored system?

	has_new_attribute: BOOLEAN
			-- Do we have new attributes that did not exist in the stored system?

	has_version_mismatch: BOOLEAN
			-- Do we have a mismatch in versioning?

	same_type (other: ANY): BOOLEAN
			-- Is type of current object identical to type of other?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))
		end
	
feature -- Element change

	add_attribute_count_mismatch (a_old_count, a_new_count: INTEGER_32)
			-- Mismatch where there is a_old_count attributes in the original system
			-- and a_new_count attributes in the retrieving system.
		require
			old_count_non_negative: a_old_count >= 0
			new_count_non_negative: a_new_count >= 0
		do
			old_count := a_old_count
			new_count := a_new_count
		ensure
			old_count_set: old_count = a_old_count
			new_count_set: new_count = a_new_count
		end

	add_attribute_mismatch (a_old_attr_type, a_new_attr_type: INTEGER_32; a_old_name, a_new_name: STRING_8; a_old_pos, a_new_pos: INTEGER_32)
			-- Mismatch for a_old_name where the new name is a_new_name, the new type
			-- a_new_attr_type is different from a_old_attr_type stored at position
			-- a_old_pos in the stored system for a a_new_pos in the retrieving system.
		require
			a_old_attr_type_non_negative: a_old_attr_type >= 0
			a_new_attr_type_non_negative: a_new_attr_type >= 0
			a_old_name_attached: a_old_name /= Void
			a_new_name_attached: a_new_name /= Void
			a_old_pos_positive: a_old_pos > 0
			a_new_pos_positive: a_new_pos > 0
		local
			l_info: like attribute_info
		do
			l_info := [a_old_name, a_new_name, a_old_attr_type, a_new_attr_type, a_old_pos, a_new_pos, True, False, False];
			mismatches_by_name.put (l_info, a_new_name);
			mismatches_by_stored_position.put (l_info, a_old_pos)
		end

	add_new_attribute_mismatch (a_added_attribute_count: INTEGER_32)
			-- Mismatch when new attributes have been added
		require
			a_added_attribute_count_positive: a_added_attribute_count > 0
		do
			has_new_attribute := True
		end

	add_removed_attribute (a_old_attr_type: INTEGER_32; a_old_name, a_new_name: STRING_8; a_old_pos: INTEGER_32)
			-- Attribute a_name of type a_old_attr_type at position a_old_pos in
			-- the stored system is now missing from Current.
		require
			a_old_attr_type_non_negative: a_old_attr_type >= 0
			a_old_name_attached: a_old_name /= Void
			a_new_name_attached: a_new_name /= Void
			a_old_pos_positive: a_old_pos > 0
		local
			l_info: like attribute_info
		do
			l_info := [a_old_name, a_new_name, a_old_attr_type, -1, a_old_pos, -1, False, True, False];
			mismatches_by_name.put (l_info, a_new_name);
			mismatches_by_stored_position.put (l_info, a_old_pos)
		end

	add_version_mismatch (a_old_version, a_new_version: detachable IMMUTABLE_STRING_8)
			-- Mismatch where the original system as a version a_old_version which differs
			-- from the version a_new_version in the retrieving system.
		require
			different_version: a_old_version /~ a_new_version
		do
			old_version := a_old_version
			new_version := a_new_version
			has_version_mismatch := True
		ensure
			old_version_set: old_version = a_old_version
			new_version_set: new_version = a_new_version
			version_mismatched: has_version_mismatch
		end

	add_void_safe_mismatch (a_old_attr_type, a_new_attr_type: INTEGER_32; a_old_name, a_new_name: STRING_8; a_old_pos, a_new_pos: INTEGER_32)
			-- Mismatch for a_old_name where the new name is a_new_name, the new type
			-- a_new_attr_type is attached and a_old_attr_type is detachable stored at position
			-- a_old_pos in the stored system for a a_new_pos in the retrieving system.
		require
			a_old_attr_type_non_negative: a_old_attr_type >= 0
			a_new_attr_type_non_negative: a_new_attr_type >= 0
			a_old_name_attached: a_old_name /= Void
			a_new_name_attached: a_new_name /= Void
			a_old_pos_positive: a_old_pos > 0
			a_new_pos_positive: a_new_pos > 0
		local
			l_info: like attribute_info
		do
			l_info := [a_old_name, a_new_name, a_old_attr_type, a_new_attr_type, a_old_pos, a_new_pos, False, False, True];
			mismatches_by_name.put (l_info, a_new_name);
			mismatches_by_stored_position.put (l_info, a_old_pos)
		end
	
feature -- Duplication

	frozen clone (other: detachable ANY): like other
		obsolete "Use `twin' instead. [2017-05-31]"
			-- 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.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.twin
			end
		ensure -- from ANY
			instance_free: class
			equal: Result ~ other
		end

	copy (other: SED_TYPE_MISMATCH)
			-- Update current object using fields of object attached
			-- to other, so as to yield equal objects.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_equal: Current ~ other
		end

	frozen deep_clone (other: detachable ANY): like other
		obsolete "Use `deep_twin' instead. [2017-05-31]"
			-- Void if other is void: otherwise, new object structure
			-- recursively duplicated from the one attached to other
			-- (from ANY)
		do
			if other /= Void then
				Result := other.deep_twin
			end
		ensure -- from ANY
			instance_free: class
			deep_equal: deep_equal (other, Result)
		end

	frozen deep_copy (other: SED_TYPE_MISMATCH)
			-- Effect equivalent to that of:
			--		copy (other . deep_twin)
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		do
			copy (other.deep_twin)
		ensure -- from ANY
			deep_equal: deep_equal (Current, other)
		end

	frozen deep_twin: SED_TYPE_MISMATCH
			-- New object structure recursively duplicated from Current.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			deep_twin_not_void: Result /= Void
			deep_equal: deep_equal (Current, Result)
		end

	frozen standard_clone (other: detachable ANY): like other
		obsolete "Use `standard_twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.standard_twin
			end
		ensure -- from ANY
			instance_free: class
			equal: standard_equal (Result, other)
		end

	frozen standard_copy (other: SED_TYPE_MISMATCH)
			-- Copy every field of other onto corresponding field
			-- of current object.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)
		end

	frozen standard_twin: SED_TYPE_MISMATCH
			-- New object field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			standard_twin_not_void: Result /= Void
			equal: standard_equal (Result, Current)
		end

	frozen twin: SED_TYPE_MISMATCH
			-- New object equal to Current
			-- twin calls copy; to change copying/twinning semantics, redefine copy.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result ~ Current
		end
	
feature -- Basic operations

	frozen as_attached: attached SED_TYPE_MISMATCH
		obsolete "Remove calls to this feature. [2017-05-31]"
			-- Attached version of Current.
			-- (Can be used during transitional period to convert
			-- non-void-safe classes to void-safe ones.)
			-- (from ANY)
		do
			Result := Current
		end

	frozen default: detachable SED_TYPE_MISMATCH
			-- Default value of object's type
			-- (from ANY)
		do
		end

	frozen default_pointer: POINTER
			-- Default value of type POINTER
			-- (Avoid the need to write p.default for
			-- some p of type POINTER.)
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end

	default_rescue
			-- Process exception for routines with no Rescue clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end
	
feature {NONE} -- Implementation

	Internal: REFLECTOR
			-- To query type properties.
		once
			create Result
		end
	
feature -- Output

	Io: STD_FILES
			-- Handle to standard file setup
			-- (from ANY)
		once
			create Result;
			Result.set_output_default
		ensure -- from ANY
			instance_free: class
			io_not_void: Result /= Void
		end

	out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		do
			Result := tagged_out
		ensure -- from ANY
			out_not_void: Result /= Void
		end

	print (o: detachable ANY)
			-- Write terse external representation of o
			-- on standard output.
			-- (from ANY)
		local
			s: READABLE_STRING_8
		do
			if attached o then
				s := o.out
				if attached {READABLE_STRING_32} s as s32 then
					Io.put_string_32 (s32)
				elseif attached {READABLE_STRING_8} s as s8 then
					Io.put_string (s8)
				else
					Io.put_string_32 (s.as_string_32)
				end
			end
		ensure -- from ANY
			instance_free: class
		end

	frozen tagged_out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			tagged_out_not_void: Result /= Void
		end
	
feature -- Platform

	Operating_environment: OPERATING_ENVIRONMENT
			-- Objects available from the operating system
			-- (from ANY)
		once
			create Result
		ensure -- from ANY
			instance_free: class
			operating_environment_not_void: Result /= Void
		end
	
feature {NONE} -- Retrieval

	frozen internal_correct_mismatch
			-- Called from runtime to perform a proper dynamic dispatch on correct_mismatch
			-- from MISMATCH_CORRECTOR.
			-- (from ANY)
		local
			l_msg: STRING_32
			l_exc: EXCEPTIONS
		do
			if attached {MISMATCH_CORRECTOR} Current as l_corrector then
				l_corrector.correct_mismatch
			else
				create l_msg.make_from_string ("Mismatch: ".as_string_32)
				create l_exc;
				l_msg.append (generating_type.name_32);
				l_exc.raise_retrieval_exception (l_msg)
			end
		end
	
invariant
	type_id_non_negative: type_id >= 0
	counts_non_negative: old_count >= 0 and new_count >= 0

		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

note
	library: "EiffelBase: Library of reusable components for Eiffel."
	copyright: "Copyright (c) 1984-2020, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class SED_TYPE_MISMATCH

Generated by ISE EiffelStudio