indexing description: "[ Generates EM_NET_OBJECTs based on their type ID. Object types need to be registered using `add' first. This can only be done through EM_NET_OBJECT_TYPES or a descendant. See EM_NET_OBJECT_TYPES for further details. By default, there is one object factory per instance of a subclass of EM_NET_BASE. You can access this factory through `net_object_factory'. ]" date: "$Date$" revision: "$Revision$" class EM_NET_OBJECT_FACTORY create make feature {NONE} -- Initialization make is -- Create a new object factory. do create type_map.make (20) end feature {EM_NET_OBJECT_TYPES} -- Registration add (a_type_id: INTEGER; creation_function: FUNCTION [ANY, TUPLE[], EM_NET_OBJECT]) is -- Register a `type_id' to an object that is created by a `creation_function'. -- `a_type_id' must not conflict with predefined system IDs. require system_id_valid: not is_initialized implies (a_type_id >= lowest_system_id and a_type_id <= highest_system_id) user_id_valid: is_initialized implies (a_type_id > highest_system_id) type_id_free: not type_map.has (a_type_id) do type_map.force (creation_function, a_type_id) end feature -- Application IDs create_object_by_type_id (a_type_id: INTEGER): EM_NET_OBJECT is -- Create instance of an EM_NET_OBJECT that corresponds to `a_type_id'. require type_exists: has_object_type (a_type_id) local an_agent: FUNCTION[ANY, TUPLE, EM_NET_OBJECT] do an_agent := type_map.item (a_type_id) check creation_procedure_registered: an_agent /= Void end an_agent.call ([]) Result := an_agent.last_result end feature {EM_NET_OBJECT_TYPES} -- Element change mark_initialized is -- Mark the factory as initialized with system objects. do is_initialized := True end feature -- Information has_object_type(a_type_id: INTEGER) : BOOLEAN is -- Do we have a creation agent for a given type id? do Result := type_map.has(a_type_id) end frozen lowest_system_id: INTEGER is 0 -- Lowest type ID of a system object frozen highest_system_id: INTEGER is 99 -- Highest type ID of a system objects is_initialized: BOOLEAN -- Has the factory been initialized with system objects? feature {EM_NET_OBJECT_TYPES} -- Implementation type_map: DS_HASH_TABLE[FUNCTION[ANY, TUPLE, EM_NET_OBJECT], INTEGER] -- Type map invariant type_map_created: type_map /= Void end