API Documentation
Loading...
Searching...
No Matches
Unit.h
Go to the documentation of this file.
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/TranslatedString.h>
4#include <NDEVR/StringStream.h>
5#include <NDEVR/Angle.h>
6namespace NDEVR
7{
8 class TranslatedString;
9 enum class UnitType
10 {
12 , e_angle
17 , e_volume
18 , e_weight
19 , e_speed
22 , e_time
23 , e_force
24 , e_ratio
25 , e_lat_lon
26 };
28 {
29 const String name;
31 TranslatedString axis_name_ids[4];
32 TranslatedString axis_abbreviations[4];
33 Unit(String name, TranslatedString translated_id);
34 virtual ~Unit() = default;
35
36 [[nodiscard]] virtual fltp08 convertToUnit(const fltp08& program_space, const uint01 direction = X) const = 0;
37 [[nodiscard]] virtual fltp08 convertFromUnit(const fltp08& unit_space, const uint01 direction = X) const = 0;
38 [[nodiscard]] virtual Vertex<3, fltp08> convertToUnit(const Vertex<3, fltp08>& program_space) const = 0;
39 [[nodiscard]] virtual Vertex<3, fltp08> convertFromUnit(const Vertex<3, fltp08>& unit_space) const = 0;
40 [[nodiscard]] virtual Ray<3, fltp08> convertToUnit(const Ray<3, fltp08>& program_space) const = 0;
41 [[nodiscard]] virtual Ray<3, fltp08> convertFromUnit(const Ray<3, fltp08>& unit_space) const = 0;
42 [[nodiscard]] virtual const TranslatedString& abbreviation(uint01 direction = X) const = 0;
43 template<class t_angle_type>
44 [[nodiscard]] String convertToString(const Angle<t_angle_type>& program_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv = true, uint01 direction = X) const
45 {
46 return convertToString(program_space.template internal<false>(), add_comma, min_decimals, max_decimals, min_digits, include_abv, direction);
47 }
48 template<class t_angle_type>
49 [[nodiscard]] fltp08 convertToUnit(const Angle<t_angle_type>& program_space, uint01 direction = X) const
50 {
51 return convertToUnit(program_space.template internal<false>(), direction);
52 }
53 template<class t_angle_type>
54 [[nodiscard]] Angle<t_angle_type> convertAngleFromUnit(const fltp08& unit_space, uint01 direction = X) const
55 {
56 return Angle<t_angle_type>(INTERNAL_ANGLE, convertFromUnit(unit_space, direction));
57 }
58 [[nodiscard]] virtual String convertToString(const fltp08& program_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv = true, uint01 direction = X) const
59 {
60 return toString(convertToUnit(program_space, direction), add_comma, min_decimals, max_decimals, min_digits, include_abv, direction);
61 }
62 [[nodiscard]] String toString(const fltp08& unit_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv = true, uint01 direction = X) const
63 {
64 String s;
65 toString(s, unit_space, add_comma, min_decimals, max_decimals, min_digits, include_abv, direction);
66 return s;
67 }
68
69 virtual void toString(String& string, const fltp08& unit_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv = true, uint01 direction = X) const
70 {
71 StringStream<fltp08>::toString(unit_space, string);
72 if (add_comma || min_decimals > 0 || max_decimals <= string.size() || min_digits > 0)
73 string = string.formatNumberString(add_comma, min_decimals, max_decimals, min_digits);
74 if (include_abv)
75 string += abbreviation(direction).translation();
76 }
77
78 [[nodiscard]] virtual fltp08 convertFromString(const String& unit_string, uint01 direction = X) const
79 {
80 return convertFromUnit(fromString(unit_string, direction), direction);
81 }
82 [[nodiscard]] virtual fltp08 fromString(const String& unit_string, uint01 direction = X) const
83 {
84 UNUSED(direction);
85 return unit_string.getAs<fltp08>();
86 }
87
88 [[nodiscard]] TranslatedString translatedName() const;
89 [[nodiscard]] virtual TranslatedString translatedAxisName(uint04 index) const;
90 [[nodiscard]] virtual String getNextPreferredSeparator(const String& current_string, uint01 direction = X) const;
91
92 [[nodiscard]] virtual String toFormula(const String& unit_string, uint01 direction = X) const;
93 [[nodiscard]] virtual fltp08 epsilon(fltp08 value, uint01 direction = X) const;
94
95
96 [[nodiscard]] virtual const Unit* subUnit(uint01 direction) const = 0;
97 [[nodiscard]] virtual Matrix<fltp08> matrix() const = 0;
98 bool operator==(const Unit& other) const
99 {
100 return other.matrix() == matrix() && other.name == name;
101 }
102 [[nodiscard]] virtual Unit* clone() const;
103 [[nodiscard]] virtual Unit* clone(const String& new_name, const TranslatedString& new_display_name) const = 0;
104 protected:
105 static Buffer<String> OperatorSplit(const String& string);
106 };
108
109
110}
#define NDEVR_BASE_API
Definition DLLInfo.h:78
#define UNUSED(expr)
Definition BaseValues.hpp:433
Stores an angle in an optimized format.
Definition StringStream.h:352
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition Matrix.hpp:173
Definition Vertex.hpp:341
Definition String.h:40
t_type getAs() const
Definition String.h:334
Definition StringStream.h:62
Definition TranslatedString.h:9
A vertex.
Definition Vertex.hpp:54
Definition ACIColor.h:37
UnitType
Definition Unit.h:10
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
@ INTERNAL_ANGLE
Definition Angle.h:67
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition Unit.h:28
virtual const Unit * subUnit(uint01 direction) const =0
virtual Vertex< 3, fltp08 > convertFromUnit(const Vertex< 3, fltp08 > &unit_space) const =0
virtual fltp08 convertFromUnit(const fltp08 &unit_space, const uint01 direction=X) const =0
virtual Matrix< fltp08 > matrix() const =0
const TranslatedString translated_id
Definition Unit.h:30
String toString(const fltp08 &unit_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv=true, uint01 direction=X) const
Definition Unit.h:62
virtual const TranslatedString & abbreviation(uint01 direction=X) const =0
virtual Unit * clone(const String &new_name, const TranslatedString &new_display_name) const =0
fltp08 convertToUnit(const Angle< t_angle_type > &program_space, uint01 direction=X) const
Definition Unit.h:49
virtual Ray< 3, fltp08 > convertToUnit(const Ray< 3, fltp08 > &program_space) const =0
virtual void toString(String &string, const fltp08 &unit_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv=true, uint01 direction=X) const
Definition Unit.h:69
virtual fltp08 convertToUnit(const fltp08 &program_space, const uint01 direction=X) const =0
bool operator==(const Unit &other) const
Definition Unit.h:98
virtual String convertToString(const fltp08 &program_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv=true, uint01 direction=X) const
Definition Unit.h:58
virtual fltp08 convertFromString(const String &unit_string, uint01 direction=X) const
Definition Unit.h:78
String convertToString(const Angle< t_angle_type > &program_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv=true, uint01 direction=X) const
Definition Unit.h:44
virtual Vertex< 3, fltp08 > convertToUnit(const Vertex< 3, fltp08 > &program_space) const =0
virtual fltp08 fromString(const String &unit_string, uint01 direction=X) const
Definition Unit.h:82
virtual ~Unit()=default
const String name
Definition Unit.h:29
virtual Ray< 3, fltp08 > convertFromUnit(const Ray< 3, fltp08 > &unit_space) const =0
Angle< t_angle_type > convertAngleFromUnit(const fltp08 &unit_space, uint01 direction=X) const
Definition Unit.h:54