~sil2100/location-service/gps-arm64

« back to all changes in this revision

Viewing changes to include/location_service/com/ubuntu/location/velocity.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_VELOCITY_H_
 
2
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_VELOCITY_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 Velocity
 
18
{
 
19
    typedef units::Velocity Unit;
 
20
    typedef units::Quantity<Unit> Quantity;
 
21
 
 
22
    static inline const Quantity& min()
 
23
    {
 
24
        static const Quantity instance = Quantity::from_value(0.);
 
25
        return instance;
 
26
    }
 
27
 
 
28
    static inline const Quantity max()
 
29
    {
 
30
        static const Quantity instance = Quantity::from_value(std::numeric_limits<double>::max());
 
31
        return instance;
 
32
    }
 
33
 
 
34
    Velocity(const Quantity& value = Quantity()) : value(value)
 
35
    {
 
36
        if (value < Velocity::min())
 
37
            throw std::out_of_range("");
 
38
        if (value > Velocity::max())
 
39
            throw std::out_of_range("");
 
40
    }
 
41
 
 
42
    inline bool operator==(const Velocity& rhs) const
 
43
    {
 
44
        return value == rhs.value;
 
45
    }
 
46
 
 
47
    inline bool operator!=(const Velocity& rhs) const
 
48
    {
 
49
        return value != rhs.value;
 
50
    }
 
51
 
 
52
    Quantity value;
 
53
};
 
54
 
 
55
inline std::ostream& operator<<(std::ostream& out, const Velocity& velocity)
 
56
{
 
57
    out << "Velocity(" << velocity.value << ")";
 
58
    return out;
 
59
}
 
60
 
 
61
template<>
 
62
struct AccuracyTraits<Velocity>
 
63
{
 
64
    static AccuracyLevel classify(const Velocity& h)
 
65
    {
 
66
        if (h.value > (1.f * units::MetersPerSecond))
 
67
            return AccuracyLevel::worst;
 
68
        
 
69
        if (h.value <= (1.f * units::MetersPerSecond))
 
70
            return AccuracyLevel::best;
 
71
 
 
72
        return AccuracyLevel::worst;
 
73
    }
 
74
 
 
75
    static Accuracy<Velocity> best()
 
76
    {
 
77
        return Accuracy<Velocity>{Velocity{Velocity::min()}};
 
78
    }
 
79
 
 
80
    static Accuracy<Velocity> worst()
 
81
    {
 
82
        return Accuracy<Velocity>{Velocity{2*units::MetersPerSecond}};
 
83
    }
 
84
};
 
85
}
 
86
}
 
87
}
 
88
 
 
89
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_VELOCITY_H_