awa_unit_2.4.0_59135a52/ada-util/samples/city_mapping.ads

 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
-----------------------------------------------------------------------
--  city_mapping -- Example of serialization mapping for city CSV records
--  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 Ada.Strings.Unbounded;

with Util.Beans.Objects;
with Util.Serialize.Mappers.Record_Mapper;
with Util.Serialize.Mappers.Vector_Mapper;
with Util.Serialize.Mappers;
with Ada.Containers.Vectors;
package City_Mapping is

   use Ada.Strings.Unbounded;

   type City is record
      Country   : Unbounded_String;
      City      : Unbounded_String;
      Name      : Unbounded_String;
      Region    : Unbounded_String;
      Latitude  : Float;
      Longitude : Float;
   end record;
   type City_Access is access all City;

   type City_Fields is (FIELD_COUNTRY, FIELD_CITY, FIELD_NAME,
                        FIELD_REGION, FIELD_LATITUDE, FIELD_LONGITUDE);

   --  Set the name/value pair on the current object.
   procedure Set_Member (P     : in out City;
                         Field : in City_Fields;
                         Value : in Util.Beans.Objects.Object);

   package City_Mapper is
     new Util.Serialize.Mappers.Record_Mapper (Element_Type        => City,
                                               Element_Type_Access => City_Access,
                                               Fields              => City_Fields,
                                               Set_Member          => Set_Member);

   subtype City_Context is City_Mapper.Element_Data;

   package City_Vector is
     new Ada.Containers.Vectors (Element_Type => City,
                                 Index_Type   => Positive);

   package City_Vector_Mapper is
     new Util.Serialize.Mappers.Vector_Mapper (Vectors        => City_Vector,
                                               Element_Mapper => City_Mapper);

   subtype City_Vector_Context is City_Vector_Mapper.Vector_Data;

   --  Get the address mapper which describes how to load an Address.
   function Get_City_Mapper return Util.Serialize.Mappers.Mapper_Access;

   --  Get the person vector mapper which describes how to load a list of Person.
   function Get_City_Vector_Mapper return City_Vector_Mapper.Mapper_Access;

end City_Mapping;