| 1 | // tUnits.cpp  |
| 2 | //  |
| 3 | // Definitions of various units for length, time, and mass along with the SI multiplier prefixes.  |
| 4 | //  |
| 5 | // Copyright (c) 2017, 2020 Tristan Grimmer.  |
| 6 | // Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby  |
| 7 | // granted, provided that the above copyright notice and this permission notice appear in all copies.  |
| 8 | //  |
| 9 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL  |
| 10 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,  |
| 11 | // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN  |
| 12 | // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR  |
| 13 | // PERFORMANCE OF THIS SOFTWARE.  |
| 14 |   |
| 15 | #include "Foundation/tStandard.h"  |
| 16 | #include "Foundation/tUnits.h"  |
| 17 |   |
| 18 |   |
| 19 | namespace tUnit  |
| 20 | {  |
| 21 | const char* TimeUnitNames[int(tTime::NumTimeUnits)] =  |
| 22 | {  |
| 23 | "PlankTime" ,  |
| 24 | "Chronon" ,  |
| 25 | "Attosecond" ,  |
| 26 | "Femtosecond" ,  |
| 27 | "Picosecond" ,  |
| 28 | "Nanosecond" ,  |
| 29 | "Microsecond" ,  |
| 30 | "Millisecond" ,  |
| 31 | "Tick" ,  |
| 32 | "Second" ,  |
| 33 | "She" ,  |
| 34 | "Helek" ,  |
| 35 | "Minute" ,  |
| 36 | "Hour" ,  |
| 37 | "Day" ,  |
| 38 | "Week" ,  |
| 39 | "Fortnight" ,  |
| 40 | "Year" ,  |
| 41 | "Annum" ,  |
| 42 | "Century" ,  |
| 43 | "Millennium" ,  |
| 44 | "GalacticYear"   |
| 45 | };  |
| 46 |   |
| 47 |   |
| 48 | const char* LengthUnitNames[int(tLength::NumLengthUnits)] =  |
| 49 | {  |
| 50 | "Angstrom" ,  |
| 51 | "Meter" ,  |
| 52 | "Kilometer" ,  |
| 53 | "Inch" ,  |
| 54 | "Foot" ,  |
| 55 | "Yard" ,  |
| 56 | "Fathom" ,  |
| 57 | "Mile" ,  |
| 58 | "NauticalMile" ,  |
| 59 | "AstronomicalUnit"   |
| 60 | };  |
| 61 |   |
| 62 |   |
| 63 | const char* MassUnitNames[int(tMass::NumMassUnits)] =  |
| 64 | {  |
| 65 | "Gram" ,  |
| 66 | "Kilogram" ,  |
| 67 | "Slug"   |
| 68 | };  |
| 69 | }  |
| 70 |   |
| 71 |   |
| 72 | const char* tUnit::GetUnitName(tTime timeUnit)  |
| 73 | {  |
| 74 | if (timeUnit == tTime::Unspecified)  |
| 75 | return nullptr;  |
| 76 |   |
| 77 | return TimeUnitNames[int(timeUnit)];  |
| 78 | }  |
| 79 |   |
| 80 |   |
| 81 | const char* tUnit::GetUnitName(tLength lengthUnit)  |
| 82 | {  |
| 83 | if (lengthUnit == tLength::Unspecified)  |
| 84 | return nullptr;  |
| 85 |   |
| 86 | return LengthUnitNames[int(lengthUnit)];  |
| 87 | }  |
| 88 |   |
| 89 |   |
| 90 | const char* tUnit::GetUnitName(tMass massUnit)  |
| 91 | {  |
| 92 | if (massUnit == tMass::Unspecified)  |
| 93 | return nullptr;  |
| 94 |   |
| 95 | return MassUnitNames[int(massUnit)];  |
| 96 | }  |
| 97 |   |
| 98 |   |
| 99 | tUnit::tTime tUnit::GetTimeUnit(const char* unitName)  |
| 100 | {  |
| 101 | for (int u = 0; u < int(tTime::NumTimeUnits); u++)  |
| 102 | {  |
| 103 | if (!tStd::tStricmp(unitName, TimeUnitNames[u]))  |
| 104 | return tTime(u);  |
| 105 | }  |
| 106 |   |
| 107 | return tTime::Unspecified;  |
| 108 | }  |
| 109 |   |
| 110 |   |
| 111 | tUnit::tLength tUnit::GetLengthUnit(const char* unitName)  |
| 112 | {  |
| 113 | for (int u = 0; u < int(tLength::NumLengthUnits); u++)  |
| 114 | {  |
| 115 | if (!tStd::tStricmp(unitName, LengthUnitNames[u]))  |
| 116 | return tLength(u);  |
| 117 | }  |
| 118 |   |
| 119 | return tLength::Unspecified;  |
| 120 | }  |
| 121 |   |
| 122 |   |
| 123 | tUnit::tMass tUnit::GetMassUnit(const char* unitName)  |
| 124 | {  |
| 125 | for (int u = 0; u < int(tMass::NumMassUnits); u++)  |
| 126 | {  |
| 127 | if (!tStd::tStricmp(unitName, MassUnitNames[u]))  |
| 128 | return tMass(u);  |
| 129 | }  |
| 130 |   |
| 131 | return tMass::Unspecified;  |
| 132 | }  |
| 133 | |