-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnit.h
More file actions
173 lines (150 loc) · 5.52 KB
/
Unit.h
File metadata and controls
173 lines (150 loc) · 5.52 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/***************************************************************************
* Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef BASE_Unit_H
#define BASE_Unit_H
#ifdef _MSC_VER
# include <boost/cstdint.hpp>
#else
# include <stdint.h>
#endif
#include <string>
#include <QString>
namespace Base {
#define UnitSignatureLengthBits 4
#define UnitSignatureMassBits 4
#define UnitSignatureTimeBits 4
#define UnitSignatureElectricCurrentBits 4
#define UnitSignatureThermodynamicTemperatureBits 4
#define UnitSignatureAmountOfSubstanceBits 4
#define UnitSignatureLuminousIntensityBits 4
#define UnitSignatureAngleBits 4
// Hint:
// https://en.cppreference.com/w/cpp/language/bit_field
// https://stackoverflow.com/questions/33723631/signed-bit-field-in-c14
struct UnitSignature{
int32_t Length:UnitSignatureLengthBits;
int32_t Mass:UnitSignatureMassBits;
int32_t Time:UnitSignatureTimeBits;
int32_t ElectricCurrent:UnitSignatureElectricCurrentBits;
int32_t ThermodynamicTemperature:UnitSignatureThermodynamicTemperatureBits;
int32_t AmountOfSubstance:UnitSignatureAmountOfSubstanceBits;
int32_t LuminousIntensity:UnitSignatureLuminousIntensityBits;
int32_t Angle:UnitSignatureAngleBits;
};
/**
* The Unit class.
*/
class BaseExport Unit
{
public:
/// default constructor
Unit(int8_t Length,int8_t Mass=0,int8_t Time=0,int8_t ElectricCurrent=0,int8_t ThermodynamicTemperature=0,int8_t AmountOfSubstance=0,int8_t LuminousIntensity=0,int8_t Angle=0);
Unit(void);
Unit(const Unit&);
Unit(const QString& expr);
/// Destruction
~Unit () {}
/** Operators. */
//@{
inline Unit& operator *=(const Unit& that);
inline Unit& operator /=(const Unit& that);
Unit operator *(const Unit&) const;
Unit operator /(const Unit&) const;
bool operator ==(const Unit&) const;
bool operator !=(const Unit&that) const {return !(*this == that);}
Unit& operator =(const Unit&);
Unit pow(signed char exp)const;
//@}
/// get the unit signature
const UnitSignature & getSignature(void)const {return Sig;}
bool isEmpty(void)const;
QString getString(void) const;
/// get the type as an string such as "Area", "Length" or "Pressure".
QString getTypeString(void) const;
/** Predefined Unit types. */
//@{
/// Length unit
static Unit Length;
/// Mass unit
static Unit Mass;
/// Angle
static Unit Angle;
static Unit AngleOfFriction;
static Unit Density;
static Unit Area;
static Unit Volume;
static Unit TimeSpan;
static Unit Frequency;
static Unit Velocity;
static Unit Acceleration;
static Unit Temperature;
static Unit ElectricCurrent;
static Unit ElectricPotential;
static Unit ElectricCharge;
static Unit MagneticFieldStrength;
static Unit MagneticFlux;
static Unit MagneticFluxDensity;
static Unit ElectricalCapacitance;
static Unit ElectricalInductance;
static Unit ElectricalConductance;
static Unit ElectricalResistance;
static Unit ElectricalConductivity;
static Unit AmountOfSubstance;
static Unit LuminousIntensity;
// Pressure
static Unit CompressiveStrength;
static Unit Pressure;
static Unit ShearModulus;
static Unit Stress;
static Unit UltimateTensileStrength;
static Unit YieldStrength;
static Unit YoungsModulus;
static Unit Stiffness;
static Unit Force;
static Unit Work;
static Unit Power;
static Unit SpecificEnergy;
static Unit ThermalConductivity;
static Unit ThermalExpansionCoefficient;
static Unit VolumetricThermalExpansionCoefficient;
static Unit SpecificHeat;
static Unit ThermalTransferCoefficient;
static Unit HeatFlux;
static Unit DynamicViscosity;
static Unit KinematicViscosity;
static Unit VacuumPermittivity;
//@}
protected:
UnitSignature Sig;
};
inline Unit& Unit::operator *=(const Unit& that)
{
*this = *this * that;
return *this;
}
inline Unit& Unit::operator /=(const Unit& that)
{
*this = *this / that;
return *this;
}
} // namespace Base
#endif // BASE_Unit_H