forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
units.h
118 lines (102 loc) · 2.75 KB
/
units.h
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
117
118
#pragma once
#ifndef CATA_SRC_UNITS_H
#define CATA_SRC_UNITS_H
#include <limits>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#include "units_def.h"
#include "units_angle.h"
#include "units_volume.h"
#include "units_mass.h"
#include "units_energy.h"
#include "units_money.h"
#include "units_temperature.h"
#include "units_probability.h"
namespace units
{
// Streaming operators for debugging and tests
// (for UI output other functions should be used which render in the user's
// chosen units)
inline std::ostream &operator<<( std::ostream &o, mass_in_milligram_tag )
{
return o << "mg";
}
inline std::ostream &operator<<( std::ostream &o, volume_in_milliliter_tag )
{
return o << "ml";
}
inline std::ostream &operator<<( std::ostream &o, energy_in_joule_tag )
{
return o << "J";
}
inline std::ostream &operator<<( std::ostream &o, money_in_cent_tag )
{
return o << "cent";
}
inline std::ostream &operator<<( std::ostream &o, angle_in_radians_tag )
{
return o << "rad";
}
inline std::ostream &operator<<( std::ostream &o, temperature_in_millidegree_celsius_tag )
{
return o << "mC";
}
inline std::ostream &operator<<( std::ostream &o, probability_in_one_in_million_tag )
{
return o << "pm";
}
template<typename value_type, typename tag_type>
inline std::ostream &operator<<( std::ostream &o, const quantity<value_type, tag_type> &v )
{
return o << v.value() << tag_type{};
}
std::string display( units::energy v );
} // namespace units
namespace units
{
static const std::vector<std::pair<std::string, energy>> energy_units = { {
{ "mJ", 1_J }, // Millijoules are depreciated, this is only defined to migrate old saves.
{ "J", 1_J },
{ "kJ", 1_kJ },
}
};
static const std::vector<std::pair<std::string, mass>> mass_units = { {
{ "mg", 1_milligram },
{ "g", 1_gram },
{ "kg", 1_kilogram },
}
};
static const std::vector<std::pair<std::string, money>> money_units = { {
{ "cent", 1_cent },
{ "USD", 1_USD },
{ "kUSD", 1_kUSD },
}
};
static const std::vector<std::pair<std::string, volume>> volume_units = { {
{ "ml", 1_ml },
{ "L", 1_liter }
}
};
static const std::vector<std::pair<std::string, angle>> angle_units = { {
{ "arcmin", 1_arcmin },
{ "°", 1_degrees },
{ "rad", 1_radians },
}
};
static const std::vector<std::pair<std::string, temperature>> temperature_units = { {
{ "mC", 1_mc },
{ "C", 1_c },
// Fahrenheit not supported
// { "f", 1_f },
}
};
static const std::vector<std::pair<std::string, probability>> probability_units = { {
{ "pm", 1_pm },
{ "pct", 1_pct },
{ "%", 1_pct }
}
};
} // namespace units
#endif // CATA_SRC_UNITS_H