-----------------------------------------------------------------------
--  awa-commands-tests -- Test the AWA.Commands
--  Copyright (C) 2020 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 Util.Tests;
with Ada.Strings.Unbounded;

package AWA.Commands.Tests is

   procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite);

   type Test is new Util.Tests.Test with null record;

   --  Test start and stop command.
   procedure Test_Start_Stop (T : in out Test);

   procedure Test_List_Tables (T : in out Test);

   --  Test the list -u command.
   procedure Test_List_Users (T : in out Test);

   --  Test the list -s command.
   procedure Test_List_Sessions (T : in out Test);

   --  Test the list -j command.
   procedure Test_List_Jobs (T : in out Test);

   procedure Execute (T       : in out Test;
                      Command : in String;
                      Input   : in String;
                      Output  : in String;
                      Result  : out Ada.Strings.Unbounded.Unbounded_String;
                      Status  : in Natural := 0);

end AWA.Commands.Tests;

-----------------------------------------------------------------------
--  awa-commands-tests -- Test the AWA.Commands
--  Copyright (C) 2020 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 Util.Tests;
with Ada.Strings.Unbounded;

package AWA.Commands.Tests is

   procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite);

   type Test is new Util.Tests.Test with null record;

   --  Test start and stop command.
   procedure Test_Start_Stop (T : in out Test);

   procedure Test_List_Tables (T : in out Test);

   --  Test the list -u command.
   procedure Test_List_Users (T : in out Test);

   --  Test the list -s command.
   procedure Test_List_Sessions (T : in out Test);

   --  Test the list -j command.
   procedure Test_List_Jobs (T : in out Test);

   --  Test the command with a secure keystore configuration.
   procedure Test_Secure_Configuration (T : in out Test);

   procedure Execute (T       : in out Test;
                      Command : in String;
                      Input   : in String;
                      Output  : in String;
                      Result  : out Ada.Strings.Unbounded.Unbounded_String;
                      Status  : in Natural := 0);

end AWA.Commands.Tests;

Declare Test_Secure_Configuration procedure to check using secure configuration


-----------------------------------------------------------------------
--  asf-routes -- Request routing
--  Copyright (C) 2015 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;

