yeison_0.1.0_054232ad/src/yeison_single.adb

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 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
 98
 99
100
101
102
103
104
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
149
150
151
152
153
154
155
156
157
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.UTF_Encoding.Wide_Wide_Strings;

with GNAT.IO; use GNAT.IO;

package body Yeison_Single is

   ------------
   -- To_Int --
   ------------

   function To_Int (Img : String) return Any is
   begin
      return To_Holder (Inner_Int'(Value => Integer'Value (Img)));
   end To_Int;

   -------------
   -- To_Real --
   -------------

   function To_Real (Img : String) return Any is
   begin
      return To_Holder (Inner_Real'(Value => Float'Value (Img)));
   end To_Real;

   ---------------
   -- To_String --
   ---------------

   function To_String (Img : Wide_Wide_String) return Any is
   begin
      return To_Holder (Inner_Str'(Value => new Text'(Ada.Strings.UTF_Encoding.Wide_Wide_Strings.Encode (Img))));
   end To_String;

   ------------------------
   -- Constant_Reference --
   ------------------------

   function Constant_Reference
     (This : Any; Pos : Positive) return access constant Any
   is
   begin
      raise Constraint_Error;
      return Constant_Reference (This, Pos);
   end Constant_Reference;

   ------------------------
   -- Constant_Reference --
   ------------------------

   function Constant_Reference
     (This : Any; Key : String) return access constant Any
   is
   begin
      pragma Compile_Time_Warning
        (Standard.True, "Constant_Reference unimplemented");
      return
        raise Program_Error with "Unimplemented function Constant_Reference";
   end Constant_Reference;

   -----------
   -- Empty --
   -----------

   function Empty return Any is
   begin
      return To_Holder (Inner_Map'(Value => <>));
   end Empty;

   ------------
   -- Insert --
   ------------

   procedure Insert (This : in out Any; Key : String; Val : Any) is
      Inner : Inner_Map renames Inner_Map (This.Reference.Element.all);
   begin
      Inner.Value.Insert (Key, Val.Element);
   end Insert;

   ----------
   -- True --
   ----------

   function True return Any is
   begin
      return To_Holder (Inner_Bool'(Value => True));
   end True;

   -----------
   -- False --
   -----------

   function False return Any is
   begin
      return To_Holder (Inner_Bool'(Value => False));
   end False;

   -----------
   -- Image --
   -----------

   overriding function Image (This : Inner_Map) Return String is
      use Inner_Maps;
      Result : Unbounded_String;
   begin
      Result := Result & "(";

      for I in This.Value.Iterate loop
         Result := Result & Key (I) & " => " & Element (I).Image;
         if I /= This.Value.Last then
            Result := Result & ", ";
         end if;
      end loop;

      Result := Result & ")";
      return To_String (Result);
   end Image;

   -----------
   -- Image --
   -----------

   overriding function Image (This : Inner_Vec) return String is
      use Inner_Vectors;
      Result : Unbounded_String;
   begin
      Result := Result & "(";

      for I in This.Value.Iterate loop
         Result := Result & Element (I).Image;
         if I /= This.Value.Last then
            Result := Result & ", ";
         end if;
      end loop;

      Result := Result & ")";
      return To_String (Result);
   end Image;

   function Empty return Vec_Aux
   is (Value => (Value => Inner_Vectors.Empty_Vector));

   procedure Append (This : in out Vec_Aux; Val : Any) is
   begin
      This.Value.Value.Append (Val.Element);
   end Append;

   package body Operators is

      function "+" (This : Vec_Aux) return Any is
      begin
         return To_Holder (This.Value);
      end "+";

   end Operators;

end Yeison_Single;