awa_2.4.0_59135a52/ada-asf/src/asf-contexts-exceptions-iterator.adb

 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
-----------------------------------------------------------------------
--  asf-contexts-exceptions-iterator -- Exception handlers in faces context
--  Copyright (C) 2011, 2021, 2022 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with Ada.Unchecked_Deallocation;

--  ------------------------------
--  Iterate over the exception events which are in the queue and execute the given procedure.
--  The procedure should return True in <b>Remove</b> to indicate that the exception has been
--  processed.
--
--  Notes: this procedure should not be called directly (use ASF.Contexts.Faces.Iterate).
--  This procedure is separate to avoid circular dependency.
--  ------------------------------
package body ASF.Contexts.Exceptions.Iterator is

   procedure Iterate
     (Queue   : in out Exception_Queue;
      Context : in out ASF.Contexts.Faces.Faces_Context'Class;
      Process : not null
        access procedure (Event   : in ASF.Events.Exceptions.Exception_Event'Class;
                          Remove  : out Boolean;
                          Context : in out Contexts.Faces.Faces_Context'Class)) is

      procedure Free is
        new Ada.Unchecked_Deallocation (Object => ASF.Events.Exceptions.Exception_Event'Class,
                                        Name   => ASF.Events.Exceptions.Exception_Event_Access);

      Event  : ASF.Events.Exceptions.Exception_Event_Access;
      Remove : Boolean := False;
      Pos    : Natural := 1;
      Len    : Natural := Natural (Queue.Unhandled_Events.Length);
   begin
      while Pos <= Len loop
         Event := Queue.Unhandled_Events.Element (Pos);

         Process (Event.all, Remove, Context);
         if Remove then
            ASF.Events.Exceptions.Event_Vectors.Delete (Queue.Unhandled_Events, Pos);
            Free (Event);
            if Len > 0 then
               Len := Len - 1;
            end if;
         else
            Pos := Pos + 1;
         end if;
      end loop;
   end Iterate;

end ASF.Contexts.Exceptions.Iterator;