package body ASF.Routes.Servlets is

   use type ASF.Filters.Filter_Access;
   use type ASF.Filters.Filter_List_Access;

   procedure Free is
     new Ada.Unchecked_Deallocation (Object => ASF.Filters.Filter_List,
                                     Name   => ASF.Filters.Filter_List_Access);

   --  ------------------------------
   --  Get the servlet to call for the route.
   --  ------------------------------
   function Get_Servlet (Route : in Servlet_Route_Type) return ASF.Servlets.Servlet_Access is
   begin
      return Route.Servlet;
   end Get_Servlet;

   --  ------------------------------
   --  Append the filter to the filter list defined by the mapping node.
   --  ------------------------------
   procedure Append_Filter (Route  : in out Servlet_Route_Type;
                            Filter : in ASF.Filters.Filter_Access) is
      List : ASF.Filters.Filter_List_Access;
   begin
      --  Filters are executed through the <b>Filter_Chain.Do_Filter</b> method
      --  starting from the last position to the first.  To append a filter,
      --  it must be inserted as first position of the list.
      if Route.Filters = null then
         List := new ASF.Filters.Filter_List (1 .. 1);
      else
         --  Check that the filter is not already executed.
         for I in Route.Filters'Range loop
            if Route.Filters (I) = Filter then
               return;
            end if;
         end loop;
         List := new ASF.Filters.Filter_List (1 .. Route.Filters'Last + 1);
         List (2 .. List'Last) := Route.Filters.all;
         Free (Route.Filters);
      end if;
      List (List'First) := Filter;
      Route.Filters := List;
   end Append_Filter;

   --  ------------------------------
   --  Release the storage held by the route.
   --  ------------------------------
   overriding
   procedure Finalize (Route : in out Servlet_Route_Type) is
   begin
      Free (Route.Filters);
   end Finalize;

end ASF.Routes.Servlets;

-----------------------------------------------------------------------
--  asf-routes -- Request routing
--  Copyright (C) 2015 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;

package body ASF.Routes.Servlets is

   use type ASF.Filters.Filter_Access;
   use type ASF.Filters.Filter_List_Access;

   procedure Free is
     new Ada.Unchecked_Deallocation (Object => ASF.Filters.Filter_List,
                                     Name   => ASF.Filters.Filter_List_Access);

   --  ------------------------------
   --  Get the servlet to call for the route.
   --  ------------------------------
   function Get_Servlet (Route : in Servlet_Route_Type) return ASF.Servlets.Servlet_Access is
   begin
      return Route.Servlet;
   end Get_Servlet;

   --  ------------------------------
   --  Append the filter to the filter list defined by the mapping node.
   --  ------------------------------
   procedure Append_Filter (Route  : in out Servlet_Route_Type;
                            Filter : in ASF.Filters.Filter_Access) is
      List : ASF.Filters.Filter_List_Access;
   begin
      --  Filters are executed through the <b>Filter_Chain.Do_Filter</b> method
      --  starting from the last position to the first.  To append a filter,
      --  it must be inserted as first position of the list.
      if Route.Filters = null then
         List := new ASF.Filters.Filter_List (1 .. 1);
      else
         --  Check that the filter is not already executed.
         for I in Route.Filters'Range loop
            if Route.Filters (I) = Filter then
               return;
            end if;
         end loop;
         List := new ASF.Filters.Filter_List (1 .. Route.Filters'Last + 1);
         List (2 .. List'Last) := Route.Filters.all;
         Free (Route.Filters);
      end if;
      List (List'First) := Filter;
      Route.Filters := List;
   end Append_Filter;

   --  ------------------------------
   --  Release the storage held by the route.
   --  ------------------------------
   overriding
   procedure Finalize (Route : in out Servlet_Route_Type) is
   begin
      Free (Route.Filters);
   end Finalize;

   --  ------------------------------
   --  Get the servlet to call for the route.
   --  ------------------------------
   overriding
   function Get_Servlet (Route : in Proxy_Route_Type) return ASF.Servlets.Servlet_Access is
   begin
      if Route.Route /= null then
         return Route.Route.Get_Servlet;
      else
         return Route.Servlet;
      end if;
   end Get_Servlet;

end ASF.Routes.Servlets;

Implement the Get_Servlet function for Proxy_Route_Type


-----------------------------------------------------------------------
--  Util.Streams.Files -- File Stream utilities
--  Copyright (C) 2010, 2011, 2012 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.IO_Exceptions;
package body Util.Streams.Texts is

   procedure Initialize (Stream : in out Print_Stream;
                         To     : in Output_Stream_Access) is
   begin
      Stream.Initialize (Output => To, Input => null, Size => 4096);
   end Initialize;

   --  ------------------------------
   --  Write an integer on the stream.
   --  ------------------------------
   procedure Write (Stream : in out Print_Stream;
                    Item   : in Integer) is
      S : constant String := Integer'Image (Item);
   begin
      if Item > 0 then
         Stream.Write (S (S'First + 1 .. S'Last));
      else
         Stream.Write (S);
      end if;
   end Write;

   --  ------------------------------
   --  Write an integer on the stream.
   --  ------------------------------
   procedure Write (Stream : in out Print_Stream;
                    Item   : in Long_Long_Integer) is
      S : constant String := Long_Long_Integer'Image (Item);
   begin
      if Item > 0 then
         Stream.Write (S (S'First + 1 .. S'Last));
      else
         Stream.Write (S);
      end if;
   end Write;

   --  ------------------------------
   --  Write a string on the stream.
   --  ------------------------------
   procedure Write (Stream : in out Print_Stream;
                    Item   : in Ada.Strings.Unbounded.Unbounded_String) is
   begin
      Stream.Write (Ada.Strings.Unbounded.To_String (Item));
   end Write;

   --  ------------------------------
   --  Write a date on the stream.
   --  ------------------------------
   procedure Write (Stream : in out Print_Stream;
                    Item   : in Ada.Calendar.Time;
                    Format : in GNAT.Calendar.Time_IO.Picture_String
                    := GNAT.Calendar.Time_IO.ISO_Date) is
   begin
      Stream.Write (GNAT.Calendar.Time_IO.Image (Item, Format));
   end Write;

   --  ------------------------------
   --  Get the output stream content as a string.
   --  ------------------------------
   function To_String (Stream : in Buffered.Buffered_Stream) return String is
      use Ada.Streams;

      Size   : constant Natural := Stream.Get_Size;
      Buffer : constant Streams.Buffered.Buffer_Access := Stream.Get_Buffer;
      Result : String (1 .. Size);
   begin
      for I in Result'Range loop
         Result (I) := Character'Val (Buffer (Stream_Element_Offset (I)));
      end loop;
      return Result;
   end To_String;

   --  ------------------------------
   --  Initialize the reader to read the input from the input stream given in From.
   --  ------------------------------
   procedure Initialize (Stream : in out Reader_Stream;
                         From   : in Input_Stream_Access) is
   begin
      Stream.Initialize (Output => null, Input => From, Size => 4096);
   end Initialize;

   --  ------------------------------
   --  Read an input line from the input stream.  The line is terminated by ASCII.LF.
   --  When Strip is set, the line terminators (ASCII.CR, ASCII.LF) are removed.
   --  ------------------------------
   procedure Read_Line (Stream : in out Reader_Stream;
                        Into   : out Ada.Strings.Unbounded.Unbounded_String;
                        Strip  : in Boolean := False) is
      C : Character;
   begin
      while not Stream.Is_Eof loop
         Stream.Read (C);
         if C = ASCII.LF then
            if not Strip then
               Ada.Strings.Unbounded.Append (Into, C);
            end if;
            return;
         elsif C /= ASCII.CR or not Strip then
            Ada.Strings.Unbounded.Append (Into, C);
         end if;
      end loop;

   exception
      when Ada.IO_Exceptions.Data_Error =>
         return;
   end Read_Line;

end Util.Streams.Texts;

-----------------------------------------------------------------------
--  Util.Streams.Files -- File Stream utilities
--  Copyright (C) 2010, 2011, 2012, 2016 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.IO_Exceptions;
package body Util.Streams.Texts is

   procedure Initialize (Stream : in out Print_Stream;
                         To     : in Output_Stream_Access) is
   begin
      Stream.Initialize (Output => To, Input => null, Size => 4096);
   end Initialize;

   --  ------------------------------
   --  Write an integer on the stream.
   --  ------------------------------
   procedure Write (Stream : in out Print_Stream;
                    Item   : in Integer) is
      S : constant String := Integer'Image (Item);
   begin
      if Item > 0 then
         Stream.Write (S (S'First + 1 .. S'Last));
      else
         Stream.Write (S);
      end if;
   end Write;

   --  ------------------------------
   --  Write an integer on the stream.
   --  ------------------------------
   procedure Write (Stream : in out Print_Stream;
                    Item   : in Long_Long_Integer) is
      S : constant String := Long_Long_Integer'Image (Item);
   begin
      if Item > 0 then
         Stream.Write (S (S'First + 1 .. S'Last));
      else
         Stream.Write (S);
      end if;
   end Write;

   --  ------------------------------
   --  Write a string on the stream.
   --  ------------------------------
   procedure Write (Stream : in out Print_Stream;
                    Item   : in Ada.Strings.Unbounded.Unbounded_String) is
   begin
      Stream.Write (Ada.Strings.Unbounded.To_String (Item));
   end Write;

   --  ------------------------------
   --  Write a date on the stream.
   --  ------------------------------
   procedure Write (Stream : in out Print_Stream;
                    Item   : in Ada.Calendar.Time;
                    Format : in GNAT.Calendar.Time_IO.Picture_String
                    := GNAT.Calendar.Time_IO.ISO_Date) is
   begin
      Stream.Write (GNAT.Calendar.Time_IO.Image (Item, Format));
   end Write;

   --  ------------------------------
   --  Get the output stream content as a string.
   --  ------------------------------
   function To_String (Stream : in Buffered.Buffered_Stream) return String is
      use Ada.Streams;

      Size   : constant Natural := Stream.Get_Size;
      Buffer : constant Streams.Buffered.Buffer_Access := Stream.Get_Buffer;
      Result : String (1 .. Size);
   begin
      for I in Result'Range loop
         Result (I) := Character'Val (Buffer (Stream_Element_Offset (I)));
      end loop;
      return Result;
   end To_String;

   --  ------------------------------
   --  Write a character on the stream.
   --  ------------------------------
   procedure Write_Char (Stream : in out Buffered.Buffered_Stream'Class;
                         Item   : in Character) is
   begin
      Stream.Write (Item);
   end Write_Char;

   --  ------------------------------
   --  Write a character on the stream.
   --  ------------------------------
   procedure Write_Char (Stream : in out Buffered.Buffered_Stream'Class;
                         Item   : in Wide_Wide_Character) is
   begin
      Stream.Write_Wide (Item);
   end Write_Char;

   --  ------------------------------
   --  Initialize the reader to read the input from the input stream given in From.
   --  ------------------------------
   procedure Initialize (Stream : in out Reader_Stream;
                         From   : in Input_Stream_Access) is
   begin
      Stream.Initialize (Output => null, Input => From, Size => 4096);
   end Initialize;

   --  ------------------------------
   --  Read an input line from the input stream.  The line is terminated by ASCII.LF.
   --  When Strip is set, the line terminators (ASCII.CR, ASCII.LF) are removed.
   --  ------------------------------
   procedure Read_Line (Stream : in out Reader_Stream;
                        Into   : out Ada.Strings.Unbounded.Unbounded_String;
                        Strip  : in Boolean := False) is
      C : Character;
   begin
      while not Stream.Is_Eof loop
         Stream.Read (C);
         if C = ASCII.LF then
            if not Strip then
               Ada.Strings.Unbounded.Append (Into, C);
            end if;
            return;
         elsif C /= ASCII.CR or not Strip then
            Ada.Strings.Unbounded.Append (Into, C);
         end if;
      end loop;

   exception
      when Ada.IO_Exceptions.Data_Error =>
         return;
   end Read_Line;

end Util.Streams.Texts;

Implement the Wide_Char procedures for the TR and WTR packages


-----------------------------------------------------------------------
--  EL.Beans.Tests - Testsuite for EL.Beans
--  Copyright (C) 2011 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 Util.Test_Caller;

with Test_Bean;
with Util.Beans.Objects;
with EL.Contexts.Default;
package body EL.Beans.Tests is

   use Util.Tests;
   use Util.Beans.Objects;
   use Test_Bean;

   package Caller is new Util.Test_Caller (Test);

   procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
   begin
      Caller.Add_Test (Suite, "Test EL.Beans.Add_Parameter",
                       Test_Add_Parameter'Access);
      Caller.Add_Test (Suite, "Test EL.Beans.Initialize",
                       Test_Initialize'Access);
   end Add_Tests;

   --  ------------------------------
   --  Test Add_Parameter
   --  ------------------------------
   procedure Test_Add_Parameter (T : in out Test) is
      P       : Param_Vectors.Vector;
      Context : EL.Contexts.Default.Default_Context;
   begin
      --  Add a constant parameter.
      Add_Parameter (Container => P,
                     Name      => "firstName",
                     Value     => "my name",
                     Context   => Context);
      Assert_Equals (T, 1, Integer (P.Length), "Parameter was not added");
      T.Assert_Equals ("firstName", P.Element (1).Name, "Invalid parameter name");
      T.Assert (P.Element (1).Value.Is_Constant, "Value should be a constant");
      T.Assert_Equals ("my name",
                       Util.Beans.Objects.To_String (P.Element (1).Value.Get_Value (Context)),
                       "Invalid value");

      --  Add an expression parameter.
      Add_Parameter (Container => P,
                     Name      => "lastName",
                     Value     => "#{name}",
                     Context   => Context);
      Assert_Equals (T, 2, Integer (P.Length), "Parameter was not added");
   end Test_Add_Parameter;

   --  ------------------------------
   --  Test the Initialize procedure with a set of expressions
   --  ------------------------------
   procedure Test_Initialize (T : in out Test) is
      P       : Param_Vectors.Vector;
      Context : EL.Contexts.Default.Default_Context;
      User    : Person_Access := Create_Person ("Joe", "Black", 42);
      Bean    : Person_Access := Create_Person ("", "", 0);
   begin
      Context.Set_Variable ("user", User);
      Add_Parameter (P, "firstName", "#{user.firstName}", Context);
      Add_Parameter (P, "lastName", "#{user.lastName}", Context);
      Add_Parameter (P, "age", "#{user.age + 2}", Context);

      Initialize (Bean.all, P, Context);
      T.Assert_Equals ("Joe", Bean.First_Name, "First name not initialized");
      T.Assert_Equals ("Black", Bean.Last_Name, "Last name not initialized");
      Assert_Equals (T, 44, Integer (Bean.Age), "Age was not initialized");
      Free (Bean);
      Free (User);
   end Test_Initialize;

end EL.Beans.Tests;

-----------------------------------------------------------------------
--  EL.Beans.Tests - Testsuite for EL.Beans
--  Copyright (C) 2011 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 Util.Test_Caller;

with Test_Bean;
with Util.Beans.Objects;
with EL.Contexts.Default;
package body EL.Beans.Tests is

   use Util.Tests;
   use Util.Beans.Objects;
   use Test_Bean;

   package Caller is new Util.Test_Caller (Test, "EL.Beans");

   procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is
   begin
      Caller.Add_Test (Suite, "Test EL.Beans.Add_Parameter",
                       Test_Add_Parameter'Access);
      Caller.Add_Test (Suite, "Test EL.Beans.Initialize",
                       Test_Initialize'Access);
   end Add_Tests;

   --  ------------------------------
   --  Test Add_Parameter
   --  ------------------------------
   procedure Test_Add_Parameter (T : in out Test) is
      P       : Param_Vectors.Vector;
      Context : EL.Contexts.Default.Default_Context;
   begin
      --  Add a constant parameter.
      Add_Parameter (Container => P,
                     Name      => "firstName",
                     Value     => "my name",
                     Context   => Context);
      Assert_Equals (T, 1, Integer (P.Length), "Parameter was not added");
      T.Assert_Equals ("firstName", P.Element (1).Name, "Invalid parameter name");
      T.Assert (P.Element (1).Value.Is_Constant, "Value should be a constant");
      T.Assert_Equals ("my name",
                       Util.Beans.Objects.To_String (P.Element (1).Value.Get_Value (Context)),
                       "Invalid value");

      --  Add an expression parameter.
      Add_Parameter (Container => P,
                     Name      => "lastName",
                     Value     => "#{name}",
                     Context   => Context);
      Assert_Equals (T, 2, Integer (P.Length), "Parameter was not added");
   end Test_Add_Parameter;

   --  ------------------------------
   --  Test the Initialize procedure with a set of expressions
   --  ------------------------------
   procedure Test_Initialize (T : in out Test) is
      P       : Param_Vectors.Vector;
      Context : EL.Contexts.Default.Default_Context;
      User    : Person_Access := Create_Person ("Joe", "Black", 42);
      Bean    : Person_Access := Create_Person ("", "", 0);
   begin
      Context.Set_Variable ("user", User);
      Add_Parameter (P, "firstName", "#{user.firstName}", Context);
      Add_Parameter (P, "lastName", "#{user.lastName}", Context);
      Add_Parameter (P, "age", "#{user.age + 2}", Context);

      Initialize (Bean.all, P, Context);
      T.Assert_Equals ("Joe", Bean.First_Name, "First name not initialized");
      T.Assert_Equals ("Black", Bean.Last_Name, "Last name not initialized");
      Assert_Equals (T, 44, Integer (Bean.Age), "Age was not initialized");
      Free (Bean);
      Free (User);
   end Test_Initialize;

end EL.Beans.Tests;

Use the test name EL.Beans

Use the test name EL.Beans


--  Copyright (c) 2012 Felix Krause <contact@flyx.org>
--
--  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.

package GL.Low_Level.Enums is
   pragma Preelaborate;

   -- Unlike GL.Enums, this package is not private and hosts enum types that may
   -- be needed by third-party code or wrappers.

   type Texture_Kind is (Texture_1D, Texture_2D, Texture_3D,
                         Texture_Rectangle, Texture_Cube_Map,
                         Texture_1D_Array, Texture_2D_Array,
                         Texture_Buffer, Texture_Cube_Map_Array,
                         Texture_2D_Multisample, Texture_2D_Multisample_Array);

   type Renderbuffer_Kind is (Renderbuffer);

   type Framebuffer_Kind is (Read, Draw);

   type Transform_Feedback_Kind is (Transform_Feedback);

   type Buffer_Kind is (Array_Buffer, Element_Array_Buffer, Pixel_Pack_Buffer,
                        Pixel_Unpack_Buffer, Uniform_Buffer, Texture_Buffer,
                        Transform_Feedback_Buffer, Copy_Read_Buffer,
                        Copy_Write_Buffer, Draw_Indirect_Buffer,
                        Shader_Storage_Buffer, Dispatch_Indirect_Buffer,
                        Query_Buffer, Atomic_Counter_Buffer);

   type Draw_Buffer_Index is (DB0, DB1, DB2, DB3, DB4, DB5, DB6, DB7,
      DB8, DB9, DB10, DB11, DB12, DB13, DB14, DB15);

   type Only_Depth_Buffer is (Depth_Buffer);
   type Only_Stencil_Buffer is (Stencil);
   type Only_Depth_Stencil_Buffer is (Depth_Stencil);
   type Only_Color_Buffer is (Color);

   type Resource_Type is
     (Int_Type,
      UInt_Type,
      Single_Type,
      Double_Type,
      Single_Vec2,
      Single_Vec3,
      Single_Vec4,
      Int_Vec2,
      Int_Vec3,
      Int_Vec4,
      Bool_Type,
      Bool_Vec2,
      Bool_Vec3,
      Bool_Vec4,
      Single_Matrix2,
      Single_Matrix3,
      Single_Matrix4,
      Sampler_1D,
      Sampler_2D,
      Sampler_3D,
      Sampler_Cube,
      Sampler_1D_Shadow,
      Sampler_2D_Shadow,
      Sampler_2D_Rect,
      Sampler_2D_Rect_Shadow,
      Single_Matrix2x3,
      Single_Matrix2x4,
      Single_Matrix3x2,
      Single_Matrix3x4,
      Single_Matrix4x2,
      Single_Matrix4x3,
      Sampler_1D_Array,
      Sampler_2D_Array,
      Sampler_Buffer,
      Sampler_1D_Array_Shadow,
      Sampler_2D_Array_Shadow,
      Sampler_Cube_Shadow,
      UInt_Vec2,
      UInt_Vec3,
      UInt_Vec4,
      Int_Sampler_1D,
      Int_Sampler_2D,
      Int_Sampler_3D,
      Int_Sampler_Cube,
      Int_Sampler_2D_Rect,
      Int_Sampler_1D_Array,
      Int_Sampler_2D_Array,
      Int_Sampler_Buffer,
      UInt_Sampler_1D,
      UInt_Sampler_2D,
      UInt_Sampler_3D,
      UInt_Sampler_Cube,
      UInt_Sampler_2D_Rect,
      UInt_Sampler_1D_Array,
      UInt_Sampler_2D_Array,
      UInt_Sampler_Buffer,
      Double_Matrix2,
      Double_Matrix3,
      Double_Matrix4,
      Double_Matrix2x3,
      Double_Matrix2x4,
      Double_Matrix3x2,
      Double_Matrix3x4,
      Double_Matrix4x2,
      Double_Matrix4x3,
      Double_Vec2,
      Double_Vec3,
      Double_Vec4,
      Sampler_2D_Multisample,
      Int_Sampler_2D_Multisample,
      UInt_Sampler_2D_Multisample,
      Sampler_2D_Multisample_Array,
      Int_Sampler_2D_Multisample_Array,
      UInt_Sampler_2D_Multisample_Array);

private

   for Texture_Kind use (Texture_1D                   => 16#0DE0#,
                         Texture_2D                   => 16#0DE1#,
                         Texture_3D                   => 16#806F#,
                         Texture_Rectangle            => 16#84F5#,
                         Texture_Cube_Map             => 16#8513#,
                         Texture_1D_Array             => 16#8C18#,
                         Texture_2D_Array             => 16#8C1A#,
                         Texture_Buffer               => 16#8C2A#,
                         Texture_Cube_Map_Array       => 16#9009#,
                         Texture_2D_Multisample       => 16#9100#,
                         Texture_2D_Multisample_Array => 16#9102#);
   for Texture_Kind'Size use Enum'Size;

   for Renderbuffer_Kind use (Renderbuffer => 16#8D41#);
   for Renderbuffer_Kind'Size use Enum'Size;

   for Framebuffer_Kind use (Read      => 16#8CA8#,
                             Draw      => 16#8CA9#);
   for Framebuffer_Kind'Size use Enum'Size;

   for Transform_Feedback_Kind use (Transform_Feedback => 16#8E22#);
   for Transform_Feedback_Kind'Size use Enum'Size;

   for Buffer_Kind use (Array_Buffer              => 16#8892#,
                        Element_Array_Buffer      => 16#8893#,
                        Pixel_Pack_Buffer         => 16#88EB#,
                        Pixel_Unpack_Buffer       => 16#88EC#,
                        Uniform_Buffer            => 16#8A11#,
                        Texture_Buffer            => 16#8C2A#,
                        Transform_Feedback_Buffer => 16#8C8E#,
                        Copy_Read_Buffer          => 16#8F36#,
                        Copy_Write_Buffer         => 16#8F37#,
                        Draw_Indirect_Buffer      => 16#8F3F#,
                        Shader_Storage_Buffer     => 16#90D2#,
                        Dispatch_Indirect_Buffer  => 16#90EE#,
                        Query_Buffer              => 16#9192#,
                        Atomic_Counter_Buffer     => 16#92C0#);
   for Buffer_Kind'Size use Enum'Size;

   for Draw_Buffer_Index use (DB0  => 16#8825#,
                              DB1  => 16#8826#,
                              DB2  => 16#8827#,
                              DB3  => 16#8828#,
                              DB4  => 16#8829#,
                              DB5  => 16#882A#,
                              DB6  => 16#882B#,
                              DB7  => 16#882C#,
                              DB8  => 16#882D#,
                              DB9  => 16#882E#,
                              DB10 => 16#882F#,
                              DB11 => 16#8830#,
                              DB12 => 16#8831#,
                              DB13 => 16#8832#,
                              DB14 => 16#8833#,
                              DB15 => 16#8834#);
   for Draw_Buffer_Index'Size use Int'Size;

   for Only_Depth_Buffer use (Depth_Buffer => 16#1801#);
   for Only_Depth_Buffer'Size use Enum'Size;

   for Only_Stencil_Buffer use (Stencil => 16#1802#);
   for Only_Stencil_Buffer'Size use Enum'Size;

   for Only_Depth_Stencil_Buffer use (Depth_Stencil => 16#84F9#);
   for Only_Depth_Stencil_Buffer'Size use Enum'Size;

   for Only_Color_Buffer use (Color => 16#1800#);
   for Only_Color_Buffer'Size use Enum'Size;

   for Resource_Type use
     (Int_Type                          => 16#1404#,
      UInt_Type                         => 16#1405#,
      Single_Type                       => 16#1406#,
      Double_Type                       => 16#140A#,
      Single_Vec2                       => 16#8B50#,
      Single_Vec3                       => 16#8B51#,
      Single_Vec4                       => 16#8B52#,
      Int_Vec2                          => 16#8B53#,
      Int_Vec3                          => 16#8B54#,
      Int_Vec4                          => 16#8B55#,
      Bool_Type                         => 16#8B56#,
      Bool_Vec2                         => 16#8B57#,
      Bool_Vec3                         => 16#8B58#,
      Bool_Vec4                         => 16#8B59#,
      Single_Matrix2                    => 16#8B5A#,
      Single_Matrix3                    => 16#8B5B#,
      Single_Matrix4                    => 16#8B5C#,
      Sampler_1D                        => 16#8B5D#,
      Sampler_2D                        => 16#8B5E#,
      Sampler_3D                        => 16#8B5F#,
      Sampler_Cube                      => 16#8B60#,
      Sampler_1D_Shadow                 => 16#8B61#,
      Sampler_2D_Shadow                 => 16#8B62#,
      Sampler_2D_Rect                   => 16#8B63#,
      Sampler_2D_Rect_Shadow            => 16#8B64#,
      Single_Matrix2x3                  => 16#8B65#,
      Single_Matrix2x4                  => 16#8B66#,
      Single_Matrix3x2                  => 16#8B67#,
      Single_Matrix3x4                  => 16#8B68#,
      Single_Matrix4x2                  => 16#8B69#,
      Single_Matrix4x3                  => 16#8B6A#,
      Sampler_1D_Array                  => 16#8DC0#,
      Sampler_2D_Array                  => 16#8DC1#,
      Sampler_Buffer                    => 16#8DC2#,
      Sampler_1D_Array_Shadow           => 16#8DC3#,
      Sampler_2D_Array_Shadow           => 16#8DC4#,
      Sampler_Cube_Shadow               => 16#8DC5#,
      UInt_Vec2                         => 16#8DC6#,
      UInt_Vec3                         => 16#8DC7#,
      UInt_Vec4                         => 16#8DC8#,
      Int_Sampler_1D                    => 16#8DC9#,
      Int_Sampler_2D                    => 16#8DCA#,
      Int_Sampler_3D                    => 16#8DCB#,
      Int_Sampler_Cube                  => 16#8DCC#,
      Int_Sampler_2D_Rect               => 16#8DCD#,
      Int_Sampler_1D_Array              => 16#8DCE#,
      Int_Sampler_2D_Array              => 16#8DCF#,
      Int_Sampler_Buffer                => 16#8DD0#,
      UInt_Sampler_1D                   => 16#8DD1#,
      UInt_Sampler_2D                   => 16#8DD2#,
      UInt_Sampler_3D                   => 16#8DD3#,
      UInt_Sampler_Cube                 => 16#8DD4#,
      UInt_Sampler_2D_Rect              => 16#8DD5#,
      UInt_Sampler_1D_Array             => 16#8DD6#,
      UInt_Sampler_2D_Array             => 16#8DD7#,
      UInt_Sampler_Buffer               => 16#8DD8#,
      Double_Matrix2                    => 16#8F46#,
      Double_Matrix3                    => 16#8F47#,
      Double_Matrix4                    => 16#8F48#,
      Double_Matrix2x3                  => 16#8F49#,
      Double_Matrix2x4                  => 16#8F4A#,
      Double_Matrix3x2                  => 16#8F4B#,
      Double_Matrix3x4                  => 16#8F4C#,
      Double_Matrix4x2                  => 16#8F4D#,
      Double_Matrix4x3                  => 16#8F4E#,
      Double_Vec2                       => 16#8FFC#,
      Double_Vec3                       => 16#8FFD#,
      Double_Vec4                       => 16#8FFE#,
      Sampler_2D_Multisample            => 16#9108#,
      Int_Sampler_2D_Multisample        => 16#9109#,
      UInt_Sampler_2D_Multisample       => 16#910A#,
      Sampler_2D_Multisample_Array      => 16#910B#,
      Int_Sampler_2D_Multisample_Array  => 16#910C#,
      UInt_Sampler_2D_Multisample_Array => 16#910D#);
   for Resource_Type'Size use Enum'Size;

end GL.Low_Level.Enums;

--  Copyright (c) 2012 Felix Krause <contact@flyx.org>
--
--  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.

package GL.Low_Level.Enums is
   pragma Preelaborate;

   -- Unlike GL.Enums, this package is not private and hosts enum types that may
   -- be needed by third-party code or wrappers.

   type Texture_Kind is (Texture_1D, Texture_2D, Texture_3D,
                         Texture_Rectangle, Texture_Cube_Map,
                         Texture_1D_Array, Texture_2D_Array,
                         Texture_Buffer, Texture_Cube_Map_Array,
                         Texture_2D_Multisample, Texture_2D_Multisample_Array);

   type Renderbuffer_Kind is (Renderbuffer);

   type Framebuffer_Kind is (Read, Draw);

   type Transform_Feedback_Kind is (Transform_Feedback);

   type Buffer_Kind is (Array_Buffer, Element_Array_Buffer, Pixel_Pack_Buffer,
                        Pixel_Unpack_Buffer, Uniform_Buffer, Texture_Buffer,
                        Transform_Feedback_Buffer, Copy_Read_Buffer,
                        Copy_Write_Buffer, Draw_Indirect_Buffer,
                        Shader_Storage_Buffer, Dispatch_Indirect_Buffer,
                        Query_Buffer, Atomic_Counter_Buffer);

   type Draw_Buffer_Index is (DB0, DB1, DB2, DB3, DB4, DB5, DB6, DB7,
      DB8, DB9, DB10, DB11, DB12, DB13, DB14, DB15);

   type Only_Depth_Buffer is (Depth_Buffer);
   type Only_Stencil_Buffer is (Stencil);
   type Only_Depth_Stencil_Buffer is (Depth_Stencil);
   type Only_Color_Buffer is (Color);

   type Resource_Type is
     (Int_Type,
      UInt_Type,
      Single_Type,
      Double_Type,
      Single_Vec2,
      Single_Vec3,
      Single_Vec4,
      Int_Vec2,
      Int_Vec3,
      Int_Vec4,
      Bool_Type,
      Bool_Vec2,
      Bool_Vec3,
      Bool_Vec4,
      Single_Matrix2,
      Single_Matrix3,
      Single_Matrix4,
      Sampler_1D,
      Sampler_2D,
      Sampler_3D,
      Sampler_Cube,
      Sampler_1D_Shadow,
      Sampler_2D_Shadow,
      Sampler_2D_Rect,
      Sampler_2D_Rect_Shadow,
      Single_Matrix2x3,
      Single_Matrix2x4,
      Single_Matrix3x2,
      Single_Matrix3x4,
      Single_Matrix4x2,
      Single_Matrix4x3,
      Sampler_1D_Array,
      Sampler_2D_Array,
      Sampler_Buffer,
      Sampler_1D_Array_Shadow,
      Sampler_2D_Array_Shadow,
      Sampler_Cube_Shadow,
      UInt_Vec2,
      UInt_Vec3,
      UInt_Vec4,
      Int_Sampler_1D,
      Int_Sampler_2D,
      Int_Sampler_3D,
      Int_Sampler_Cube,
      Int_Sampler_2D_Rect,
      Int_Sampler_1D_Array,
      Int_Sampler_2D_Array,
      Int_Sampler_Buffer,
      UInt_Sampler_1D,
      UInt_Sampler_2D,
      UInt_Sampler_3D,
      UInt_Sampler_Cube,
      UInt_Sampler_2D_Rect,
      UInt_Sampler_1D_Array,
      UInt_Sampler_2D_Array,
      UInt_Sampler_Buffer,
      Double_Matrix2,
      Double_Matrix3,
      Double_Matrix4,
      Double_Matrix2x3,
      Double_Matrix2x4,
      Double_Matrix3x2,
      Double_Matrix3x4,
      Double_Matrix4x2,
      Double_Matrix4x3,
      Double_Vec2,
      Double_Vec3,
      Double_Vec4,
      Sampler_Cube_Array,
      Sampler_Cube_Array_Shadow,
      Int_Sampler_Cube_Array,
      UInt_Sampler_Cube_Array,
      Sampler_2D_Multisample,
      Int_Sampler_2D_Multisample,
      UInt_Sampler_2D_Multisample,
      Sampler_2D_Multisample_Array,
      Int_Sampler_2D_Multisample_Array,
      UInt_Sampler_2D_Multisample_Array);

private

   for Texture_Kind use (Texture_1D                   => 16#0DE0#,
                         Texture_2D                   => 16#0DE1#,
                         Texture_3D                   => 16#806F#,
                         Texture_Rectangle            => 16#84F5#,
                         Texture_Cube_Map             => 16#8513#,
                         Texture_1D_Array             => 16#8C18#,
                         Texture_2D_Array             => 16#8C1A#,
                         Texture_Buffer               => 16#8C2A#,
                         Texture_Cube_Map_Array       => 16#9009#,
                         Texture_2D_Multisample       => 16#9100#,
                         Texture_2D_Multisample_Array => 16#9102#);
   for Texture_Kind'Size use Enum'Size;

   for Renderbuffer_Kind use (Renderbuffer => 16#8D41#);
   for Renderbuffer_Kind'Size use Enum'Size;

   for Framebuffer_Kind use (Read      => 16#8CA8#,
                             Draw      => 16#8CA9#);
   for Framebuffer_Kind'Size use Enum'Size;

   for Transform_Feedback_Kind use (Transform_Feedback => 16#8E22#);
   for Transform_Feedback_Kind'Size use Enum'Size;

   for Buffer_Kind use (Array_Buffer              => 16#8892#,
                        Element_Array_Buffer      => 16#8893#,
                        Pixel_Pack_Buffer         => 16#88EB#,
                        Pixel_Unpack_Buffer       => 16#88EC#,
                        Uniform_Buffer            => 16#8A11#,
                        Texture_Buffer            => 16#8C2A#,
                        Transform_Feedback_Buffer => 16#8C8E#,
                        Copy_Read_Buffer          => 16#8F36#,
                        Copy_Write_Buffer         => 16#8F37#,
                        Draw_Indirect_Buffer      => 16#8F3F#,
                        Shader_Storage_Buffer     => 16#90D2#,
                        Dispatch_Indirect_Buffer  => 16#90EE#,
                        Query_Buffer              => 16#9192#,
                        Atomic_Counter_Buffer     => 16#92C0#);
   for Buffer_Kind'Size use Enum'Size;

   for Draw_Buffer_Index use (DB0  => 16#8825#,
                              DB1  => 16#8826#,
                              DB2  => 16#8827#,
                              DB3  => 16#8828#,
                              DB4  => 16#8829#,
                              DB5  => 16#882A#,
                              DB6  => 16#882B#,
                              DB7  => 16#882C#,
                              DB8  => 16#882D#,
                              DB9  => 16#882E#,
                              DB10 => 16#882F#,
                              DB11 => 16#8830#,
                              DB12 => 16#8831#,
                              DB13 => 16#8832#,
                              DB14 => 16#8833#,
                              DB15 => 16#8834#);
   for Draw_Buffer_Index'Size use Int'Size;

   for Only_Depth_Buffer use (Depth_Buffer => 16#1801#);
   for Only_Depth_Buffer'Size use Enum'Size;

   for Only_Stencil_Buffer use (Stencil => 16#1802#);
   for Only_Stencil_Buffer'Size use Enum'Size;

   for Only_Depth_Stencil_Buffer use (Depth_Stencil => 16#84F9#);
   for Only_Depth_Stencil_Buffer'Size use Enum'Size;

   for Only_Color_Buffer use (Color => 16#1800#);
   for Only_Color_Buffer'Size use Enum'Size;

   for Resource_Type use
     (Int_Type                          => 16#1404#,
      UInt_Type                         => 16#1405#,
      Single_Type                       => 16#1406#,
      Double_Type                       => 16#140A#,
      Single_Vec2                       => 16#8B50#,
      Single_Vec3                       => 16#8B51#,
      Single_Vec4                       => 16#8B52#,
      Int_Vec2                          => 16#8B53#,
      Int_Vec3                          => 16#8B54#,
      Int_Vec4                          => 16#8B55#,
      Bool_Type                         => 16#8B56#,
      Bool_Vec2                         => 16#8B57#,
      Bool_Vec3                         => 16#8B58#,
      Bool_Vec4                         => 16#8B59#,
      Single_Matrix2                    => 16#8B5A#,
      Single_Matrix3                    => 16#8B5B#,
      Single_Matrix4                    => 16#8B5C#,
      Sampler_1D                        => 16#8B5D#,
      Sampler_2D                        => 16#8B5E#,
      Sampler_3D                        => 16#8B5F#,
      Sampler_Cube                      => 16#8B60#,
      Sampler_1D_Shadow                 => 16#8B61#,
      Sampler_2D_Shadow                 => 16#8B62#,
      Sampler_2D_Rect                   => 16#8B63#,
      Sampler_2D_Rect_Shadow            => 16#8B64#,
      Single_Matrix2x3                  => 16#8B65#,
      Single_Matrix2x4                  => 16#8B66#,
      Single_Matrix3x2                  => 16#8B67#,
      Single_Matrix3x4                  => 16#8B68#,
      Single_Matrix4x2                  => 16#8B69#,
      Single_Matrix4x3                  => 16#8B6A#,
      Sampler_1D_Array                  => 16#8DC0#,
      Sampler_2D_Array                  => 16#8DC1#,
      Sampler_Buffer                    => 16#8DC2#,
      Sampler_1D_Array_Shadow           => 16#8DC3#,
      Sampler_2D_Array_Shadow           => 16#8DC4#,
      Sampler_Cube_Shadow               => 16#8DC5#,
      UInt_Vec2                         => 16#8DC6#,
      UInt_Vec3                         => 16#8DC7#,
      UInt_Vec4                         => 16#8DC8#,
      Int_Sampler_1D                    => 16#8DC9#,
      Int_Sampler_2D                    => 16#8DCA#,
      Int_Sampler_3D                    => 16#8DCB#,
      Int_Sampler_Cube                  => 16#8DCC#,
      Int_Sampler_2D_Rect               => 16#8DCD#,
      Int_Sampler_1D_Array              => 16#8DCE#,
      Int_Sampler_2D_Array              => 16#8DCF#,
      Int_Sampler_Buffer                => 16#8DD0#,
      UInt_Sampler_1D                   => 16#8DD1#,
      UInt_Sampler_2D                   => 16#8DD2#,
      UInt_Sampler_3D                   => 16#8DD3#,
      UInt_Sampler_Cube                 => 16#8DD4#,
      UInt_Sampler_2D_Rect              => 16#8DD5#,
      UInt_Sampler_1D_Array             => 16#8DD6#,
      UInt_Sampler_2D_Array             => 16#8DD7#,
      UInt_Sampler_Buffer               => 16#8DD8#,
      Double_Matrix2                    => 16#8F46#,
      Double_Matrix3                    => 16#8F47#,
      Double_Matrix4                    => 16#8F48#,
      Double_Matrix2x3                  => 16#8F49#,
      Double_Matrix2x4                  => 16#8F4A#,
      Double_Matrix3x2                  => 16#8F4B#,
      Double_Matrix3x4                  => 16#8F4C#,
      Double_Matrix4x2                  => 16#8F4D#,
      Double_Matrix4x3                  => 16#8F4E#,
      Double_Vec2                       => 16#8FFC#,
      Double_Vec3                       => 16#8FFD#,
      Double_Vec4                       => 16#8FFE#,
      Sampler_Cube_Array                => 16#900C#,
      Sampler_Cube_Array_Shadow         => 16#900D#,
      Int_Sampler_Cube_Array            => 16#900E#,
      UInt_Sampler_Cube_Array           => 16#900F#,
      Sampler_2D_Multisample            => 16#9108#,
      Int_Sampler_2D_Multisample        => 16#9109#,
      UInt_Sampler_2D_Multisample       => 16#910A#,
      Sampler_2D_Multisample_Array      => 16#910B#,
      Int_Sampler_2D_Multisample_Array  => 16#910C#,
      UInt_Sampler_2D_Multisample_Array => 16#910D#);
   for Resource_Type'Size use Enum'Size;

end GL.Low_Level.Enums;

Add support for cube map array textures

gl: Add support for cube map array textures

 * Extension ARB_texture_cube_map_array (OpenGL 4.0)

Signed-off-by: onox <34c1d3d2d1347bea60a26f46574de21a7a79b6d5@gmail.com>


-----------------------------------------------------------------------
--  Util.Beans.Objects.Datasets -- Datasets
--  Copyright (C) 2013, 2018 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.Strings.Hash;
with Ada.Finalization;
with Ada.Containers.Indefinite_Hashed_Maps;

with Util.Beans.Basic;

--  == Datasets ==
--  The `Datasets` package implements the `Dataset` list bean which
--  defines a set of objects organized in rows and columns.  The `Dataset`
--  implements the `List_Bean` interface and allows to iterate over its rows.
--  Each row defines a `Bean` instance and allows to access each column value.
--  Each column is associated with a unique name.  The row `Bean` allows to
--  get or set the column by using the column name.
package Util.Beans.Objects.Datasets is

   Invalid_State : exception;

   --  An array of objects.
   type Object_Array is array (Positive range <>) of Object;

   type Dataset is new Util.Beans.Basic.List_Bean with private;

   --  Get the number of elements in the list.
   overriding
   function Get_Count (From : in Dataset) return Natural;

   --  Set the current row index.  Valid row indexes start at 1.
   overriding
   procedure Set_Row_Index (From  : in out Dataset;
                            Index : in Natural);

   --  Get the element at the current row index.
   overriding
   function Get_Row (From  : in Dataset) return Util.Beans.Objects.Object;

   --  Get the value identified by the name.
   --  If the name cannot be found, the method should return the Null object.
   overriding
   function Get_Value (From : in Dataset;
                       Name : in String) return Util.Beans.Objects.Object;

   --  Append a row in the dataset and call the fill procedure to populate
   --  the row content.
   procedure Append (Into : in out Dataset;
                     Fill : not null access procedure (Data : in out Object_Array));

   --  Add a column to the dataset.  If the position is not specified,
   --  the column count is incremented and the name associated with the last column.
   --  Raises Invalid_State exception if the dataset contains some rows,
   procedure Add_Column (Into : in out Dataset;
                         Name : in String;
                         Pos  : in Natural := 0);

   --  Clear the content of the dataset.
   procedure Clear (Set : in out Dataset);

private

   type Object_Array_Access is access all Object_Array;

   type Dataset_Array is array (Positive range <>) of Object_Array_Access;
   type Dataset_Array_Access is access all Dataset_Array;

   package Dataset_Map is
      new Ada.Containers.Indefinite_Hashed_Maps (Key_Type        => String,
                                                 Element_Type    => Positive,
                                                 Hash            => Ada.Strings.Hash,
                                                 Equivalent_Keys => "=",
                                                 "="             => "=");

   type Row is new Util.Beans.Basic.Bean with record
      Data : Object_Array_Access;
      Map  : access Dataset_Map.Map;
   end record;

   --  Get the value identified by the name.
   --  If the name cannot be found, the method should return the Null object.
   overriding
   function Get_Value (From : in Row;
                       Name : in String) return Util.Beans.Objects.Object;

   --  Set the value identified by the name.
   --  If the name cannot be found, the method should raise the No_Value
   --  exception.
   overriding
   procedure Set_Value (From  : in out Row;
                        Name  : in String;
                        Value : in Util.Beans.Objects.Object);

   type Dataset is new Ada.Finalization.Controlled and Util.Beans.Basic.List_Bean with record
      Data        : Dataset_Array_Access;
      Count       : Natural := 0;
      Columns     : Natural := 0;
      Map         : aliased Dataset_Map.Map;
      Current     : aliased Row;
      Current_Pos : Natural := 0;
      Row         : Util.Beans.Objects.Object;
   end record;

   --  Initialize the dataset and the row bean instance.
   overriding
   procedure Initialize (Set : in out Dataset);

   --  Release the dataset storage.
   overriding
   procedure Finalize (Set : in out Dataset);

end Util.Beans.Objects.Datasets;

-----------------------------------------------------------------------
--  util-beans-objects-datasets -- Datasets
--  Copyright (C) 2013, 2018, 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.Strings.Hash;
with Ada.Finalization;
with Ada.Containers.Indefinite_Hashed_Maps;

with Util.Beans.Basic;
with Util.Beans.Objects.Iterators;

--  == Datasets ==
--  The `Datasets` package implements the `Dataset` list bean which
--  defines a set of objects organized in rows and columns.  The `Dataset`
--  implements the `List_Bean` interface and allows to iterate over its rows.
--  Each row defines a `Bean` instance and allows to access each column value.
--  Each column is associated with a unique name.  The row `Bean` allows to
--  get or set the column by using the column name.
--
--     with Util.Beans.Objects.Datasets;
--     ...
--        Set : Util.Beans.Objects.Datasets.Dataset_Access
--            := new Util.Beans.Objects.Datasets.Dataset;
--
--  After creation of the dataset instance, the first step is to define
--  the columns that composed the list.  This is done by using the `Add_Column`
--  procedure:
--
--     Set.Add_Column ("name");
--     Set.Add_Column ("email");
--     Set.Add_Column ("age");
--
--  To populate the dataset, the package only provide the `Append` procedure
--  which adds a new row and calls a procedure whose job is to fill the columns
--  of the new row.  The procedure gets the row as an array of `Object`:
--
--     procedure Fill (Row : in out Util.Beans.Objects.Object_Array) is
--     begin
--        Row (Row'First) := To_Object (String '("Yoda"));
--        Row (Row'First + 1) := To_Object (String '("Yoda@Dagobah"));
--        Row (Row'First + 2) := To_Object (Integer (900));
--     end Fill;
--
--     Set.Append (Fill'Access);
--
--  The dataset instance is converted to an `Object` by using the `To_Object`
--  function.  Note that the default behavior of `To_Object` is to take
--  the ownershiup of the object and hence it will be released automatically.
--
--     List : Util.Beans.Objects.Object
--        := Util.Beans.Objects.To_Object (Set);
--
package Util.Beans.Objects.Datasets is

   subtype Iterator_Bean is Util.Beans.Objects.Iterators.Iterator_Bean;

   Invalid_State : exception;

   type Dataset is new Util.Beans.Basic.List_Bean and Iterator_Bean with private;
   type Dataset_Access is access all Dataset'Class;

   --  Get the number of elements in the list.
   overriding
   function Get_Count (From : in Dataset) return Natural;

   --  Set the current row index.  Valid row indexes start at 1.
   overriding
   procedure Set_Row_Index (From  : in out Dataset;
                            Index : in Natural);

   --  Get the element at the current row index.
   overriding
   function Get_Row (From  : in Dataset) return Util.Beans.Objects.Object;

   --  Get the value identified by the name.
   --  If the name cannot be found, the method should return the Null object.
   overriding
   function Get_Value (From : in Dataset;
                       Name : in String) return Util.Beans.Objects.Object;

   --  Get an iterator to iterate starting with the first element.
   overriding
   function First (From : in Dataset) return Iterators.Proxy_Iterator_Access;

   --  Get an iterator to iterate starting with the last element.
   overriding
   function Last (From : in Dataset) return Iterators.Proxy_Iterator_Access;

   --  Append a row in the dataset and call the fill procedure to populate
   --  the row content.
   procedure Append (Into : in out Dataset;
                     Fill : not null access procedure (Data : in out Object_Array));

   --  Add a column to the dataset.  If the position is not specified,
   --  the column count is incremented and the name associated with the last column.
   --  Raises Invalid_State exception if the dataset contains some rows,
   procedure Add_Column (Into : in out Dataset;
                         Name : in String;
                         Pos  : in Natural := 0);

   --  Clear the content of the dataset.
   procedure Clear (Set : in out Dataset);

private

   type Object_Array_Access is access all Object_Array;

   type Dataset_Array is array (Positive range <>) of Object_Array_Access;
   type Dataset_Array_Access is access all Dataset_Array;

   package Dataset_Map is
      new Ada.Containers.Indefinite_Hashed_Maps (Key_Type        => String,
                                                 Element_Type    => Positive,
                                                 Hash            => Ada.Strings.Hash,
                                                 Equivalent_Keys => "=",
                                                 "="             => "=");

   type Row is new Util.Beans.Basic.Bean and Iterator_Bean with record
      Data : Object_Array_Access;
      Map  : access Dataset_Map.Map;
   end record;

   --  Get the value identified by the name.
   --  If the name cannot be found, the method should return the Null object.
   overriding
   function Get_Value (From : in Row;
                       Name : in String) return Util.Beans.Objects.Object;

   --  Set the value identified by the name.
   --  If the name cannot be found, the method should raise the No_Value
   --  exception.
   overriding
   procedure Set_Value (From  : in out Row;
                        Name  : in String;
                        Value : in Util.Beans.Objects.Object);

   --  Get an iterator to iterate starting with the first element.
   overriding
   function First (From : in Row) return Iterators.Proxy_Iterator_Access;

   --  Get an iterator to iterate starting with the last element.
   overriding
   function Last (From : in Row) return Iterators.Proxy_Iterator_Access;

   type Dataset is new Ada.Finalization.Controlled
     and Util.Beans.Basic.List_Bean and Iterator_Bean with record
      Data        : Dataset_Array_Access;
      Count       : Natural := 0;
      Columns     : Natural := 0;
      Map         : aliased Dataset_Map.Map;
      Current     : aliased Row;
      Current_Pos : Natural := 0;
      Row         : Util.Beans.Objects.Object;
   end record;

   --  Initialize the dataset and the row bean instance.
   overriding
   procedure Initialize (Set : in out Dataset);

   --  Release the dataset storage.
   overriding
   procedure Finalize (Set : in out Dataset);

   type Dataset_Iterator is new Iterators.Proxy_Iterator with record
      Current     : aliased Row;
      Current_Pos : Natural := 0;
      Row         : Util.Beans.Objects.Object;
   end record;
   type Dataset_Iterator_Access is access all Dataset_Iterator;

   overriding
   procedure Initialize (Iter : in out Dataset_Iterator);

   overriding
   function Has_Element (Iter : in Dataset_Iterator) return Boolean;

   overriding
   procedure Next (Iter : in out Dataset_Iterator);

   overriding
   procedure Previous (Iter : in out Dataset_Iterator);

   overriding
   function Element (Iter : in Dataset_Iterator) return Object;

   type Row_Iterator is new Iterators.Proxy_Map_Iterator with record
      Pos  : Dataset_Map.Cursor;
      Data : Object_Array_Access;
   end record;
   type Row_Iterator_Access is access all Row_Iterator;

   overriding
   procedure Initialize (Iter : in out Row_Iterator);

   overriding
   function Has_Element (Iter : in Row_Iterator) return Boolean;

   overriding
   procedure Next (Iter : in out Row_Iterator);

   overriding
   procedure Previous (Iter : in out Row_Iterator);

   overriding
   function Element (Iter : in Row_Iterator) return Object;

   overriding
   function Key (Iter : in Row_Iterator) return String;

end Util.Beans.Objects.Datasets;

Add some documentation Implement the Iterator_Bean interface to allow iterating over the dataset and its columns


-----------------------------------------------------------------------
--  security-auth-oauth -- OAuth based authentication
--  Copyright (C) 2013 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 Util.Log.Loggers;
with Security.OAuth.Clients;
package body Security.Auth.OAuth is

   Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Security.Auth.OAuth");

   --  ------------------------------
   --  OAuth Manager
   --  ------------------------------
   --  The Manager provides the core operations for the OAuth authorization process.

   --  ------------------------------
   --  Initialize the authentication realm.
   --  ------------------------------
   overriding
   procedure Initialize (Realm     : in out Manager;
                         Params    : in Parameters'Class;
                         Provider  : in String := PROVIDER_OPENID) is
   begin
      Realm.App.Set_Application_Identifier (Params.Get_Parameter (Provider & ".client_id"));
      Realm.App.Set_Application_Secret (Params.Get_Parameter (Provider & ".secret"));
      Realm.App.Set_Application_Callback (Params.Get_Parameter (Provider & ".callback_url"));
      Realm.App.Set_Provider_URI (Params.Get_Parameter (Provider & ".request_url"));
      Realm.Realm := To_Unbounded_String (Params.Get_Parameter (Provider & ".realm"));
      Realm.Scope := To_Unbounded_String (Params.Get_Parameter (Provider & ".scope"));
   end Initialize;

   --  ------------------------------
   --  Discover the OpenID provider that must be used to authenticate the user.
   --  The Name can be an URL or an alias that identifies the provider.
   --  A cached OpenID provider can be returned.
   --  Read the XRDS document from the URI and initialize the OpenID provider end point.
   --  (See OpenID Section 7.3 Discovery)
   --  ------------------------------
   overriding
   procedure Discover (Realm  : in out Manager;
                       Name   : in String;
                       Result : out End_Point) is
   begin
      Result.URL := To_Unbounded_String (Name);
   end Discover;

   --  ------------------------------
   --  Associate the application (relying party) with the OpenID provider.
   --  The association can be cached.
   --  (See OpenID Section 8 Establishing Associations)
   --  ------------------------------
   overriding
   procedure Associate (Realm  : in out Manager;
                        OP     : in End_Point;
                        Result : out Association) is
   begin
      Result.Assoc_Handle := To_Unbounded_String ("nonce-generator");
   end Associate;

   --  ------------------------------
   --  Get the authentication URL to which the user must be redirected for authentication
   --  by the authentication server.
   --  ------------------------------
   overriding
   function Get_Authentication_URL (Realm : in Manager;
                                    OP    : in End_Point;
                                    Assoc : in Association) return String is
      Result : Unbounded_String := OP.URL;
      State  : constant String := Realm.App.Get_State (To_String (Assoc.Assoc_Handle));
      Params : constant String := Realm.App.Get_Auth_Params (State, To_String (Realm.Scope));
   begin
      if Index (Result, "?") > 0 then
         Append (Result, "&");
      else
         Append (Result, "?");
      end if;
      Append (Result, Params);
      Append (Result, "&");
      Append (Result, Security.OAuth.Response_Type);
      Append (Result, "=code");

      Log.Debug ("Params = {0}", Params);
      return To_String (Result);
   end Get_Authentication_URL;

   --  ------------------------------
   --  Verify the authentication result
   --  ------------------------------
   overriding
   procedure Verify (Realm   : in out Manager;
                     Assoc   : in Association;
                     Request : in Parameters'Class;
                     Result  : out Authentication) is
      State : constant String := Request.Get_Parameter (Security.OAuth.State);
      Code  : constant String := Request.Get_Parameter (Security.OAuth.Code);
      Error : constant String := Request.Get_Parameter (Security.OAuth.Error_Description);
   begin
      if Error'Length /= 0 then
         Set_Result (Result, CANCEL, "Authentication refused: " & Error);
         return;
      end if;

      --  First, verify that the state parameter matches our internal state.
      if not Realm.App.Is_Valid_State (To_String (Assoc.Assoc_Handle), State) then
         Set_Result (Result, INVALID_SIGNATURE, "invalid OAuth state parameter");
         return;
      end if;

      --  Get the access token from the authorization code.
      declare
         use type Security.OAuth.Clients.Access_Token_Access;

         Acc : constant Security.OAuth.Clients.Access_Token_Access
           := Realm.App.Request_Access_Token (Code);
      begin
         if Acc = null then
            Set_Result (Result, INVALID_SIGNATURE, "cannot change the code to an access_token");
            return;
         end if;

         --  Last step, verify the access token and get the user identity.
         Manager'Class (Realm).Verify_Access_Token (Assoc, Request, Acc, Result);
      end;

   end Verify;

end Security.Auth.OAuth;

-----------------------------------------------------------------------
--  security-auth-oauth -- OAuth based authentication
--  Copyright (C) 2013 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 Util.Log.Loggers;
with Security.OAuth.Clients;
package body Security.Auth.OAuth is

   Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Security.Auth.OAuth");

   --  ------------------------------
   --  OAuth Manager
   --  ------------------------------
   --  The Manager provides the core operations for the OAuth authorization process.

   --  ------------------------------
   --  Initialize the authentication realm.
   --  ------------------------------
   overriding
   procedure Initialize (Realm     : in out Manager;
                         Params    : in Parameters'Class;
                         Provider  : in String := PROVIDER_OPENID) is
   begin
      Realm.App.Set_Application_Identifier (Params.Get_Parameter (Provider & ".client_id"));
      Realm.App.Set_Application_Secret (Params.Get_Parameter (Provider & ".secret"));
      Realm.App.Set_Application_Callback (Params.Get_Parameter (Provider & ".callback_url"));
      Realm.App.Set_Provider_URI (Params.Get_Parameter (Provider & ".request_url"));
      Realm.Realm := To_Unbounded_String (Params.Get_Parameter (Provider & ".realm"));
      Realm.Scope := To_Unbounded_String (Params.Get_Parameter (Provider & ".scope"));
      Realm.Issuer := To_Unbounded_String (Params.Get_Parameter (Provider & ".issuer"));
   end Initialize;

   --  ------------------------------
   --  Discover the OpenID provider that must be used to authenticate the user.
   --  The Name can be an URL or an alias that identifies the provider.
   --  A cached OpenID provider can be returned.
   --  Read the XRDS document from the URI and initialize the OpenID provider end point.
   --  (See OpenID Section 7.3 Discovery)
   --  ------------------------------
   overriding
   procedure Discover (Realm  : in out Manager;
                       Name   : in String;
                       Result : out End_Point) is
   begin
      Result.URL := To_Unbounded_String (Name);
   end Discover;

   --  ------------------------------
   --  Associate the application (relying party) with the OpenID provider.
   --  The association can be cached.
   --  (See OpenID Section 8 Establishing Associations)
   --  ------------------------------
   overriding
   procedure Associate (Realm  : in out Manager;
                        OP     : in End_Point;
                        Result : out Association) is
   begin
      Result.Assoc_Handle := To_Unbounded_String ("nonce-generator");
   end Associate;

   --  ------------------------------
   --  Get the authentication URL to which the user must be redirected for authentication
   --  by the authentication server.
   --  ------------------------------
   overriding
   function Get_Authentication_URL (Realm : in Manager;
                                    OP    : in End_Point;
                                    Assoc : in Association) return String is
      Result : Unbounded_String := OP.URL;
      State  : constant String := Realm.App.Get_State (To_String (Assoc.Assoc_Handle));
      Params : constant String := Realm.App.Get_Auth_Params (State, To_String (Realm.Scope));
   begin
      if Index (Result, "?") > 0 then
         Append (Result, "&");
      else
         Append (Result, "?");
      end if;
      Append (Result, Params);
      Append (Result, "&");
      Append (Result, Security.OAuth.Response_Type);
      Append (Result, "=code");

      Log.Debug ("Params = {0}", Params);
      return To_String (Result);
   end Get_Authentication_URL;

   --  ------------------------------
   --  Verify the authentication result
   --  ------------------------------
   overriding
   procedure Verify (Realm   : in out Manager;
                     Assoc   : in Association;
                     Request : in Parameters'Class;
                     Result  : out Authentication) is
      State : constant String := Request.Get_Parameter (Security.OAuth.State);
      Code  : constant String := Request.Get_Parameter (Security.OAuth.Code);
      Error : constant String := Request.Get_Parameter (Security.OAuth.Error_Description);
   begin
      if Error'Length /= 0 then
         Set_Result (Result, CANCEL, "Authentication refused: " & Error);
         return;
      end if;

      --  First, verify that the state parameter matches our internal state.
      if not Realm.App.Is_Valid_State (To_String (Assoc.Assoc_Handle), State) then
         Set_Result (Result, INVALID_SIGNATURE, "invalid OAuth state parameter");
         return;
      end if;

      --  Get the access token from the authorization code.
      declare
         use type Security.OAuth.Clients.Access_Token_Access;

         Acc : constant Security.OAuth.Clients.Access_Token_Access
           := Realm.App.Request_Access_Token (Code);
      begin
         if Acc = null then
            Set_Result (Result, INVALID_SIGNATURE, "cannot change the code to an access_token");
            return;
         end if;

         --  Last step, verify the access token and get the user identity.
         Manager'Class (Realm).Verify_Access_Token (Assoc, Request, Acc, Result);
      end;

   end Verify;

end Security.Auth.OAuth;

Initialize the issuer from the parameters


-----------------------------------------------------------------------
--  wiki-filters-toc -- Filter for the creation of Table Of Contents
--  Copyright (C) 2016 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.
-----------------------------------------------------------------------

--  === TOC Filter ===
--  The <tt>TOC_Filter</tt> is a filter used to build the table of contents.
--  It collects the headers with the section level as they are added to the
--  wiki document.  The TOC is built in the wiki document as a separate node
--  and it can be retrieved by using the <tt>Get_TOC</tt> function.
package Wiki.Filters.TOC is

   pragma Preelaborate;

   --  ------------------------------
   --  TOC Filter
   --  ------------------------------
   type TOC_Filter is new Filter_Type with null record;

   --  Add a text content with the given format to the document.
   overriding
   procedure Add_Text (Filter    : in out TOC_Filter;
                       Document  : in out Wiki.Documents.Document;
                       Text      : in Wiki.Strings.WString;
                       Format    : in Wiki.Format_Map);

   --  Add a section header with the given level in the document.
   overriding
   procedure Add_Header (Filter    : in out TOC_Filter;
                         Document  : in out Wiki.Documents.Document;
                         Header    : in Wiki.Strings.WString;
                         Level     : in Natural);

end Wiki.Filters.TOC;

-----------------------------------------------------------------------
--  wiki-filters-toc -- Filter for the creation of Table Of Contents
--  Copyright (C) 2016 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.
-----------------------------------------------------------------------

--  === TOC Filter ===
--  The <tt>TOC_Filter</tt> is a filter used to build the table of contents.
--  It collects the headers with the section level as they are added to the
--  wiki document.  The TOC is built in the wiki document as a separate node
--  and it can be retrieved by using the <tt>Get_TOC</tt> function.  To use
--  the filter, declare an aliased instance:
--
--     TOC : aliased Wiki.Filters.TOC.TOC_Filter;
--
--  and add the filter to the Wiki parser engine:
--
--     Engine.Add_Filter (TOC'Unchecked_Access);
--
package Wiki.Filters.TOC is

   pragma Preelaborate;

   --  ------------------------------
   --  TOC Filter
   --  ------------------------------
   type TOC_Filter is new Filter_Type with null record;

   --  Add a text content with the given format to the document.
   overriding
   procedure Add_Text (Filter    : in out TOC_Filter;
                       Document  : in out Wiki.Documents.Document;
                       Text      : in Wiki.Strings.WString;
                       Format    : in Wiki.Format_Map);

   --  Add a section header with the given level in the document.
   overriding
   procedure Add_Header (Filter    : in out TOC_Filter;
                         Document  : in out Wiki.Documents.Document;
                         Header    : in Wiki.Strings.WString;
                         Level     : in Natural);

end Wiki.Filters.TOC;

Add some documentation

Add some documentation