nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 // License: BSD/LGPL
2 // Copyright (C) 2011 Thomas d'Otreppe
3 using System;
4 using System.Collections;
5 using System.Text;
6  
7 namespace WirelessPanda
8 {
9 public class Coordinates
10 {
11 #region Dictionary stuff
12 private Hashtable _dictionary = new Hashtable();
13  
14 private void setDictValue(string elem, double value)
15 {
16 if (this._dictionary.ContainsKey(elem))
17 {
18 this._dictionary.Remove(elem);
19 }
20 this._dictionary.Add(elem, value);
21 }
22  
23 private double getDictValue(string elem)
24 {
25 if (this._dictionary.ContainsKey(elem))
26 {
27 return (double)this._dictionary[elem];
28 }
29  
30 throw new MissingFieldException("Value <" + elem + "> is not set or does not exist");
31 }
32 #endregion
33  
34 #region Properties
35 /// <summary>
36 /// Latitude
37 /// </summary>
38 public double Latitude
39 {
40 get
41 {
42 return this.getDictValue("Latitude");
43 }
44 set
45 {
46 this.setDictValue("Latitude", value);
47 }
48 }
49  
50 /// <summary>
51 /// Longitude
52 /// </summary>
53 public double Longitude
54 {
55 get
56 {
57 return this.getDictValue("Longitude");
58 }
59 set
60 {
61 this.setDictValue("Longitude", value);
62 }
63 }
64  
65 /// <summary>
66 /// Altitude (in meters)
67 /// </summary>
68 public double Altitude
69 {
70 get
71 {
72 return this.getDictValue("Altitude");
73 }
74 set
75 {
76 this.setDictValue("Altitude", value);
77 }
78 }
79  
80 /// <summary>
81 /// Speed (UOM: probably knot but unsure)
82 /// </summary>
83 public double Speed
84 {
85 get
86 {
87 return this.getDictValue("Speed");
88 }
89 set
90 {
91 this.setDictValue("Speed", value);
92 }
93 }
94 #endregion
95  
96 public Coordinates(string latitude = null, string longitude = null, string altitude = null, string speed = null)
97 {
98 if (!string.IsNullOrEmpty(latitude))
99 {
100 this.Latitude = double.Parse(latitude);
101 }
102  
103 if (!string.IsNullOrEmpty(longitude))
104 {
105 this.Longitude = double.Parse(longitude);
106 }
107  
108 if (!string.IsNullOrEmpty(altitude))
109 {
110 this.Altitude = double.Parse(altitude);
111 }
112  
113 if (!string.IsNullOrEmpty(speed))
114 {
115 this.Speed = double.Parse(speed);
116 }
117 }
118  
119 public Coordinates(double latitude, double longitude)
120 {
121 this.Latitude = latitude;
122 }
123  
124 public Coordinates(double latitude, double longitude, double altitude) : this(latitude, longitude)
125 {
126 this.Altitude = latitude;
127 }
128  
129 public Coordinates(double latitude, double longitude, double altitude, double speed) : this(latitude, longitude, altitude)
130 {
131 this.Speed = speed;
132 }
133  
134 public override string ToString()
135 {
136 StringBuilder sb = new StringBuilder();
137 try
138 {
139 sb.Append(this.Latitude);
140 sb.Append(", ");
141 sb.Append(this.Longitude);
142  
143  
144 if (this._dictionary.ContainsKey("Altitude"))
145 {
146 sb.Append(" - Altitude: ");
147 sb.Append(this.Altitude);
148 }
149  
150 if (this._dictionary.ContainsKey("Speed"))
151 {
152 sb.Append(" - Speed: ");
153 sb.Append(this.Speed);
154 }
155  
156 }
157 catch
158 {
159 if (sb.Length > 0)
160 {
161 sb.Remove(0, sb.Length);
162 }
163 }
164  
165 return sb.ToString();
166 }
167 }
168 }