image_io_20240725.0.0_e3fcdc57/src/image_io-qoi_holders.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
-- Image I/O: output in PPM, BMP, PNG, and QOI formats; input in BMP, GIF, JPG, PNG, PNM, QOI, and TGA formats
-- Copyright (C) by Pragmada Software Engineering
-- Released under the terms of the BSD 3-Clause license; see https://opensource.org/licenses

with Ada.Finalization;
with Image_IO.QOI;

private package Image_IO.QOI_Holders is
   type Handle is tagged limited private; -- Initially empty

   procedure Create (Holder : in out Handle; Length : in QOI.Storage_Count);
   -- Makes Holder hold a Storage_Array of length Length, default initialized
   -- Any value in Holder is discarded

   function Is_Empty (Holder : in Handle) return Boolean;
   -- Returns True if Create has not been called on Holder; False otherwise

   function Value (Holder : in Handle) return QOI.Storage_Array with
      Pre => not Holder.Is_Empty;
   -- Returns the data held by Holder

   procedure Update (Holder : in Handle; Process : access procedure (Data : in out QOI.Storage_Array) ) with
      Pre => not Holder.Is_Empty;
   -- Calls Process with the data in Holder
private -- Image_IO.QOI_Holders
   type Data_Ptr is access QOI.Storage_Array;

   type Handle is new Ada.Finalization.Limited_Controlled with record
      Ptr : Data_Ptr;
   end record;

   overriding procedure Finalize (Object : in out Handle);

   function Value (Holder : in Handle) return QOI.Storage_Array is
      (Holder.Ptr.all);

   function Is_Empty (Holder : in Handle) return Boolean is
      (Holder.Ptr = null);
end Image_IO.QOI_Holders;