ubuntu-location-service  0.0.2
position.h
1 /*
2  * Copyright © 2012-2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 #ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_POSITION_H_
19 #define LOCATION_SERVICE_COM_UBUNTU_LOCATION_POSITION_H_
20 
21 #include "com/ubuntu/location/wgs84/altitude.h"
22 #include "com/ubuntu/location/wgs84/latitude.h"
23 #include "com/ubuntu/location/wgs84/longitude.h"
24 
25 #include <bitset>
26 #include <ostream>
27 
28 namespace com
29 {
30 namespace ubuntu
31 {
32 namespace location
33 {
34 class Position
35 {
36  public:
37  enum Flag
38  {
39  latitude_flag = 0,
40  longitude_flag = 1,
41  altitude_flag = 2
42  };
43 
44  typedef std::bitset<3> Flags;
45 
46  Position();
47  Position(
48  const wgs84::Latitude& latitude,
49  const wgs84::Longitude& longitude);
50  Position(
51  const wgs84::Latitude& latitude,
52  const wgs84::Longitude& longitude,
53  const wgs84::Altitude& altitude);
54 
55  bool operator==(const Position& rhs) const;
56  bool operator!=(const Position& rhs) const;
57 
58  const Flags& flags() const;
59 
60  bool has_latitude() const;
61  Position& latitude(const wgs84::Latitude& lat);
62  const wgs84::Latitude& latitude() const;
63 
64  bool has_longitude() const;
65  Position& longitude(const wgs84::Longitude& lon);
66  const wgs84::Longitude& longitude() const;
67 
68  bool has_altitude() const;
69  Position& altitude(const wgs84::Altitude& alt);
70  const wgs84::Altitude& altitude() const;
71 
72  private:
73  template<typename> friend struct Codec;
74 
75  struct
76  {
77  Flags flags;
78  wgs84::Latitude latitude;
79  wgs84::Longitude longitude;
80  wgs84::Altitude altitude;
81  } fields;
82 };
83 
84 std::ostream& operator<<(std::ostream& out, const Position& position);
85 
86 units::Quantity<units::Length> haversine_distance(const Position& p1, const Position& p2);
87 }
88 }
89 }
90 #endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_POSITION_H_