sdlada_2.5.20_cd53c280/src/rwops/sdl-rwops.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
--------------------------------------------------------------------------------------------------------------------
--  This source code is subject to the Zlib license, see the LICENCE file in the root of this directory.
--------------------------------------------------------------------------------------------------------------------
--  SDL.RWops
--
--  Read/Write operations, i.e. file related machinery.
--------------------------------------------------------------------------------------------------------------------
with Ada.Strings.UTF_Encoding;
with Interfaces.C;
private with System;

package SDL.RWops is
   pragma Preelaborate;

   package C renames Interfaces.C;
   package UTF_Strings renames Ada.Strings.UTF_Encoding;

   RWops_Error : exception;

   subtype Uint8 is Interfaces.Unsigned_8;
   subtype Uint16 is Interfaces.Unsigned_16;
   subtype Uint32 is Interfaces.Unsigned_32;
   subtype Uint64 is Interfaces.Unsigned_64;

   type RWops is limited private;

   type File_Mode is (Read,
                      Create_To_Write,
                      Append,
                      Read_Write,
                      Create_To_Read_Write,
                      Append_And_Read,
                      Read_Binary,
                      Create_To_Write_Binary,
                      Append_Binary,
                      Read_Write_Binary,
                      Create_To_Read_Write_Binary,
                      Append_And_Read_Binary);

   type Whence_Type is private;

   RW_Seek_Set : constant Whence_Type;  --  Seek from the beginning of data.
   RW_Seek_Cur : constant Whence_Type;  --  Seek relative to current read point.
   RW_Seek_End : constant Whence_Type;  --  Seek relative to the end of data.

   type Offsets is new Interfaces.Integer_64;

   Null_Offset  : constant Offsets :=  0;
   Error_Offset : constant Offsets := -1;

   subtype Sizes is Offsets;

   Error_Or_EOF : constant Sizes := 0;

   function Base_Path return UTF_Strings.UTF_String;

   function Preferences_Path (Organisation : in UTF_Strings.UTF_String;
                              Application  : in UTF_Strings.UTF_String) return UTF_Strings.UTF_String;

   function Seek (Context : in RWops;
                  Offset  : in Offsets;
                  Whence  : in Whence_Type) return Offsets;

   function Size (Context : in RWops) return Offsets;
   function Tell (Context : in RWops) return Offsets;

   function From_File (File_Name : in UTF_Strings.UTF_String;
                       Mode      : in File_Mode) return RWops;

   procedure From_File (File_Name : in UTF_Strings.UTF_String;
                        Mode      : in File_Mode;
                        Ops       : out RWops);

   procedure Close (Ops : in RWops);

   function Read_U_8 (src : in RWops) return Uint8 with
     Import        => True,
     Convention    => C,
     External_Name => "SDL_ReadU8";

   function Read_LE_16 (Src : in RWops) return Uint16 with
     Import        => True,
     Convention    => C,
     External_Name => "SDL_ReadLE16";

   function Read_BE_16 (Src : in RWops) return Uint16 with
     Import        => True,
     Convention    => C,
     External_Name => "SDL_ReadBE16";

   function Read_LE_32 (Src : in RWops) return Uint32 with
     Import        => True,
     Convention    => C,
     External_Name => "SDL_ReadLE32";

   function Read_BE_32 (Src : in RWops) return Uint32 with
     Import        => True,
     Convention    => C,
     External_Name => "SDL_ReadBE32";

   function Read_LE_64 (Src : in RWops) return Uint64 with
     Import        => True,
     Convention    => C,
     External_Name => "SDL_ReadLE64";

   function Read_BE_64 (Src : in RWops) return Uint64 with
     Import        => True,
     Convention    => C,
     External_Name => "SDL_ReadBE64";

   procedure Write_U_8 (Destination : in RWops; Value : in Uint8);
   procedure Write_LE_16 (Destination : in RWops; Value : in Uint16);
   procedure Write_BE_16 (Destination : in RWops; Value : in Uint16);
   procedure Write_LE_32 (Destination : in RWops; Value : in Uint32);
   procedure Write_BE_32 (Destination : in RWops; Value : in Uint32);
   procedure Write_LE_64 (Destination : in RWops; Value : in Uint64);
   procedure Write_BE_64 (Destination : in RWops; Value : in Uint64);

   function Is_Null (Source : in RWops) return Boolean with
     Inline_Always => True;
private
   type Whence_Type is new C.int;

   RW_Seek_Set : constant Whence_Type := 0;
   RW_Seek_Cur : constant Whence_Type := 1;
   RW_Seek_End : constant Whence_Type := 2;

   --  The SDL_RWops struct contains a union which is only used internally by SDL.
   --
   --  The manual states that when a new RWops implementation is written, the Unknown struct within the union can be
   --  used to store data, this consists of two pointers. This is all that is allowed.
   --
   --  TODO: Make it generic passing in two access types of convention C.
   type User_Datums is
      record
         Data_1 : System.Address;
         Data_2 : System.Address;
      end record with
     Convention => C;

   type Stream_Types is new C.unsigned;

   Unknown_Stream : constant Stream_Types := 0;

   type RWops_Pointer;

   type SDL_RWops is
      record
         Size        : access function (Context : in RWops_Pointer) return Offsets;
         Seek        : access function (Context : in RWops_Pointer;
                                        Offset  : in Offsets;
                                        Whence  : in Whence_Type) return Offsets;
         Read        : access function (Context : in RWops_Pointer;
                                        Ptr     : in System.Address;
                                        Size    : in Sizes;
                                        Max_Num : in C.unsigned_long) return C.unsigned_long;
         Write       : access function (Context : in RWops_Pointer;
                                        Ptr     : in System.Address;
                                        Size    : in Sizes;
                                        Num     : in C.unsigned_long) return C.unsigned_long;
         Close       : access function (Context : in RWops_Pointer) return C.int;
         Stream_Type : Stream_Types;  --  When creating a RWops, this should always be set to Unknown_Stream.
         User_Data   : User_Datums;
      end record with
     Convention => C_Pass_By_Copy;

   type RWops_Pointer is access all SDL_RWops with
     Convention => C;

   type RWops is new RWops_Pointer;
end SDL.RWops;