[Maps] Modify diposing routines
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / Route.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
18 using System;
19 using System.Collections.Generic;
20
21 namespace Tizen.Maps
22 {
23     /// <summary>
24     /// Route information, used in Route Search requests.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class Route : IDisposable
28     {
29         internal Interop.RouteHandle handle;
30
31         internal Route(Interop.RouteHandle nativeHandle)
32         {
33             handle = nativeHandle;
34         }
35
36         /// <summary>
37         /// Destroy the Route object.
38         /// </summary>
39         ~Route()
40         {
41             Dispose(false);
42         }
43
44         /// <summary>
45         /// Gets an instance of <see cref="Geocoordinates"/> object representing destination coordinates for this route.
46         /// </summary>
47         /// <since_tizen> 3 </since_tizen>
48         public Geocoordinates Destination
49         {
50             get
51             {
52                 return new Geocoordinates(handle.Destination);
53             }
54         }
55
56         /// <summary>
57         /// Gets the total distance for this route.
58         /// </summary>
59         /// <since_tizen> 3 </since_tizen>
60         public double Distance
61         {
62             get
63             {
64                 return handle.Distance;
65             }
66         }
67
68         /// <summary>
69         /// Get the total duration to cover this route.
70         /// </summary>
71         /// <since_tizen> 3 </since_tizen>
72         public double Duration
73         {
74             get
75             {
76                 return handle.Duration;
77             }
78         }
79
80         /// <summary>
81         /// Gets an ID for this route.
82         /// </summary>
83         /// <since_tizen> 3 </since_tizen>
84         public string Id
85         {
86             get
87             {
88                 return handle.Id;
89             }
90         }
91
92         /// <summary>
93         /// Gets the transport mode for this route.
94         /// </summary>
95         /// <since_tizen> 3 </since_tizen>
96         public TransportMode Mode
97         {
98             get
99             {
100                 return (TransportMode)handle.TransportMode;
101             }
102         }
103
104         /// <summary>
105         /// Gets the origin coordinates for this route.
106         /// </summary>
107         /// <since_tizen> 3 </since_tizen>
108         public Geocoordinates Origin
109         {
110             get
111             {
112                 return new Geocoordinates(handle.Origin);
113             }
114         }
115
116         /// <summary>
117         /// Gets a coordinates list for this route.
118         /// </summary>
119         /// <since_tizen> 3 </since_tizen>
120         public IEnumerable<Geocoordinates> Path
121         {
122             get
123             {
124                 var path = new List<Geocoordinates>();
125                 handle.ForeachPath(coordinateHandle => path.Add(new Geocoordinates(coordinateHandle)));
126                 return path;
127             }
128         }
129
130         /// <summary>
131         /// Gets a segment list for this route.
132         /// </summary>
133         /// <since_tizen> 3 </since_tizen>
134         public IEnumerable<RouteSegment> Segments
135         {
136             get
137             {
138                 var segments = new List<RouteSegment>();
139                 handle.ForeachSegment(segmentHandle => segments.Add(new RouteSegment(segmentHandle)));
140                 return segments;
141             }
142         }
143
144         /// <summary>
145         /// Gets the distance unit for this route.
146         /// </summary>
147         /// <since_tizen> 3 </since_tizen>
148         public DistanceUnit Unit
149         {
150             get
151             {
152                 return (DistanceUnit)handle.Unit;
153             }
154         }
155
156         /// <summary>
157         /// Gets an instance of <see cref="Area"/> object which representing bounding area for this route.
158         /// </summary>
159         private Area BoundingBox
160         {
161             get
162             {
163                 return new Area(handle.BoundingBox);
164             }
165         }
166
167         #region IDisposable Support
168         private bool _disposedValue = false;
169
170         /// <summary>
171         /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
172         /// </summary>
173         /// <param name="disposing">If true, managed and unmanaged resources can be disposed, otherwise only unmanaged resources can be disposed.</param>
174         /// <since_tizen> 3 </since_tizen>
175         protected virtual void Dispose(bool disposing)
176         {
177             if (!_disposedValue)
178             {
179                 handle?.Dispose();
180                 _disposedValue = true;
181             }
182         }
183
184         /// <summary>
185         /// Releases all the resources used by this object.
186         /// </summary>
187         /// <since_tizen> 3 </since_tizen>
188         public void Dispose()
189         {
190             Dispose(true);
191             GC.SuppressFinalize(this);
192         }
193         #endregion
194     }
195 }