API Documentation
Loading...
Searching...
No Matches
UnitManager.h
Go to the documentation of this file.
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/Unit.h>
4#include <NDEVR/SoftwareService.h>
5#include <NDEVR/Resource.h>
6#include <NDEVR/Pointer.h>
7#include <NDEVR/TranslatedString.h>
8#include <NDEVR/Dictionary.h>
9#include <NDEVR/INIInterface.h>
10namespace NDEVR
11{
12 class INIFactory;
13 /**--------------------------------------------------------------------------------------------------
14 \brief A definition of how to describe a particular set of data to a custom category of unit.
15 **/
17 {
18 public:
19 UnitOption(const String& id, const TranslatedString& name)
20 : name(name)
21 , id(id)
22 {}
23 virtual ~UnitOption() {};
24 virtual TranslatedString title() const { return name; };
25 virtual ConstPointer<Unit> unit() const = 0;
26 virtual bool hasMemberUnit(const ConstPointer<Unit>& unit) const = 0;
27 virtual ConstPointer<Unit> unit(const ConstPointer<Unit>&) const { return unit(); };
29
30
33 };
34
35 /**--------------------------------------------------------------------------------------------------
36 \brief A definition of how to describe a particular set of data to a custom category of unit.
37 **/
39 {
40 public:
42 : UnitOption(unit->name, unit->translatedName())
43 , base_unit(unit)
44 , custom_title(custom_title)
45 {}
46 virtual TranslatedString title() const final override;
47 virtual bool hasMemberUnit(const ConstPointer<Unit>& unit) const final override;
48 virtual ConstPointer<Unit> unit() const final override { return base_unit; };
49 virtual Buffer<ConstPointer<UnitOption>> subOptions() const final override { return m_sub_options; };
50 virtual Buffer<ConstPointer<UnitOption>>& editSubOptions() { return m_sub_options; };
53 protected:
55 };
56
57 /**--------------------------------------------------------------------------------------------------
58 \brief A definition of how to describe coordinate data
59 **/
61 {
62 public:
64 : UnitOption(id, name)
65 {}
66 virtual ConstPointer<Unit> unit() const final override;
67 virtual bool hasMemberUnit(const ConstPointer<Unit>& unit) const final override;
68 virtual ConstPointer<Unit> unit(const ConstPointer<Unit>& distance_unit) const final override;
69 };
70 class UnitManager;
71 /**--------------------------------------------------------------------------------------------------
72 Class: BaseValues
73 \brief A program-defined unit that can be used for some specific task different from a program-wide unit.
74 **/
76 {
77 public:
78 CustomUnit(const String& id, const TranslatedString& name, UnitCategory unit_type)
79 : name(name)
80 , id(id)
81 , unit_type(unit_type)
82 {}
83 virtual ~CustomUnit() {};
87 [[nodiscard]] virtual TranslatedString title() const { return name; };
88 [[nodiscard]] virtual Resource<ConstPointer<Unit>>& unitResource(UnitManager& manager) = 0;
89 [[nodiscard]] virtual Buffer<ConstPointer<UnitOption>> options( UnitManager& manager) const = 0;
90 virtual void prepareForINI(const UnitManager&) {};
91 virtual void setupINI(INIFactory&) = 0;
92 virtual void resetToDefault( UnitManager&);
93 virtual void finishReadingINI( UnitManager&) {};
96 [[nodiscard]] virtual ConstPointer<Unit> defaultUnit( UnitManager&) const = 0;
97 };
98 /**--------------------------------------------------------------------------------------------------
99 Class: BaseValues
100 \brief A unit that mirrors another set unit
101 **/
103 {
104 public:
105 ReferenceCustomUnit(const String& id, const TranslatedString& name, UnitCategory unit_type)
106 : CustomUnit(id, name, unit_type)
107 {}
109 [[nodiscard]] virtual Resource<ConstPointer<Unit>>& unitResource(UnitManager& manager) override;
110 [[nodiscard]] virtual Buffer<ConstPointer<UnitOption>> options( UnitManager& manager) const override;
111 virtual void prepareForINI(const UnitManager&) override{}
112 virtual void setupINI(INIFactory&) override {};
113 virtual void resetToDefault( UnitManager&) override;
114 virtual void finishReadingINI( UnitManager&) override {};
115 virtual ConstPointer<Unit> currentUnit( UnitManager& manager) override;
116 [[nodiscard]] virtual ConstPointer<Unit> defaultUnit( UnitManager&) const override;
117 };
118 /**--------------------------------------------------------------------------------------------------
119 Class: BaseValues
120 \brief A program-defined unit that can be used for some specific task different from a program-wide unit.
121 **/
123 {
124 public:
125 BasicCustomUnit(const String& name, const TranslatedString& title, UnitCategory type);
126 virtual void prepareForINI(const UnitManager& manager) override;
127 virtual void setupINI(INIFactory& ini) override;
128 virtual void finishReadingINI(UnitManager& manager) override;
129 [[nodiscard]] virtual TranslatedString title() const override { return m_title; };
130 [[nodiscard]] virtual Resource<ConstPointer<Unit>>& unitResource(UnitManager& manager) override;
131 [[nodiscard]] Buffer<ConstPointer<UnitOption>> options(UnitManager& manager) const override;
132 [[nodiscard]] virtual ConstPointer<Unit> defaultUnit(UnitManager&) const override;
133 protected:
137 };
138
139 /**--------------------------------------------------------------------------------------------------
140 \brief Handles a grouping of units that can describe any number of data categories.
141 **/
143 {
144 public:
146 UnitManager(const UnitManager& manager);
148 void setToDefaultMetric(bool preserve_spacial);
149 void setToDefaultImperial(bool preserve_spacial);
150 void tieToManager(const UnitManager& manager);
151 void getINI(INIFactory& factory) override;
152 void prepareForINI(INIFactory& factory) override;
153 void finishReadingINI(INIFactory& factory) override;
155 [[nodiscard]] static UnitManager& DefaultManager();
156
157 [[nodiscard]] ConstPointer<Unit> unit(UnitCategory type) const;
160 void setUnit(UnitCategory type, const ConstPointer<Unit>& unit);
165
167 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& angleUnitOptions() const { return m_angle_unit_options; };
168 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& latLonUnitOptions() const { return m_lat_lon_unit_options; };
169 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& distanceUnitOptions() const { return m_distance_unit_options; };
170 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& areaUnitOptions() const { return m_area_unit_options; };
171 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& volumeUnitOptions() const { return m_volume_unit_options; };
172 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& weightUnitOptions() const { return m_weight_unit_options; };
173 [[nodiscard]] const Buffer<ConstPointer<UnitOption>>& coordinateSpaceFormatOptions() const { return m_coordinate_format_options; }
174 [[nodiscard]] const Buffer<DynamicPointer<CustomUnit>>& specialUnits() const { return m_special_units; }
178 bool hasSpecialUnit(const String& name) const;
186 [[nodiscard]] ConstPointer<Unit> unit(const String& name) const;
187
188
189 [[nodiscard]] ConstPointer<Unit> parseUnit(const String& name, UnitCategory type = UnitCategory::e_undefined_unit) const;
190 [[nodiscard]] ConstPointer<Unit> determineUnit(const Buffer<String>& unit_parts, UnitCategory type) const;
191
192 bool canBeImperial(const ConstPointer<Unit>& unit) const;
193 bool canBeMetric(const ConstPointer<Unit>& unit) const;
194 void addFormatOption(UnitCategory unit_type, const ConstPointer<UnitOption>& format_option);
195 void removeFormatOption(UnitCategory unit_type, const ConstPointer<UnitOption>& format_option);
198 public:
199 Resource<ConstPointer<Unit>> angle_unit;//unit for describing non-dimensional angles
200 Resource<ConstPointer<Unit>> orientation_space_unit;//unit for describing dimensional angles
201 Resource<ConstPointer<Unit>> distance_unit;//unit for describing non-dimensional distances
202 Resource<ConstPointer<Unit>> coordinate_space_unit;//unit for describing dimensional distances
203 Resource<ConstPointer<Unit>> surface_area_unit;//unit for describing surface areas
204 Resource<ConstPointer<Unit>> volume_unit;//unit for describing volumes
205 Resource<ConstPointer<Unit>> weight_unit;//unit for describing weights
206 Resource<ConstPointer<Unit>> temperature_unit;//unit for describing temperature
207 Resource<ConstPointer<Unit>> lat_lon_unit;//unit for describing position on globe
208 static Resource<ConstPointer<Unit>> default_orientation_space_unit;//default program-wide unit for describing non-dimensional angles
209 protected:
210 Buffer<ConstPointer<UnitOption>> m_angle_unit_options;//all units that are specified for describing non-dimensional angles
211 Buffer<ConstPointer<UnitOption>> m_lat_lon_unit_options;//all units that are specified for describing position on globe
212 Buffer<ConstPointer<UnitOption>> m_distance_unit_options;//all units that are specified for describing non-dimensional distances
213 Buffer<ConstPointer<UnitOption>> m_area_unit_options;//all units that are specified for describing surface areas
214 Buffer<ConstPointer<UnitOption>> m_volume_unit_options;//all units that are specified for describing volumes
215 Buffer<ConstPointer<UnitOption>> m_weight_unit_options;//all units that are specified for describing weights
216 Buffer<ConstPointer<UnitOption>> m_coordinate_format_options;//all units that are specified for describing dimensional distances
220 private:
221 //For INI read/writes
222 String angle_name;
223 String orientation_space_name;
224 String coordinate_space_name;
225 String distance_space_name;
226 String surface_area_name;
227 String volume_name;
228 String temperature_name;
229 String weight_name;
230 String lat_lon_name;
231 protected:
232 ResourceListener* m_tie_to_listener = nullptr;
233 };
234}
#define NDEVR_BASE_API
Definition DLLInfo.h:57
A program-defined unit that can be used for some specific task different from a program-wide unit.
Definition UnitManager.h:123
Buffer< ConstPointer< UnitOption > > options(UnitManager &manager) const override
BasicCustomUnit(const String &name, const TranslatedString &title, UnitCategory type)
String m_ini_unit_name
Definition UnitManager.h:135
Resource< ConstPointer< Unit > > m_unit
Definition UnitManager.h:136
TranslatedString m_title
Definition UnitManager.h:134
virtual ConstPointer< Unit > defaultUnit(UnitManager &) const override
virtual void finishReadingINI(UnitManager &manager) override
virtual Resource< ConstPointer< Unit > > & unitResource(UnitManager &manager) override
virtual void prepareForINI(const UnitManager &manager) override
virtual TranslatedString title() const override
Definition UnitManager.h:129
virtual void setupINI(INIFactory &ini) override
A definition of how to describe a particular set of data to a custom category of unit.
Definition UnitManager.h:39
virtual TranslatedString title() const final override
Buffer< ConstPointer< UnitOption > > m_sub_options
Definition UnitManager.h:54
TranslatedString custom_title
Definition UnitManager.h:52
ConstPointer< Unit > base_unit
Definition UnitManager.h:51
BasicUnitOption(const ConstPointer< Unit > &unit, const TranslatedString &custom_title=TranslatedString())
Definition UnitManager.h:41
virtual Buffer< ConstPointer< UnitOption > > & editSubOptions()
Definition UnitManager.h:50
virtual Buffer< ConstPointer< UnitOption > > subOptions() const final override
Definition UnitManager.h:49
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition GraphicsPipeline.h:42
A definition of how to describe coordinate data.
Definition UnitManager.h:61
CoordinateUnitOption(const String &id, const TranslatedString &name)
Definition UnitManager.h:63
virtual ConstPointer< Unit > unit() const final override
A program-defined unit that can be used for some specific task different from a program-wide unit.
Definition UnitManager.h:76
virtual TranslatedString title() const
Definition UnitManager.h:87
virtual void finishReadingINI(UnitManager &)
Definition UnitManager.h:93
virtual ConstPointer< Unit > currentUnit(UnitManager &manager)
virtual void setupINI(INIFactory &)=0
TranslatedString name
Definition UnitManager.h:84
virtual void resetToDefault(UnitManager &)
virtual ConstPointer< Unit > currentUnit()
String id
Definition UnitManager.h:85
virtual void prepareForINI(const UnitManager &)
Definition UnitManager.h:90
UnitCategory unit_type
Definition UnitManager.h:86
CustomUnit(const String &id, const TranslatedString &name, UnitCategory unit_type)
Definition UnitManager.h:78
virtual ~CustomUnit()
Definition UnitManager.h:83
virtual ConstPointer< Unit > defaultUnit(UnitManager &) const =0
virtual Resource< ConstPointer< Unit > > & unitResource(UnitManager &manager)=0
virtual Buffer< ConstPointer< UnitOption > > options(UnitManager &manager) const =0
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:68
Contains methods for easily reading and writing to an INI file including.
Definition INIInterface.h:45
A unit that mirrors another set unit.
Definition UnitManager.h:103
virtual void finishReadingINI(UnitManager &) override
Definition UnitManager.h:114
virtual void resetToDefault(UnitManager &) override
virtual ConstPointer< Unit > defaultUnit(UnitManager &) const override
ReferenceCustomUnit(const String &id, const TranslatedString &name, UnitCategory unit_type)
Definition UnitManager.h:105
virtual void prepareForINI(const UnitManager &) override
Definition UnitManager.h:111
virtual Resource< ConstPointer< Unit > > & unitResource(UnitManager &manager) override
virtual ~ReferenceCustomUnit()
Definition UnitManager.h:108
virtual void setupINI(INIFactory &) override
Definition UnitManager.h:112
virtual Buffer< ConstPointer< UnitOption > > options(UnitManager &manager) const override
virtual ConstPointer< Unit > currentUnit(UnitManager &manager) override
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Toggle.h:41
A class that can subscribe to any number of Resources which will get updates when the Resource(s) hav...
Definition ResourceListener.h:62
Software Service Managers take a Software service to modify the behavior of the software.
Definition SoftwareService.h:15
The core String class for the NDEVR API.
Definition String.h:69
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
Handles a grouping of units that can describe any number of data categories.
Definition UnitManager.h:143
void setupDefaultLatLonOptions()
ConstPointer< Unit > parseUnit(const String &name, UnitCategory type=UnitCategory::e_undefined_unit) const
UnitManager(const UnitManager &manager)
Resource< ConstPointer< Unit > > weight_unit
Definition UnitManager.h:205
void setupDefaultDistanceOptions()
bool canBeMetric(const ConstPointer< Unit > &unit) const
Resource< ConstPointer< Unit > > distance_unit
Definition UnitManager.h:201
void setupDefaultWeightOptions()
void addFormatOption(UnitCategory unit_type, const ConstPointer< UnitOption > &format_option)
static ConstPointer< UnitOption > ActiveOption(const Buffer< ConstPointer< UnitOption > > &options, const ConstPointer< Unit > &unit)
void setToDefaultImperial(bool preserve_spacial)
ConstPointer< Unit > unit(const String &name) const
void getINI(INIFactory &factory) override
Buffer< ConstPointer< UnitOption > > m_area_unit_options
Definition UnitManager.h:213
void tieToManager(const UnitManager &manager)
Buffer< DynamicPointer< CustomUnit > > m_special_units
Definition UnitManager.h:218
ConstPointer< Unit > determineUnit(const Buffer< String > &unit_parts, UnitCategory type) const
static Resource< ConstPointer< Unit > > default_orientation_space_unit
Definition UnitManager.h:208
void setupDefaultAreaOptions()
Resource< ConstPointer< Unit > > volume_unit
Definition UnitManager.h:204
Buffer< ConstPointer< UnitOption > > m_volume_unit_options
Definition UnitManager.h:214
void setupDefaultCoordinateSpaceOptions()
static UnitManager & DefaultManager()
void updateCoordinateBase(const ConstPointer< Unit > &base)
void setUnitOptions(UnitCategory type, const Buffer< ConstPointer< UnitOption > > &options)
Buffer< ConstPointer< UnitOption > > m_weight_unit_options
Definition UnitManager.h:215
Resource< ConstPointer< Unit > > & unitResource(UnitCategory type)
bool hasSpecialUnit(const String &name) const
UnitManager & operator=(const UnitManager &manager)
ConstPointer< Unit > unit(UnitCategory type) const
ConstPointer< Unit > orientationOffsetUnit() const
const Buffer< ConstPointer< UnitOption > > & coordinateSpaceFormatOptions() const
Definition UnitManager.h:173
const Buffer< ConstPointer< UnitOption > > & latLonUnitOptions() const
Definition UnitManager.h:168
void setUnitOptions(UnitCategory type, const Buffer< ConstPointer< Unit > > &options)
void setToDefaultMetric(bool preserve_spacial)
Buffer< ConstPointer< UnitOption > > m_coordinate_format_options
Definition UnitManager.h:216
void prepareForINI(INIFactory &factory) override
const Buffer< ConstPointer< UnitOption > > & angleUnitOptions() const
Definition UnitManager.h:167
void finishReadingINI(INIFactory &factory) override
Buffer< ConstPointer< UnitOption > > unitOptions(UnitCategory units) const
const Buffer< ConstPointer< UnitOption > > & areaUnitOptions() const
Definition UnitManager.h:170
const Buffer< ConstPointer< UnitOption > > & distanceUnitOptions() const
Definition UnitManager.h:169
const Buffer< ConstPointer< UnitOption > > & volumeUnitOptions() const
Definition UnitManager.h:171
ConstPointer< Unit > specialUnit(const String &name)
void setUnit(UnitCategory type, const ConstPointer< Unit > &unit)
Buffer< ConstPointer< UnitOption > > m_angle_unit_options
Definition UnitManager.h:210
void setupDefaultVolumeOptions()
Resource< ConstPointer< Unit > > coordinate_space_unit
Definition UnitManager.h:202
Resource< ConstPointer< Unit > > surface_area_unit
Definition UnitManager.h:203
const Buffer< ConstPointer< UnitOption > > & weightUnitOptions() const
Definition UnitManager.h:172
Resource< ConstPointer< Unit > > lat_lon_unit
Definition UnitManager.h:207
void removeFormatOption(UnitCategory unit_type, const ConstPointer< UnitOption > &format_option)
Resource< ConstPointer< Unit > > temperature_unit
Definition UnitManager.h:206
Dictionary< String, ConstPointer< UnitOption > > m_registered_units
Definition UnitManager.h:217
Resource< ConstPointer< Unit > > & specialUnitResource(const String &name)
void clearUnitOptions(UnitCategory type)
void addSpecialUnit(const DynamicPointer< CustomUnit > &custom_unit)
Buffer< ConstPointer< UnitOption > > m_distance_unit_options
Definition UnitManager.h:212
void setUnitOptionsToDefault(UnitCategory type)
void setupDefaultAngleUnitOptions()
Resource< ConstPointer< Unit > > angle_unit
Definition UnitManager.h:199
Dictionary< String, DynamicPointer< CustomUnit > > m_special_unit_lookup
Definition UnitManager.h:219
Resource< ConstPointer< Unit > > orientation_space_unit
Definition UnitManager.h:200
const Buffer< DynamicPointer< CustomUnit > > & specialUnits() const
Definition UnitManager.h:174
bool canBeImperial(const ConstPointer< Unit > &unit) const
Buffer< ConstPointer< UnitOption > > m_lat_lon_unit_options
Definition UnitManager.h:211
A definition of how to describe a particular set of data to a custom category of unit.
Definition UnitManager.h:17
virtual TranslatedString title() const
Definition UnitManager.h:24
virtual bool hasMemberUnit(const ConstPointer< Unit > &unit) const =0
TranslatedString name
Definition UnitManager.h:31
String id
Definition UnitManager.h:32
virtual ~UnitOption()
Definition UnitManager.h:23
virtual ConstPointer< Unit > unit() const =0
virtual ConstPointer< Unit > unit(const ConstPointer< Unit > &) const
Definition UnitManager.h:27
UnitOption(const String &id, const TranslatedString &name)
Definition UnitManager.h:19
virtual Buffer< ConstPointer< UnitOption > > subOptions() const
Definition UnitManager.h:28
Definition ACIColor.h:37
UnitCategory
A category of unit describing what it relates to. Any category can have some number of units defined ...
Definition Unit.h:14
A definition of how to describe and display data. Units can be of any type.
Definition Unit.h:36