Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Interop / Interop.Coordinates.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19
20 internal static partial class Interop
21 {
22     [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_get_latitude")]
23     internal static extern ErrorCode GetLatitude(this CoordinatesHandle /* maps_coordinates_h */ coordinates, out double latitude);
24
25     [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_get_longitude")]
26     internal static extern ErrorCode GetLongitude(this CoordinatesHandle /* maps_coordinates_h */ coordinates, out double longitude);
27
28     internal class CoordinatesHandle : SafeMapsHandle
29     {
30         [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_create")]
31         internal static extern ErrorCode Create(double latitude, double longitude, out IntPtr /* maps_coordinates_h */ coordinates);
32
33         [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_destroy")]
34         internal static extern ErrorCode Destroy(IntPtr /* maps_coordinates_h */ coordinates);
35
36         [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_clone")]
37         internal static extern ErrorCode Clone(IntPtr /* maps_coordinates_h */ origin, out IntPtr /* maps_coordinates_h */ cloned);
38
39         internal double Latitude
40         {
41             get { return NativeGet<double>(this.GetLatitude); }
42         }
43
44         internal double Longitude
45         {
46             get { return NativeGet<double>(this.GetLongitude); }
47         }
48
49         internal CoordinatesHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
50         {
51         }
52
53         internal CoordinatesHandle(double latitude, double longitude) : this(IntPtr.Zero, true)
54         {
55             Create(latitude, longitude, out handle).ThrowIfFailed("Failed to create native handle");
56         }
57
58         internal static CoordinatesHandle CloneFrom(IntPtr nativeHandle)
59         {
60             IntPtr handle;
61             Clone(nativeHandle, out handle).ThrowIfFailed("Failed to clone native handle");
62             return new CoordinatesHandle(handle, true);
63         }
64
65         internal static CoordinatesHandle Create(IntPtr nativeHandle)
66         {
67             return new CoordinatesHandle(nativeHandle, true);
68         }
69
70         public override string ToString()
71         {
72             return $"[{Latitude}, {Longitude}]";
73         }
74     }
75 }