note description: "Represent a file. With this, you can read information from a file" author: "Louis Marchand" date: "Thu, 02 Apr 2015 04:11:03 +0000" revision: "2.0" todo: "can_read_16, can_read_32, can_read_64" class GAME_FILE inherit RAW_FILE redefine make_with_name, make_with_path end create make_with_name, make_with_path, make_open_read, make_open_write, make_open_append, make_open_read_write, make_create_read_write, make_open_read_append feature -- Implementation make_with_name (a_name: READABLE_STRING_GENERAL) -- Create file object with fn as file name. do Precursor (a_name) create internal_mutex.make end make_with_path (a_path: PATH) -- Create file object with a_path as path. do Precursor (a_path) create internal_mutex.make end feature -- Access can_read_16: BOOLEAN -- There is another 16 bits in the stream to read. require file_readable: is_readable do Result := count - position > 1 end can_read_32: BOOLEAN -- There is another 16 bits in the stream to read. require file_readable: is_readable do Result := count - position > 3 end can_read_64: BOOLEAN -- There is another 16 bits in the stream to read. require file_readable: is_readable do Result := count - position > 7 end read_natural_16_big_endian -- Read the next 16-bit natural in the file (Reading in Big-Endian order). -- Make the result available in last_natural_16. require file_readable: is_readable can_read: can_read_16 do lock_mutex internal_read_natural_16_big_endian unlock_mutex end read_natural_32_big_endian -- Read the next 32-bit natural in the file (Reading in Big-Endian order). -- Make the result available in last_natural_32. -- Was declared in GAME_FILE as synonym of read_natural_big_endian. require file_readable: is_readable can_read: can_read_32 do lock_mutex internal_read_natural_32_big_endian unlock_mutex end read_natural_big_endian -- Read the next 32-bit natural in the file (Reading in Big-Endian order). -- Make the result available in last_natural_32. -- Was declared in GAME_FILE as synonym of read_natural_32_big_endian. require file_readable: is_readable can_read: can_read_32 do lock_mutex internal_read_natural_32_big_endian unlock_mutex end read_natural_64_big_endian -- Read the next 64-bit natural in the file (Reading in Big-Endian order). -- Make the result available in last_natural_64. require file_readable: is_readable can_read: can_read_64 do lock_mutex internal_read_natural_64_big_endian unlock_mutex end read_natural_16_little_endian -- Read the next 16-bit natural in the file (Reading in Little-Endian order). -- Make the result available in last_natural_16. require file_readable: is_readable can_read: can_read_16 do lock_mutex internal_read_natural_16_little_endian unlock_mutex end read_natural_32_little_endian -- Read the next 32-bit natural in the file (Reading in Little-Endian order). -- Make the result available in last_natural_32. -- Was declared in GAME_FILE as synonym of read_natural_little_endian. require file_readable: is_readable can_read: can_read_32 do lock_mutex internal_read_natural_32_little_endian unlock_mutex end read_natural_little_endian -- Read the next 32-bit natural in the file (Reading in Little-Endian order). -- Make the result available in last_natural_32. -- Was declared in GAME_FILE as synonym of read_natural_32_little_endian. require file_readable: is_readable can_read: can_read_32 do lock_mutex internal_read_natural_32_little_endian unlock_mutex end read_natural_64_little_endian -- Read the next 64-bit natural in the file (Reading in Little-Endian order). -- Make the result available in last_natural_64. require file_readable: is_readable can_read: can_read_64 do lock_mutex internal_read_natural_64_little_endian unlock_mutex end read_real_big_endian -- Read a new real (Reading in Big-Endian order). -- Make result available in last_real. -- Was declared in GAME_FILE as synonym of readreal_big_endian. require file_readable: is_readable can_read: can_read_32 local l_old_natural: NATURAL_32 do lock_mutex l_old_natural := last_natural internal_read_natural_32_big_endian last_real := {SHARED_EXTERNAL}.natural_32_to_real_32 (last_natural_32) last_natural := l_old_natural unlock_mutex end readreal_big_endian -- Read a new real (Reading in Big-Endian order). -- Make result available in last_real. -- Was declared in GAME_FILE as synonym of read_real_big_endian. require file_readable: is_readable can_read: can_read_32 local l_old_natural: NATURAL_32 do lock_mutex l_old_natural := last_natural internal_read_natural_32_big_endian last_real := {SHARED_EXTERNAL}.natural_32_to_real_32 (last_natural_32) last_natural := l_old_natural unlock_mutex end read_double_big_endian -- Read a new double (Reading in Big-Endian order). -- Make result available in last_double. -- Was declared in GAME_FILE as synonym of readdouble_big_endian. require file_readable: is_readable can_read: can_read_64 local l_old_natural_64: NATURAL_64 do lock_mutex l_old_natural_64 := last_natural_64 internal_read_natural_64_big_endian last_double := {SHARED_EXTERNAL}.natural_64_to_real_64 (last_natural_64) last_natural_64 := l_old_natural_64 unlock_mutex end readdouble_big_endian -- Read a new double (Reading in Big-Endian order). -- Make result available in last_double. -- Was declared in GAME_FILE as synonym of read_double_big_endian. require file_readable: is_readable can_read: can_read_64 local l_old_natural_64: NATURAL_64 do lock_mutex l_old_natural_64 := last_natural_64 internal_read_natural_64_big_endian last_double := {SHARED_EXTERNAL}.natural_64_to_real_64 (last_natural_64) last_natural_64 := l_old_natural_64 unlock_mutex end read_real_little_endian -- Read a new real (Reading in Little-Endian order). -- Make result available in last_real. -- Was declared in GAME_FILE as synonym of readreal_little_endian. require file_readable: is_readable can_read: can_read_32 local l_old_natural: NATURAL_32 do lock_mutex l_old_natural := last_natural internal_read_natural_32_little_endian last_real := {SHARED_EXTERNAL}.natural_32_to_real_32 (last_natural_32) last_natural := l_old_natural unlock_mutex end readreal_little_endian -- Read a new real (Reading in Little-Endian order). -- Make result available in last_real. -- Was declared in GAME_FILE as synonym of read_real_little_endian. require file_readable: is_readable can_read: can_read_32 local l_old_natural: NATURAL_32 do lock_mutex l_old_natural := last_natural internal_read_natural_32_little_endian last_real := {SHARED_EXTERNAL}.natural_32_to_real_32 (last_natural_32) last_natural := l_old_natural unlock_mutex end read_double_little_endian -- Read a new double (Reading in Little-Endian order). -- Make result available in last_double. -- Was declared in GAME_FILE as synonym of readdouble_little_endian. require file_readable: is_readable can_read: can_read_64 local l_old_natural_64: NATURAL_64 do lock_mutex l_old_natural_64 := last_natural_64 internal_read_natural_64_little_endian last_double := {SHARED_EXTERNAL}.natural_64_to_real_64 (last_natural_64) last_natural_64 := l_old_natural_64 unlock_mutex end readdouble_little_endian -- Read a new double (Reading in Little-Endian order). -- Make result available in last_double. -- Was declared in GAME_FILE as synonym of read_double_little_endian. require file_readable: is_readable can_read: can_read_64 local l_old_natural_64: NATURAL_64 do lock_mutex l_old_natural_64 := last_natural_64 internal_read_natural_64_little_endian last_double := {SHARED_EXTERNAL}.natural_64_to_real_64 (last_natural_64) last_natural_64 := l_old_natural_64 unlock_mutex end read_integer_16_big_endian -- Read a new 16-bit integer (Reading in Big-Endian order). -- Make result available in last_integer_16. require file_readable: is_readable can_read: can_read_16 local l_old_natural_16: NATURAL_16 do lock_mutex l_old_natural_16 := last_natural_16 internal_read_natural_16_big_endian last_integer_16 := last_natural_16.as_integer_16 last_natural_16 := l_old_natural_16 unlock_mutex end read_integer_32_big_endian -- Read a new 32-bit integer (Reading in Big-Endian order). -- Make result available in last_integer_32. -- Was declared in GAME_FILE as synonym of read_integer_big_endian. require file_readable: is_readable can_read: can_read_32 local l_old_natural: NATURAL_32 do lock_mutex l_old_natural := last_natural internal_read_natural_32_big_endian last_integer := last_natural_32.as_integer_32 last_natural := l_old_natural unlock_mutex end read_integer_big_endian -- Read a new 32-bit integer (Reading in Big-Endian order). -- Make result available in last_integer_32. -- Was declared in GAME_FILE as synonym of read_integer_32_big_endian. require file_readable: is_readable can_read: can_read_32 local l_old_natural: NATURAL_32 do lock_mutex l_old_natural := last_natural internal_read_natural_32_big_endian last_integer := last_natural_32.as_integer_32 last_natural := l_old_natural unlock_mutex end read_integer_64_big_endian -- Read a new 64-bit integer (Reading in Big-Endian order). -- Make result available in last_integer_64. require file_readable: is_readable can_read: can_read_64 local l_old_natural_64: NATURAL_64 do lock_mutex l_old_natural_64 := last_natural_64 internal_read_natural_64_big_endian last_integer_64 := last_natural_64.as_integer_64 last_natural_64 := l_old_natural_64 unlock_mutex end read_integer_16_little_endian -- Read a new 16-bit integer (Reading in Little-Endian order). -- Make result available in last_integer_16. require file_readable: is_readable can_read: can_read_16 local l_old_natural_16: NATURAL_16 do lock_mutex l_old_natural_16 := last_natural_16 internal_read_natural_16_little_endian last_integer_16 := last_natural_16.as_integer_16 last_natural_16 := l_old_natural_16 unlock_mutex end read_integer_32_little_endian -- Read a new 32-bit integer (Reading in Little-Endian order). -- Make result available in last_integer_32. -- Was declared in GAME_FILE as synonym of read_integer_little_endian. require file_readable: is_readable can_read: can_read_32 local l_old_natural: NATURAL_32 do lock_mutex l_old_natural := last_natural internal_read_natural_32_little_endian last_integer := last_natural_32.as_integer_32 last_natural := l_old_natural unlock_mutex end read_integer_little_endian -- Read a new 32-bit integer (Reading in Little-Endian order). -- Make result available in last_integer_32. -- Was declared in GAME_FILE as synonym of read_integer_32_little_endian. require file_readable: is_readable can_read: can_read_32 local l_old_natural: NATURAL_32 do lock_mutex l_old_natural := last_natural internal_read_natural_32_little_endian last_integer := last_natural_32.as_integer_32 last_natural := l_old_natural unlock_mutex end read_integer_64_little_endian -- Read a new 64-bit integer (Reading in Little-Endian order). -- Make result available in last_integer_64. require file_readable: is_readable can_read: can_read_64 local l_old_natural_64: NATURAL_64 do lock_mutex l_old_natural_64 := last_natural_64 internal_read_natural_64_little_endian last_integer_64 := last_natural_64.as_integer_64 last_natural_64 := l_old_natural_64 unlock_mutex end put_natural_16_big_endian (a_value: NATURAL_16) -- Write a_value at current position (Writing in Big-Endian order). require extendible: extendible do lock_mutex internal_put_natural_16_big_endian (a_value) unlock_mutex end put_natural_16_little_endian (a_value: NATURAL_16) -- Write a_value at current position (Writing in Little-Endian order). require extendible: extendible do lock_mutex internal_put_natural_16_little_endian (a_value) unlock_mutex end put_natural_32_big_endian (a_value: NATURAL_32) -- Write a_value at current position (Writing in Big-Endian order). require extendible: extendible do lock_mutex internal_put_natural_32_big_endian (a_value) unlock_mutex end put_natural_32_little_endian (a_value: NATURAL_32) -- Write a_value at current position (Writing in Little-Endian order). require extendible: extendible do lock_mutex internal_put_natural_32_little_endian (a_value) unlock_mutex end put_natural_64_big_endian (a_value: NATURAL_64) -- Write a_value at current position (Writing in Big-Endian order). require extendible: extendible do lock_mutex internal_put_natural_32_big_endian (a_value.bit_shift_right (32).to_natural_32) internal_put_natural_32_big_endian (a_value.bit_and (4294967295).to_natural_32) unlock_mutex end put_natural_64_little_endian (a_value: NATURAL_64) -- Write a_value at current position (Writing in Little-Endian order). require extendible: extendible do lock_mutex internal_put_natural_32_little_endian (a_value.bit_and (4294967295).to_natural_32) internal_put_natural_32_little_endian (a_value.bit_shift_right (32).to_natural_32) unlock_mutex end put_integer_16_big_endian (a_value: INTEGER_16) -- Write a_value at current position (Writing in Big-Endian order). do put_natural_16_big_endian (a_value.as_natural_16) end put_integer_32_big_endian (a_value: INTEGER_32) -- Write a_value at current position (Writing in Big-Endian order). -- Was declared in GAME_FILE as synonym of put_integer_big_endian and putint_big_endian. do put_natural_32_big_endian (a_value.as_natural_32) end put_integer_big_endian (a_value: INTEGER_32) -- Write a_value at current position (Writing in Big-Endian order). -- Was declared in GAME_FILE as synonym of put_integer_32_big_endian and putint_big_endian. do put_natural_32_big_endian (a_value.as_natural_32) end putint_big_endian (a_value: INTEGER_32) -- Write a_value at current position (Writing in Big-Endian order). -- Was declared in GAME_FILE as synonym of put_integer_32_big_endian and put_integer_big_endian. do put_natural_32_big_endian (a_value.as_natural_32) end put_integer_64_big_endian (a_value: INTEGER_64) -- Write a_value at current position (Writing in Big-Endian order). do put_natural_64_big_endian (a_value.as_natural_64) end put_real_big_endian (a_value: REAL_32) -- Write a_value at current position (Writing in Big-Endian order). -- Was declared in GAME_FILE as synonym of putreal_big_endian. do put_natural_32_big_endian ({SHARED_EXTERNAL}.real_32_to_natural_32 (a_value)) end putreal_big_endian (a_value: REAL_32) -- Write a_value at current position (Writing in Big-Endian order). -- Was declared in GAME_FILE as synonym of put_real_big_endian. do put_natural_32_big_endian ({SHARED_EXTERNAL}.real_32_to_natural_32 (a_value)) end put_double_big_endian (a_value: REAL_64) -- Write a_value at current position (Writing in Big-Endian order). -- Was declared in GAME_FILE as synonym of putdouble_big_endian. do put_natural_64_big_endian ({SHARED_EXTERNAL}.real_64_to_natural_64 (a_value)) end putdouble_big_endian (a_value: REAL_64) -- Write a_value at current position (Writing in Big-Endian order). -- Was declared in GAME_FILE as synonym of put_double_big_endian. do put_natural_64_big_endian ({SHARED_EXTERNAL}.real_64_to_natural_64 (a_value)) end put_integer_16_little_endian (a_value: INTEGER_16) -- Write a_value at current position (Writing in little-Endian order). do put_natural_16_little_endian (a_value.as_natural_16) end put_integer_32_little_endian (a_value: INTEGER_32) -- Write a_value at current position (Writing in little-Endian order). -- Was declared in GAME_FILE as synonym of put_integer_little_endian and putint_little_endian. do put_natural_32_little_endian (a_value.as_natural_32) end put_integer_little_endian (a_value: INTEGER_32) -- Write a_value at current position (Writing in little-Endian order). -- Was declared in GAME_FILE as synonym of put_integer_32_little_endian and putint_little_endian. do put_natural_32_little_endian (a_value.as_natural_32) end putint_little_endian (a_value: INTEGER_32) -- Write a_value at current position (Writing in little-Endian order). -- Was declared in GAME_FILE as synonym of put_integer_32_little_endian and put_integer_little_endian. do put_natural_32_little_endian (a_value.as_natural_32) end put_integer_64_little_endian (a_value: INTEGER_64) -- Write a_value at current position (Writing in little-Endian order). do put_natural_64_little_endian (a_value.as_natural_64) end put_real_little_endian (a_value: REAL_32) -- Write a_value at current position (Writing in little-Endian order). -- Was declared in GAME_FILE as synonym of putreal_little_endian. do put_natural_32_little_endian ({SHARED_EXTERNAL}.real_32_to_natural_32 (a_value)) end putreal_little_endian (a_value: REAL_32) -- Write a_value at current position (Writing in little-Endian order). -- Was declared in GAME_FILE as synonym of put_real_little_endian. do put_natural_32_little_endian ({SHARED_EXTERNAL}.real_32_to_natural_32 (a_value)) end put_double_little_endian (a_value: REAL_64) -- Write a_value at current position (Writing in Little-Endian order). -- Was declared in GAME_FILE as synonym of putdouble_little_endian. do put_natural_64_little_endian ({SHARED_EXTERNAL}.real_64_to_natural_64 (a_value)) end putdouble_little_endian (a_value: REAL_64) -- Write a_value at current position (Writing in Little-Endian order). -- Was declared in GAME_FILE as synonym of put_double_little_endian. do put_natural_64_little_endian ({SHARED_EXTERNAL}.real_64_to_natural_64 (a_value)) end feature {GAME_RESSOURCE_MANAGER} -- Access is_thread_safe: BOOLEAN -- Is Current can be used in a multi-threaded system. enable_thread_safe -- Make Current usable in a multi-threaded system. do is_thread_safe := True end disable_thread_safe -- Make Current unusable in a multi-threaded system. do is_thread_safe := True end internal_mutex: MUTEX -- A mutex to sinchronize the file input/output and position lock_mutex -- Lock the internal mutex to prevent multiple access to the package file do if is_thread_safe then internal_mutex.lock end end unlock_mutex -- Unlock the internal mutex do if is_thread_safe then internal_mutex.unlock end end feature {NONE} -- Implementation internal_read_natural_16_big_endian -- Read the next 16-bit natural in the file (Reading in Big-Endian order). -- Make the result available in last_natural_16. require file_readable: is_readable local l_temp: NATURAL_16 l_old_natural_8: NATURAL_8 do l_old_natural_8 := last_natural_8 read_natural_8 l_temp := last_natural_8.to_natural_16.bit_shift_left (8) read_natural_8 last_natural_16 := last_natural_8.to_natural_16.bit_or (l_temp) last_natural_8 := l_old_natural_8 end internal_read_natural_32_big_endian -- Read the next 32-bit natural in the file (Reading in Big-Endian order). -- Make the result available in last_natural_32. require file_readable: is_readable local l_temp: NATURAL_32 l_old_natural_16: NATURAL_16 do l_old_natural_16 := last_natural_16 internal_read_natural_16_big_endian l_temp := last_natural_16.to_natural_32.bit_shift_left (16) internal_read_natural_16_big_endian last_natural := last_natural_16.to_natural_32.bit_or (l_temp) last_natural_16 := l_old_natural_16 end internal_read_natural_64_big_endian -- Read the next 64-bit natural in the file (Reading in Big-Endian order). -- Make the result available in last_natural_64. require file_readable: is_readable local l_temp: NATURAL_64 l_old_natural: NATURAL_32 do l_old_natural := last_natural internal_read_natural_32_big_endian l_temp := last_natural_32.to_natural_64.bit_shift_left (16) internal_read_natural_32_big_endian last_natural_64 := last_natural_32.to_natural_64.bit_or (l_temp) last_natural := l_old_natural end internal_read_natural_16_little_endian -- Read the next 16-bit natural in the file (Reading in Little-Endian order). -- Make the result available in last_natural_16. require file_readable: is_readable local l_temp: NATURAL_16 l_old_natural_8: NATURAL_8 do l_old_natural_8 := last_natural_8 read_natural_8 l_temp := last_natural_8.to_natural_16 read_natural_8 last_natural_16 := l_temp.bit_or (last_natural_8.to_natural_16.bit_shift_left (8)) last_natural_8 := l_old_natural_8 end internal_read_natural_32_little_endian -- Read the next 32-bit natural in the file (Reading in Little-Endian order). -- Make the result available in last_natural_32. require file_readable: is_readable local l_temp: NATURAL_32 l_old_natural_16: NATURAL_16 do l_old_natural_16 := last_natural_16 internal_read_natural_16_little_endian l_temp := last_natural_16.to_natural_32 internal_read_natural_16_little_endian last_natural := l_temp.bit_or (last_natural_16.to_natural_32.bit_shift_left (16)) last_natural_16 := l_old_natural_16 end internal_read_natural_64_little_endian -- Read the next 64-bit natural in the file (Reading in Little-Endian order). -- Make the result available in last_natural_64. require file_readable: is_readable local l_temp: NATURAL_64 l_old_natural: NATURAL_32 do l_old_natural := last_natural internal_read_natural_32_little_endian l_temp := last_natural_32.to_natural_64 internal_read_natural_32_little_endian last_natural_64 := l_temp.bit_or (last_natural_32.to_natural_64.bit_shift_left (16)) last_natural := l_old_natural end internal_put_natural_16_big_endian (a_value: NATURAL_16) -- Write a_value at current position (Writing in Big-Endian order). require extendible: extendible do put_natural_8 (a_value.bit_shift_right (8).to_natural_8) put_natural_8 (a_value.bit_and (255).to_natural_8) end internal_put_natural_16_little_endian (a_value: NATURAL_16) -- Write a_value at current position (Writing in Little-Endian order). require extendible: extendible do put_natural_8 (a_value.bit_and (255).to_natural_8) put_natural_8 (a_value.bit_shift_right (8).to_natural_8) end internal_put_natural_32_big_endian (a_value: NATURAL_32) -- Write a_value at current position (Writing in Big-Endian order). require extendible: extendible do internal_put_natural_16_big_endian (a_value.bit_shift_right (16).to_natural_16) internal_put_natural_16_big_endian (a_value.bit_and (65535).to_natural_16) end internal_put_natural_32_little_endian (a_value: NATURAL_32) -- Write a_value at current position (Writing in Little-Endian order). require extendible: extendible do internal_put_natural_16_little_endian (a_value.bit_and (65535).to_natural_16) internal_put_natural_16_little_endian (a_value.bit_shift_right (16).to_natural_16) end invariant file_ptr_not_null: not (is_closed xor file_pointer.is_default_pointer) end -- class GAME_FILE
Generated by ISE EiffelStudio