summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/Speed.h
blob: 8ad5d05bf02db0fb67e3081f8ef52e1e11604e6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "utils/IArchivable.h"

#include <string>

class CSpeed : public IArchivable
{
public:
  CSpeed();
  CSpeed(const CSpeed& speed);

  typedef enum Unit
  {
    UnitKilometresPerHour = 0,
    UnitMetresPerMinute,
    UnitMetresPerSecond,
    UnitFeetPerHour,
    UnitFeetPerMinute,
    UnitFeetPerSecond,
    UnitMilesPerHour,
    UnitKnots,
    UnitBeaufort,
    UnitInchPerSecond,
    UnitYardPerSecond,
    UnitFurlongPerFortnight
  } Unit;

  static CSpeed CreateFromKilometresPerHour(double value);
  static CSpeed CreateFromMetresPerMinute(double value);
  static CSpeed CreateFromMetresPerSecond(double value);
  static CSpeed CreateFromFeetPerHour(double value);
  static CSpeed CreateFromFeetPerMinute(double value);
  static CSpeed CreateFromFeetPerSecond(double value);
  static CSpeed CreateFromMilesPerHour(double value);
  static CSpeed CreateFromKnots(double value);
  static CSpeed CreateFromBeaufort(unsigned int value);
  static CSpeed CreateFromInchPerSecond(double value);
  static CSpeed CreateFromYardPerSecond(double value);
  static CSpeed CreateFromFurlongPerFortnight(double value);

  bool operator >(const CSpeed& right) const;
  bool operator >=(const CSpeed& right) const;
  bool operator <(const CSpeed& right) const;
  bool operator <=(const CSpeed& right) const;
  bool operator ==(const CSpeed& right) const;
  bool operator !=(const CSpeed& right) const;

  CSpeed& operator =(const CSpeed& right);
  const CSpeed& operator +=(const CSpeed& right);
  const CSpeed& operator -=(const CSpeed& right);
  const CSpeed& operator *=(const CSpeed& right);
  const CSpeed& operator /=(const CSpeed& right);
  CSpeed operator +(const CSpeed& right) const;
  CSpeed operator -(const CSpeed& right) const;
  CSpeed operator *(const CSpeed& right) const;
  CSpeed operator /(const CSpeed& right) const;

  bool operator >(double right) const;
  bool operator >=(double right) const;
  bool operator <(double right) const;
  bool operator <=(double right) const;
  bool operator ==(double right) const;
  bool operator !=(double right) const;

  const CSpeed& operator +=(double right);
  const CSpeed& operator -=(double right);
  const CSpeed& operator *=(double right);
  const CSpeed& operator /=(double right);
  CSpeed operator +(double right) const;
  CSpeed operator -(double right) const;
  CSpeed operator *(double right) const;
  CSpeed operator /(double right) const;

  CSpeed& operator ++();
  CSpeed& operator --();
  CSpeed operator ++(int);
  CSpeed operator --(int);

  void Archive(CArchive& ar) override;

  bool IsValid() const;

  double ToKilometresPerHour() const;
  double ToMetresPerMinute() const;
  double ToMetresPerSecond() const;
  double ToFeetPerHour() const;
  double ToFeetPerMinute() const;
  double ToFeetPerSecond() const;
  double ToMilesPerHour() const;
  double ToKnots() const;
  double ToBeaufort() const;
  double ToInchPerSecond() const;
  double ToYardPerSecond() const;
  double ToFurlongPerFortnight() const;

  double To(Unit speedUnit) const;
  std::string ToString(Unit speedUnit) const;

protected:
  explicit CSpeed(double value);

  void SetValid(bool valid) { m_valid = valid; }

  double m_value; // we store in m/s
  bool m_valid;
};