Natools

Check-in [592c7cfd1a]
Login
Overview
Comment:s_expressions-templates-generic_discrete_render: new generic procedure for rendering values of discrete types
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 592c7cfd1ad08e58243f48d02025cd196a131685
User & Date: nat on 2014-09-17 21:07:13
Other Links: manifest | tags
Context
2014-09-18
20:08
s_expressions-templates-tests: a simple tests for discrete-type templates check-in: 6f0dd49985 user: nat tags: trunk
2014-09-17
21:07
s_expressions-templates-generic_discrete_render: new generic procedure for rendering values of discrete types check-in: 592c7cfd1a user: nat tags: trunk
2014-09-16
19:05
s_expressions-templates-tests: new test suite for S-expression template systems check-in: f11c7d1766 user: nat tags: trunk
Changes

Added src/natools-s_expressions-templates-generic_discrete_render.adb version [62ec8a401e].













































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

procedure Natools.S_Expressions.Templates.Generic_Discrete_Render
  (Output : in out Ada.Streams.Root_Stream_Type'Class;
   Template : in out Lockable.Descriptor'Class;
   Value : in T)
is
   Current_Value : T := T'First;
   Event : Events.Event := Template.Current_Event;
begin
   loop
      case Event is
         when Events.Add_Atom =>
            if Current_Value = Value then
               Output.Write (Template.Current_Atom);
               return;
            end if;

         when Events.Open_List =>
            loop
               Template.Next (Event);

               case Event is
                  when Events.Add_Atom =>
                     Output.Write (Template.Current_Atom);
                  when others =>
                     return;
               end case;
            end loop;

         when Events.Close_List | Events.End_Of_Input | Events.Error =>
            exit;
      end case;

      Template.Next (Event);
      Current_Value := T'Succ (Current_Value);
   end loop;

   Output.Write (To_Atom (Default_Image (Value)));
end Natools.S_Expressions.Templates.Generic_Discrete_Render;

Added src/natools-s_expressions-templates-generic_discrete_render.ads version [6aed9b558e].











































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-- Natools.S_Expressions.Templates.Generic_Discrete_Render provides a       --
-- S-expression template renderer for discrete types.                       --
-- The template is a list of atoms, representing images in the order of the --
-- formal discrete type, optionally followed by a list whose atoms are      --
-- concatenated to form a fallback image for all others values. When        --
-- fallback image is not provided, formal Default_Image function is used.   --
------------------------------------------------------------------------------

with Ada.Streams;
with Natools.S_Expressions.Lockable;

generic
   type T is (<>);
   with function Default_Image (Object : T) return String is T'Image;
   with function "=" (Left, Right : T) return Boolean is <>;
procedure Natools.S_Expressions.Templates.Generic_Discrete_Render
  (Output : in out Ada.Streams.Root_Stream_Type'Class;
   Template : in out Lockable.Descriptor'Class;
   Value : in T);
pragma Preelaborate (Natools.S_Expressions.Templates.Generic_Discrete_Render);