Overview
Comment: | s_expressions-templates-generic_integers: new command to add template-provided images for specific values (similar to discrete renderer) |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
7b85767e7d091dafd9fbed8cf83f5601 |
User & Date: | nat on 2014-09-23 18:33:51 |
Other Links: | manifest | tags |
Context
2014-09-23
| ||
18:35 | Add generated packages updates missing from previous commit check-in: 160210cf8d user: nat tags: trunk | |
18:33 | s_expressions-templates-generic_integers: new command to add template-provided images for specific values (similar to discrete renderer) check-in: 7b85767e7d user: nat tags: trunk | |
2014-09-21
| ||
20:14 | s_expressions-templates-tests-integers: test the new Render procedure with client-provided default format check-in: 6f758d2e84 user: nat tags: trunk | |
Changes
Modified generated/natools-static_maps-s_expressions-templates-integers-mc.adb from [079f989c24] to [f99aedd664].
1 2 3 4 | 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 | - - + + - - + + - - + + - - - + + + + - - + + - + | with Interfaces; use Interfaces; package body Natools.Static_Maps.S_Expressions.Templates.Integers.MC is |
Modified generated/natools-static_maps-s_expressions-templates-integers-t.adb from [1e73774a70] to [dd1c4e859a].
| 1 2 3 4 5 6 7 8 | - + |
|
︙ |
Modified generated/natools-static_maps-s_expressions-templates-integers-t.ads from [3769356ef6] to [ef4bea0b49].
| 1 2 3 4 5 6 | - + |
|
Modified src/natools-s_expressions-templates-generic_integers-maps.sx from [bb53337f82] to [55e2d235de].
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 | 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 | + + | (Natools.Static_Maps.S_Expressions.Templates.Integers pure (test-function T) (extra-decl "\ type Main_Command is (Error, Align, Align_Center, Align_Left, Align_Right, Base, Images, Padding, Padding_Left, Padding_Right, Sign, Width, Width_Max, Width_Min); type Align_Command is (Unknown_Align, Set_Left, Set_Center, Set_Right);") (Main_Command (hash-package Natools.Static_Maps.S_Expressions.Templates.Integers.MC) (function Main) (not-found Error) (nodes (Align align) (Align_Center align-center centered) (Align_Left align-left left-align) (Align_Right align-right right-align) (Base base) (Images image images) (Padding padding) (Padding_Left padding-left left-padding) (Padding_Right padding-right right-padding) (Sign sign signs) (Width width) (Width_Max width-max max-width) (Width_Min width-min min-width))) |
︙ |
Modified src/natools-s_expressions-templates-generic_integers.adb from [5a59e200e3] to [6f9a793c86].
︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 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 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | package Commands renames Natools.Static_Maps.S_Expressions.Templates.Integers; function Create (Data : Atom) return Atom_Refs.Immutable_Reference renames Atom_Ref_Constructors.Create; procedure Insert_Image (State : in out Format; Context : in Meaningless_Type; Image : in Atom); procedure Update_Image (State : in out Format; Context : in Meaningless_Type; Name : in Atom; Arguments : in out Lockable.Descriptor'Class); procedure Update_Format (State : in out Format; Context : in Meaningless_Type; Name : in Atom; Arguments : in out Lockable.Descriptor'Class); ------------------------------ -- Local Helper Subprograms -- ------------------------------ procedure Insert_Image (State : in out Format; Context : in Meaningless_Type; Image : in Atom) is pragma Unreferenced (Context); begin State.Append_Image (Image); end Insert_Image; procedure Update_Image (State : in out Format; Context : in Meaningless_Type; Name : in Atom; Arguments : in out Lockable.Descriptor'Class) is pragma Unreferenced (Context); Value : T; begin begin Value := T'Value (To_String (Name)); exception when Constraint_Error => return; end; case Arguments.Current_Event is when Events.Add_Atom => State.Set_Image (Value, Arguments.Current_Atom); when others => State.Remove_Image (Value); end case; end Update_Image; procedure Image_Interpreter is new Interpreter_Loop (Format, Meaningless_Type, Update_Image, Insert_Image); procedure Update_Format (State : in out Format; Context : in Meaningless_Type; Name : in Atom; Arguments : in out Lockable.Descriptor'Class) is |
︙ | |||
79 80 81 82 83 84 85 86 87 88 89 90 91 92 | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | + + + | when Commands.Align_Right => State.Set_Align (Right_Aligned); when Commands.Base => State.Set_Symbols (Arguments); when Commands.Images => Image_Interpreter (Arguments, State, Meaningless_Value); when Commands.Padding => case Arguments.Current_Event is when Events.Add_Atom => State.Left_Padding := Create (Arguments.Current_Atom); State.Right_Padding := State.Left_Padding; when others => return; |
︙ | |||
189 190 191 192 193 194 195 | 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | - + | null; end case; end case; end Update_Format; procedure Interpreter is new Interpreter_Loop |
︙ | |||
310 311 312 313 314 315 316 317 318 319 320 321 322 323 | 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | + + + + + + + + + | Output : Atom_Buffers.Atom_Buffer; Has_Sign : Boolean := True; Length : Width; Symbols : constant Atom_Arrays.Immutable_Reference := (if Template.Symbols.Is_Empty then Decimal else Template.Symbols); begin Check_Explicit_Image : declare Cursor : constant Atom_Maps.Cursor := Template.Images.Find (Value); begin if Atom_Maps.Has_Element (Cursor) then return Atom_Maps.Element (Cursor).Query.Data.all; end if; end Check_Explicit_Image; if Value < 0 then Reverse_Render (-Value, Symbols.Query.Data.all, Output, Length); Output.Append (Safe_Atom (Template.Negative_Sign, "-")); else Reverse_Render (Value, Symbols.Query.Data.all, Output, Length); if not Template.Positive_Sign.Is_Empty then |
︙ | |||
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | end Render; --------------------- -- Format Mutators -- --------------------- procedure Append_Image (Object : in out Format; Image : in Atom_Refs.Immutable_Reference) is begin Set_Image (Object, Next_Index (Object.Images), Image); end Append_Image; procedure Append_Image (Object : in out Format; Image : in Atom) is begin Append_Image (Object, Create (Image)); end Append_Image; procedure Remove_Image (Object : in out Format; Value : in T) is begin Object.Images.Exclude (Value); end Remove_Image; procedure Set_Align (Object : in out Format; Value : in Alignment) is begin Object.Align := Value; end Set_Align; procedure Set_Image (Object : in out Format; Value : in T; Image : in Atom_Refs.Immutable_Reference) is begin Object.Images.Include (Value, Image); end Set_Image; procedure Set_Image (Object : in out Format; Value : in T; Image : in Atom) is begin Set_Image (Object, Value, Create (Image)); end Set_Image; procedure Set_Left_Padding (Object : in out Format; Symbol : in Atom_Refs.Immutable_Reference) is begin Object.Left_Padding := Symbol; end Set_Left_Padding; |
︙ |
Modified src/natools-s_expressions-templates-generic_integers.ads from [d783375add] to [cc73e0eb79].
︙ | |||
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 | 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 | + + + + | ------------------------------------------------------------------------------ -- Natools.S_Expressions.Templates.Generic_Integers provides a template -- -- interpreter for integer rendering. -- -- The following commands are recognized: -- -- (align "left|right|center") -- -- (base "symbol 0" "symbol 1" "symbol 2" ...) -- -- (left-padding "symbol") -- -- (image (0 "symbol 0") (2 "symbol 2") ...) -- -- (max-width "max width" ["overflow text"]) -- -- (min-width "min width") -- -- (padding "left-symbol" "right-symbol") -- -- (padding "symbol") -- -- (right-padding "symbol") -- -- (sign "plus sign" ["minus sign"]) -- -- (width "fixed width") -- -- (width "min width" "max width" ["overflow text"]) -- -- Top-level atoms are taken as the image for the next number. -- ------------------------------------------------------------------------------ with Ada.Containers.Ordered_Maps; with Ada.Streams; with Natools.References; with Natools.S_Expressions.Atom_Buffers; with Natools.S_Expressions.Atom_Refs; with Natools.S_Expressions.Lockable; with Natools.Storage_Pools; generic type T is range <>; with function "<" (Left, Right : T) return Boolean is <>; package Natools.S_Expressions.Templates.Generic_Integers is pragma Preelaborate; -------------------------- -- High-Level Interface -- -------------------------- |
︙ | |||
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | 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 | + + + + + + + + + + + + + + + + + + + + + + + + | -- Build an array reference consisting of -- consecutive atoms found in Atom_List. function Decimal return Atom_Arrays.Immutable_Reference with Post => not Decimal'Result.Is_Empty; -- Return a reference to usual decimal representation package Atom_Maps is new Ada.Containers.Ordered_Maps (T, Atom_Refs.Immutable_Reference, "<", Atom_Refs."="); function Next_Index (Map : Atom_Maps.Map) return T is (if Map.Is_Empty then T'First else Map.Last_Key + 1); -- Index of the next element to insert in sequential lists --------------------- -- Format Mutators -- --------------------- procedure Set_Align (Object : in out Format; Value : in Alignment); procedure Append_Image (Object : in out Format; Image : in Atom_Refs.Immutable_Reference); procedure Append_Image (Object : in out Format; Image : in Atom); procedure Remove_Image (Object : in out Format; Value : in T); procedure Set_Image (Object : in out Format; Value : in T; Image : in Atom_Refs.Immutable_Reference); procedure Set_Image (Object : in out Format; Value : in T; Image : in Atom); procedure Set_Left_Padding (Object : in out Format; Symbol : in Atom_Refs.Immutable_Reference); procedure Set_Left_Padding (Object : in out Format; Symbol : in Atom); |
︙ | |||
180 181 182 183 184 185 186 187 188 189 | 208 209 210 211 212 213 214 215 216 217 218 219 | + + | Minimum_Width : Width := 0; Align : Alignment := Right_Aligned; Left_Padding : Atom_Refs.Immutable_Reference; Right_Padding : Atom_Refs.Immutable_Reference; Maximum_Width : Width := Width'Last; Overflow_Message : Atom_Refs.Immutable_Reference; Images : Atom_Maps.Map; end record; end Natools.S_Expressions.Templates.Generic_Integers; |