~sil2100/location-service/gps-arm64

« back to all changes in this revision

Viewing changes to include/location_service/com/ubuntu/location/heading.h

  • Committer: Thomas Voß
  • Date: 2013-05-28 14:20:45 UTC
  • Revision ID: thomas.voss@canonical.com-20130528142045-kq5umqdmm4o53vwk
Initial push.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_HEADING_H_
 
2
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_HEADING_H_
 
3
 
 
4
#include "com/ubuntu/location/accuracy.h"
 
5
#include "com/ubuntu/location/units/units.h"
 
6
 
 
7
#include <limits>
 
8
#include <ostream>
 
9
#include <stdexcept>
 
10
 
 
11
namespace com
 
12
{
 
13
namespace ubuntu
 
14
{
 
15
namespace location
 
16
{
 
17
struct Heading
 
18
{
 
19
    typedef units::PlaneAngle Unit;
 
20
    typedef units::Quantity<Unit> Quantity;
 
21
 
 
22
    static const Quantity& min()
 
23
    {
 
24
        static const auto instance = Heading::Quantity::from_value(0.);
 
25
        return instance;
 
26
    }
 
27
    static const Quantity& max()
 
28
    {
 
29
        static const auto instance = Heading::Quantity::from_value(360.);
 
30
        return instance;
 
31
    }
 
32
 
 
33
    Heading(const Quantity& value = Quantity()) : value(value)
 
34
    {
 
35
        if (value < min())
 
36
            throw std::out_of_range("");
 
37
        if (value > max())
 
38
            throw std::out_of_range("");
 
39
    }
 
40
 
 
41
    bool operator==(const Heading& rhs) const
 
42
    {
 
43
        return value == rhs.value;
 
44
    }
 
45
 
 
46
    bool operator!=(const Heading& rhs) const
 
47
    {
 
48
        return value != rhs.value;
 
49
    }
 
50
 
 
51
    Quantity value;
 
52
};
 
53
 
 
54
inline std::ostream& operator<<(std::ostream& out, const Heading& heading)
 
55
{
 
56
    out << "Heading(" << heading.value << ")";
 
57
    return out;
 
58
}
 
59
 
 
60
template<>
 
61
struct AccuracyTraits<Heading>
 
62
{
 
63
    static AccuracyLevel classify(const Heading& h)
 
64
    {
 
65
        static const auto half = 0.5 * Heading::max();
 
66
        if(h.value > half)
 
67
            return AccuracyLevel::worst;
 
68
 
 
69
        if(h.value < half)
 
70
            return AccuracyLevel::best;
 
71
 
 
72
        return AccuracyLevel::worst;
 
73
    }
 
74
 
 
75
    static Accuracy<Heading> best()
 
76
    {
 
77
        return Accuracy<Heading>{Heading{Heading::min()}};
 
78
    }
 
79
 
 
80
    static Accuracy<Heading> worst()
 
81
    {
 
82
        return Accuracy<Heading>{Heading{Heading::max()}};
 
83
    }
 
84
};
 
85
}
 
86
}
 
87
}
 
88
 
 
89
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_HEADING_H_