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 /**--------------------------------------------------------------------------------------------------
10 \brief A category of unit describing what it relates to. Any category can have some number of units
11 defined which could be used to display or describe the data.
12 **/
31
32 /**--------------------------------------------------------------------------------------------------
33 \brief A definition of how to describe and display data. Units can be of any type.
34 **/
36 {
37 const String name;
39 TranslatedString axis_name_ids[4];
40 TranslatedString axis_abbreviations[4];
41 Unit(String name, TranslatedString translated_id);
42 virtual ~Unit() = default;
43
44 [[nodiscard]] virtual fltp08 convertToUnit(const fltp08& program_space, const uint01 direction = X) const = 0;
45 [[nodiscard]] virtual fltp08 convertFromUnit(const fltp08& unit_space, const uint01 direction = X) const = 0;
46 [[nodiscard]] virtual Vertex<3, fltp08> convertToUnit(const Vertex<3, fltp08>& program_space) const = 0;
47 [[nodiscard]] virtual Vertex<3, fltp08> convertFromUnit(const Vertex<3, fltp08>& unit_space) const = 0;
48 [[nodiscard]] virtual Ray<3, fltp08> convertToUnit(const Ray<3, fltp08>& program_space) const = 0;
49 [[nodiscard]] virtual Ray<3, fltp08> convertFromUnit(const Ray<3, fltp08>& unit_space) const = 0;
50 [[nodiscard]] virtual const TranslatedString& abbreviation(uint01 direction = X) const = 0;
51 template<class t_angle_type>
52 [[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
53 {
54 return convertToString(program_space.template internal<false>(), add_comma, min_decimals, max_decimals, min_digits, include_abv, direction);
55 }
56 template<class t_angle_type>
57 [[nodiscard]] fltp08 convertToUnit(const Angle<t_angle_type>& program_space, uint01 direction = X) const
58 {
59 return convertToUnit(program_space.template internal<false>(), direction);
60 }
61 template<class t_angle_type>
62 [[nodiscard]] Angle<t_angle_type> convertAngleFromUnit(const fltp08& unit_space, uint01 direction = X) const
63 {
64 return Angle<t_angle_type>(INTERNAL_ANGLE, convertFromUnit(unit_space, direction));
65 }
66 [[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
67 {
68 return toString(convertToUnit(program_space, direction), add_comma, min_decimals, max_decimals, min_digits, include_abv, direction);
69 }
70 [[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
71 {
72 String s;
73 toString(s, unit_space, add_comma, min_decimals, max_decimals, min_digits, include_abv, direction);
74 return s;
75 }
76
77 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
78 {
79 StringStream<fltp08>::toString(unit_space, string);
80 if (add_comma || min_decimals > 0 || max_decimals <= string.size() || min_digits > 0)
81 string = string.formatNumberString(add_comma, min_decimals, max_decimals, min_digits);
82 if (include_abv)
83 string += abbreviation(direction).translation();
84 }
85
86 [[nodiscard]] virtual fltp08 convertFromString(const String& unit_string, uint01 direction = X) const
87 {
88 return convertFromUnit(fromString(unit_string, direction), direction);
89 }
90 [[nodiscard]] virtual fltp08 fromString(const String& unit_string, uint01 direction = X) const
91 {
92 UNUSED(direction);
93 return unit_string.getAs<fltp08>();
94 }
95
96 [[nodiscard]] TranslatedString translatedName() const;
97 [[nodiscard]] virtual TranslatedString translatedAxisName(uint04 index) const;
98 [[nodiscard]] virtual String getNextPreferredSeparator(const String& current_string, uint01 direction = X) const;
99
100 [[nodiscard]] virtual String toFormula(const String& unit_string, uint01 direction = X) const;
101 [[nodiscard]] virtual fltp08 epsilon(fltp08 value, uint01 direction = X) const;
102
103
104 [[nodiscard]] virtual const Unit* subUnit(uint01 direction) const = 0;
105 [[nodiscard]] virtual Matrix<fltp08> matrix() const = 0;
106 bool operator==(const Unit& other) const
107 {
108 return other.matrix() == matrix() && other.name == name;
109 }
110 [[nodiscard]] virtual Unit* clone() const;
111 [[nodiscard]] virtual Unit* clone(const String& new_name, const TranslatedString& new_display_name) const = 0;
112 protected:
113 static Buffer<String> OperatorSplit(const String& string);
114 };
116
117
118}
#define NDEVR_BASE_API
Definition DLLInfo.h:57
#define UNUSED(expr)
Definition BaseValues.hpp:409
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
Definition Matrix.hpp:176
Definition Vertex.hpp:317
The core String class for the NDEVR API.
Definition String.h:69
t_type getAs() const
Converts a string into an object. To use this function an object must have overwritten StringStream<t...
Definition String.h:143
Logic for reading or writing to a string or a user friendly, TranslatedString.
Definition StringStream.h:230
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
A vertex or point. A specific type of Vector used primarily for spacial location information.
Definition Vertex.hpp:48
Definition ACIColor.h:37
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
@ INTERNAL_ANGLE
Definition Angle.h:59
UnitCategory
A category of unit describing what it relates to. Any category can have some number of units defined ...
Definition Unit.h:14
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
A definition of how to describe and display data. Units can be of any type.
Definition Unit.h:36
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 String toFormula(const String &unit_string, uint01 direction=X) const
virtual Matrix< fltp08 > matrix() const =0
virtual fltp08 epsilon(fltp08 value, uint01 direction=X) const
const TranslatedString translated_id
Definition Unit.h:38
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:70
virtual const TranslatedString & abbreviation(uint01 direction=X) const =0
virtual Unit * clone(const String &new_name, const TranslatedString &new_display_name) const =0
virtual Unit * clone() const
fltp08 convertToUnit(const Angle< t_angle_type > &program_space, uint01 direction=X) const
Definition Unit.h:57
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:77
virtual fltp08 convertToUnit(const fltp08 &program_space, const uint01 direction=X) const =0
bool operator==(const Unit &other) const
Definition Unit.h:106
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:66
virtual TranslatedString translatedAxisName(uint04 index) const
virtual fltp08 convertFromString(const String &unit_string, uint01 direction=X) const
Definition Unit.h:86
static Buffer< String > OperatorSplit(const String &string)
virtual String getNextPreferredSeparator(const String &current_string, uint01 direction=X) const
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:52
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:90
virtual ~Unit()=default
TranslatedString translatedName() const
const String name
Definition Unit.h:37
virtual Ray< 3, fltp08 > convertFromUnit(const Ray< 3, fltp08 > &unit_space) const =0
Unit(String name, TranslatedString translated_id)
Angle< t_angle_type > convertAngleFromUnit(const fltp08 &unit_space, uint01 direction=X) const
Definition Unit.h:62