25 #ifndef SRC_UNIT_UNIT_H_ 26 #define SRC_UNIT_UNIT_H_ 35 float convertToPrimaryUnits(
float value) {
38 float convertFromPrimaryUnits(
float value) {
45 virtual string getName() = 0;
46 virtual string getAbbreviation() = 0;
51 virtual IUnit& getPrimaryUnit() = 0;
52 virtual vector<IUnit *>& getSecondaryUnits() = 0;
65 string getAbbreviation() {
77 string getAbbreviation() {
82 vector<IUnit *> secondary_units;
83 IUnit& getPrimaryUnit() {
86 vector<IUnit *>& getSecondaryUnits() {
87 return secondary_units;
98 string getAbbreviation() {
103 vector<IUnit *> secondary_units;
104 IUnit& getPrimaryUnit() {
108 vector<IUnit *>& getSecondaryUnits() {
109 return secondary_units;
119 return *Distance::p_unit_family;
128 string getAbbreviation() {
134 static constexpr
float METERS_PER_INCH = .0254f;
135 static constexpr
float INCHES_PER_METER = 1.0f / METERS_PER_INCH;
140 string getAbbreviation() {
143 float convertToPrimaryUnits(
float value) {
144 return value * METERS_PER_INCH;
146 float convertFromPrimaryUnits(
float value) {
147 return value * INCHES_PER_METER;
152 static constexpr
float INCHES_PER_FOOT = 12.0f;
153 static constexpr
float METERS_PER_FOOT = Inches::METERS_PER_INCH
155 static constexpr
float FEET_PER_METER = 1.0f / METERS_PER_FOOT;
160 string getAbbreviation() {
163 float convertToPrimaryUnits(
float value) {
164 return value * METERS_PER_FOOT;
166 float convertFromPrimaryUnits(
float value) {
167 return value * FEET_PER_METER;
172 static constexpr
float MILLIMETERS_PER_METER = 1000.0f;
173 static constexpr
float METERS_PER_MILLIMETER = 1.0f / 1000.0f;
176 return "Millimeters";
178 string getAbbreviation() {
181 float convertToPrimaryUnits(
float value) {
182 return value * METERS_PER_MILLIMETER;
184 float convertFromPrimaryUnits(
float value) {
185 return value * MILLIMETERS_PER_METER;
190 static constexpr
float CENTIMETERS_PER_METER = 100.0f;
191 static constexpr
float METERS_PER_CENTIMETER = 1.0f / 100.0f;
194 return "Centimeters";
196 string getAbbreviation() {
199 float convertToPrimaryUnits(
float value) {
200 return value * METERS_PER_CENTIMETER;
202 float convertFromPrimaryUnits(
float value) {
203 return value * CENTIMETERS_PER_METER;
212 vector<IUnit *> secondary_units;
214 IUnit& getPrimaryUnit() {
219 secondary_units.push_back(&inches);
220 secondary_units.push_back(&feet);
221 secondary_units.push_back(&millimeters);
222 secondary_units.push_back(¢imeters);
224 vector<IUnit *>& getSecondaryUnits() {
225 return secondary_units;
230 static Angle *p_unit_family;
231 static constexpr
float PI = 3.14159265358979f;
235 return *Angle::p_unit_family;
244 string getAbbreviation() {
252 static constexpr
float RADIANS_TO_DEGREES = (float) (180.0 / Angle::PI);
253 static constexpr
float DEGREES_TO_RADIANS = (float) (Angle::PI / 180.0);
257 string getAbbreviation() {
260 float convertToPrimaryUnits(
float value) {
261 return value * DEGREES_TO_RADIANS;
263 float convertFromPrimaryUnits(
float value) {
264 return value * RADIANS_TO_DEGREES;
271 static constexpr
float DEGREES_IN_HALF_CIRCLE = 180.0f;
275 string getAbbreviation() {
278 float convertToPrimaryUnits(
float value) {
279 return (value - DEGREES_IN_HALF_CIRCLE)
280 * Degrees::DEGREES_TO_RADIANS;
282 float convertFromPrimaryUnits(
float value) {
283 return (value * Degrees::RADIANS_TO_DEGREES)
284 + DEGREES_IN_HALF_CIRCLE;
289 static constexpr
float REVOLUTIONS_TO_RADIANS = (float) (2.0f
291 static constexpr
float RADIANS_TO_REVOLUTIONS = 1.0f
292 / REVOLUTIONS_TO_RADIANS;
294 return "Revolutions";
296 string getAbbreviation() {
299 float convertToPrimaryUnits(
float value) {
300 return value * REVOLUTIONS_TO_RADIANS;
302 float convertFromPrimaryUnits(
float value) {
303 return value * RADIANS_TO_REVOLUTIONS;
308 vector<IUnit *> secondary_units;
312 IUnit& getPrimaryUnit() {
317 secondary_units.push_back(°rees);
318 secondary_units.push_back(&compass);
319 secondary_units.push_back(&revolutions);
321 vector<IUnit *>& getSecondaryUnits() {
322 return secondary_units;
327 static Time *p_unit_family;
332 return *Time::p_unit_family;
338 static constexpr
float SECONDS_TO_NANOSECONDS = (float) (1.0f * 1000000000);
339 static constexpr
float NANOSECONDS_TO_SECONDS = (float) (1.0f / 1000000000);
342 return "Nanoseconds";
345 string getAbbreviation() {
349 float convertToPrimaryUnits(
float value) {
350 return value * NANOSECONDS_TO_SECONDS;
353 float convertFromPrimaryUnits(
float value) {
354 return value * SECONDS_TO_NANOSECONDS;
360 static constexpr
float SECONDS_TO_MICROSECONDS = (float) (1.0f * 1000000);
361 static constexpr
float MICROSECONDS_TO_SECONDS = (float) (1.0f / 1000000);
364 return "Microseconds";
367 string getAbbreviation() {
371 float convertToPrimaryUnits(
float value) {
372 return value * MICROSECONDS_TO_SECONDS;
375 float convertFromPrimaryUnits(
float value) {
376 return value * SECONDS_TO_MICROSECONDS;
382 static constexpr
float SECONDS_TO_MILLISECONDS = (float) (1.0f * 1000);
383 static constexpr
float MILLISECONDS_TO_SECONDS = (float) (1.0f / 1000);
386 return "Milliseconds";
389 string getAbbreviation() {
393 float convertToPrimaryUnits(
float value) {
394 return value * MILLISECONDS_TO_SECONDS;
397 float convertFromPrimaryUnits(
float value) {
398 return value * SECONDS_TO_MILLISECONDS;
407 string getAbbreviation() {
413 static constexpr
float HOURS_TO_SECONDS = (float) (60 * 60);
414 static constexpr
float SECONDS_TO_HOURS = (float) (1.0f
419 string getAbbreviation() {
422 float convertToPrimaryUnits(
float value) {
423 return value * HOURS_TO_SECONDS;
425 float convertFromPrimaryUnits(
float value) {
426 return value * SECONDS_TO_HOURS;
431 static constexpr
float MINUTES_TO_SECONDS = (float) (60);
432 static constexpr
float SECONDS_TO_MINUTES = (float) (1.0f
433 / MINUTES_TO_SECONDS);
437 string getAbbreviation() {
440 float convertToPrimaryUnits(
float value) {
441 return value * MINUTES_TO_SECONDS;
443 float convertFromPrimaryUnits(
float value) {
444 return value * SECONDS_TO_MINUTES;
454 IUnit& getPrimaryUnit() {
458 vector<IUnit *> secondary_units;
460 secondary_units.push_back(&hours);
461 secondary_units.push_back(&minutes);
462 secondary_units.push_back(&milliseconds);
463 secondary_units.push_back(µseconds);
464 secondary_units.push_back(&nanoseconds);
467 vector<IUnit *>& getSecondaryUnits() {
468 return secondary_units;
478 return *SecondDerivative::p_unit_family;
483 return "Squared Seconds";
485 string getAbbreviation() {
490 vector<IUnit *> secondary_units;
491 IUnit& getPrimaryUnit() {
492 return seconds_squared;
494 vector<IUnit *>& getSecondaryUnits() {
495 return secondary_units;
505 return *ThirdDerivative::p_unit_family;
511 return "Cubed Seconds";
513 string getAbbreviation() {
518 vector<IUnit *> secondary_units;
519 IUnit& getPrimaryUnit() {
520 return seconds_cubed;
522 vector<IUnit *>& getSecondaryUnits() {
523 return secondary_units;