NDEVR
API Documentation

Manages a collection of units across multiple data categories with INI persistence. More...

Inheritance diagram for UnitManager:
[legend]
Collaboration diagram for UnitManager:
[legend]

Public Member Functions

 UnitManager ()
 Default constructor.
 UnitManager (const UnitManager &manager)
 Copy constructor.
 ~UnitManager ()
 Destructor.
void addFormatOption (UnitCategory unit_type, const ConstPointer< UnitOption > &format_option)
 Adds a format option to the specified unit category.
void addSpecialUnit (const DynamicPointer< CustomUnit > &custom_unit)
 Adds a custom unit to this manager.
const Buffer< ConstPointer< UnitOption > > & angleUnitOptions () const
 Returns the available angle unit options.
const Buffer< ConstPointer< UnitOption > > & areaUnitOptions () const
 Returns the available area unit options.
bool canBeImperial (const ConstPointer< Unit > &unit) const
 Checks whether the given unit can be classified as imperial.
bool canBeMetric (const ConstPointer< Unit > &unit) const
 Checks whether the given unit can be classified as metric.
void clearUnitOptions (UnitCategory type)
 Clears all unit options for the given category.
const Buffer< ConstPointer< UnitOption > > & coordinateSpaceFormatOptions () const
 Returns the available coordinate space format options.
ConstPointer< UnitdetermineUnit (const Buffer< String > &unit_parts, UnitCategory type) const
 Determines a unit from a set of string parts and a category.
const Buffer< ConstPointer< UnitOption > > & distanceUnitOptions () const
 Returns the available distance unit options.
void finishReadingINI (INIFactory &factory) override
 Finalizes unit state after reading INI data.
void getINI (INIFactory &factory) override
 Serializes or deserializes unit settings to/from an INI factory.
bool hasSpecialUnit (const StringView &name) const
 Checks whether a special unit with the given name exists.
const Buffer< ConstPointer< UnitOption > > & latLonUnitOptions () const
 Returns the available latitude/longitude unit options.
UnitManageroperator= (const UnitManager &manager)
 Copy assignment operator.
ConstPointer< UnitorientationOffsetUnit () const
 Returns the orientation offset unit used for orientation space.
ConstPointer< UnitparseUnit (const StringView &name, UnitCategory type=UnitCategory::e_undefined_unit) const
 Parses a unit from a string name, optionally constrained to a category.
void prepareForINI (INIFactory &factory) override
 Prepares internal state before INI serialization.
void removeFormatOption (UnitCategory unit_type, const ConstPointer< UnitOption > &format_option)
 Removes a format option from the specified unit category.
void setToDefaultImperial (bool preserve_spacial)
 Sets all units to default imperial values.
void setToDefaultMetric (bool preserve_spacial)
 Sets all units to default metric values.
void setUnit (UnitCategory type, const ConstPointer< Unit > &unit)
 Sets the unit for the given category.
void setUnitOptions (UnitCategory type, const Buffer< ConstPointer< Unit > > &options)
 Sets the unit options for the given category from Unit objects.
void setUnitOptions (UnitCategory type, const Buffer< ConstPointer< UnitOption > > &options)
 Sets the unit options for the given category from UnitOption objects.
void setUnitOptionsToDefault (UnitCategory type)
 Resets unit options for the given category to their defaults.
void setupDefaultAngleUnitOptions ()
 Populates the angle unit options with default values.
void setupDefaultAreaOptions ()
 Populates the area unit options with default values.
void setupDefaultCoordinateSpaceOptions ()
 Populates the coordinate space format options with default values.
void setupDefaultDistanceOptions ()
 Populates the distance unit options with default values.
void setupDefaultLatLonOptions ()
 Populates the latitude/longitude unit options with default values.
void setupDefaultVolumeOptions ()
 Populates the volume unit options with default values.
void setupDefaultWeightOptions ()
 Populates the weight unit options with default values.
ConstPointer< UnitspecialUnit (const StringView &name)
 Retrieves a special unit by name.
Resource< ConstPointer< Unit > > & specialUnitResource (const StringView &name)
 Retrieves the resource for a special unit by name.
const Buffer< DynamicPointer< CustomUnit > > & specialUnits () const
 Returns all registered special (custom) units.
void tieToManager (const UnitManager &manager)
 Ties this manager's units to mirror changes from another UnitManager.
ConstPointer< Unitunit (const StringView &name) const
 Looks up a unit by its string name.
ConstPointer< Unitunit (UnitCategory type) const
 Returns the currently selected unit for the given category.
Buffer< ConstPointer< UnitOption > > unitOptions (UnitCategory units) const
 Returns the unit options for the given category.
Resource< ConstPointer< Unit > > & unitResource (UnitCategory type)
 Returns a mutable reference to the unit resource for the given category.
void updateCoordinateBase (const ConstPointer< Unit > &base)
 Updates the coordinate base unit and adjusts related coordinate options.
const Buffer< ConstPointer< UnitOption > > & volumeUnitOptions () const
 Returns the available volume unit options.
const Buffer< ConstPointer< UnitOption > > & weightUnitOptions () const
 Returns the available weight unit options.
Public Member Functions inherited from INIInterface
 INIInterface ()
 Constructs an INIInterface with no default INI file.
 INIInterface (const File &default_ini)
 Constructs an INIInterface with the specified default INI file.
virtual ~INIInterface ()
 Virtual destructor for safe polymorphic cleanup.
virtual bool readINIOptions ()
 Reads INI options from the default INI file.
virtual bool readINIOptions (File &ini_file)
 Reads INI options from the specified INI file.
virtual bool saveINIOptions (bool multithead=false)
 Saves INI options to the default INI file.
virtual bool saveINIOptions (File &ini_file, bool multithead=false)
 Saves INI options to the specified INI file.
void setDefaultINIFile (const File &file)
 Sets the default INI file path used for reading and writing options.
virtual void writeToLog (const StringView &title, LogPtr log, uint01 log_level=2U)
 Writes the current INI options to the specified log with a title.
virtual void writeToLog (LogPtr log, uint01 log_level=2U)
 Writes the current INI options to the specified log.

Static Public Member Functions

static ConstPointer< UnitOptionActiveOption (const Buffer< ConstPointer< UnitOption > > &options, const ConstPointer< Unit > &unit)
 Finds the active option matching the given unit from a buffer of options.
static UnitManagerDefaultManager ()
 Returns the singleton default UnitManager instance.

Public Attributes

Resource< ConstPointer< Unit > > angle_unit
 Unit for describing non-dimensional angles.
Resource< ConstPointer< Unit > > coordinate_space_unit
 Unit for describing dimensional distances.
Resource< ConstPointer< Unit > > distance_unit
 Unit for describing non-dimensional distances.
Resource< ConstPointer< Unit > > lat_lon_unit
 Unit for describing position on the globe.
Resource< ConstPointer< Unit > > orientation_space_unit
 Unit for describing dimensional angles.
Resource< ConstPointer< Unit > > surface_area_unit
 Unit for describing surface areas.
Resource< ConstPointer< Unit > > temperature_unit
 Unit for describing temperature.
Resource< ConstPointer< Unit > > time_unit
 Unit for describing time.
Resource< ConstPointer< Unit > > volume_unit
 Unit for describing volumes.
Resource< ConstPointer< Unit > > weight_unit
 Unit for describing weights.

Static Public Attributes

static Resource< ConstPointer< Unit > > default_angle_unit
 Default program-wide unit for describing non-dimensional angles.
static Resource< ConstPointer< Unit > > default_orientation_space_unit
 Default program-wide unit for describing dimensional angles.

Protected Attributes

Buffer< ConstPointer< UnitOption > > m_angle_unit_options
 All unit options for describing non-dimensional angles.
Buffer< ConstPointer< UnitOption > > m_area_unit_options
 All unit options for describing surface areas.
Buffer< ConstPointer< UnitOption > > m_coordinate_format_options
 All unit options for describing dimensional distances.
Buffer< ConstPointer< UnitOption > > m_distance_unit_options
 All unit options for describing non-dimensional distances.
Buffer< ConstPointer< UnitOption > > m_lat_lon_unit_options
 All unit options for describing position on the globe.
Dictionary< String, ConstPointer< UnitOption > > m_registered_units
 Lookup of all registered unit options by name.
Dictionary< String, DynamicPointer< CustomUnit > > m_special_unit_lookup
 Lookup of special units by name.
Buffer< DynamicPointer< CustomUnit > > m_special_units
 All registered special (custom) units.
ResourceListenerm_tie_to_listener = nullptr
 Listener used when this manager is tied to another manager.
Buffer< ConstPointer< UnitOption > > m_volume_unit_options
 All unit options for describing volumes.
Buffer< ConstPointer< UnitOption > > m_weight_unit_options
 All unit options for describing weights.
Protected Attributes inherited from INIInterface
File m_default_ini
 The default file path used for reading and writing INI options.

Detailed Description

Manages a collection of units across multiple data categories with INI persistence.


See also
Unit, UnitDefinitions, CustomUnit

Definition at line 357 of file UnitManager.h.

Constructor & Destructor Documentation

◆ UnitManager() [1/2]

UnitManager::UnitManager ( )

Default constructor.

Initializes unit resources to default values.

Referenced by UnitManager(), DefaultManager(), operator=(), and tieToManager().

◆ UnitManager() [2/2]

UnitManager::UnitManager ( const UnitManager & manager)

Copy constructor.

Copies unit state from another UnitManager.

Parameters
[in]managerThe UnitManager to copy from.

References UnitManager().

◆ ~UnitManager()

UnitManager::~UnitManager ( )

Destructor.

Cleans up any tied resource listeners.

Member Function Documentation

◆ ActiveOption()

ConstPointer< UnitOption > UnitManager::ActiveOption ( const Buffer< ConstPointer< UnitOption > > & options,
const ConstPointer< Unit > & unit )
staticnodiscard

Finds the active option matching the given unit from a buffer of options.

Parameters
[in]optionsThe buffer of unit options to search.
[in]unitThe unit to match against.
Returns
A const pointer to the matching UnitOption, or null if not found.

References unit().

◆ addFormatOption()

void UnitManager::addFormatOption ( UnitCategory unit_type,
const ConstPointer< UnitOption > & format_option )

Adds a format option to the specified unit category.

Parameters
[in]unit_typeThe unit category to add the option to.
[in]format_optionThe unit option to add.

◆ addSpecialUnit()

void UnitManager::addSpecialUnit ( const DynamicPointer< CustomUnit > & custom_unit)

Adds a custom unit to this manager.

Parameters
[in]custom_unitThe custom unit to register.

◆ angleUnitOptions()

const Buffer< ConstPointer< UnitOption > > & UnitManager::angleUnitOptions ( ) const
inlinenodiscard

Returns the available angle unit options.

Returns
A const reference to the buffer of angle unit options.

Definition at line 469 of file UnitManager.h.

References m_angle_unit_options.

◆ areaUnitOptions()

const Buffer< ConstPointer< UnitOption > > & UnitManager::areaUnitOptions ( ) const
inlinenodiscard

Returns the available area unit options.

Returns
A const reference to the buffer of area unit options.

Definition at line 484 of file UnitManager.h.

References m_area_unit_options.

◆ canBeImperial()

bool UnitManager::canBeImperial ( const ConstPointer< Unit > & unit) const

Checks whether the given unit can be classified as imperial.

Parameters
[in]unitThe unit to check.
Returns
True if the unit is an imperial unit, false otherwise.

References unit().

◆ canBeMetric()

bool UnitManager::canBeMetric ( const ConstPointer< Unit > & unit) const

Checks whether the given unit can be classified as metric.

Parameters
[in]unitThe unit to check.
Returns
True if the unit is a metric unit, false otherwise.

References unit().

◆ clearUnitOptions()

void UnitManager::clearUnitOptions ( UnitCategory type)

Clears all unit options for the given category.

Parameters
[in]typeThe unit category whose options should be cleared.

◆ coordinateSpaceFormatOptions()

const Buffer< ConstPointer< UnitOption > > & UnitManager::coordinateSpaceFormatOptions ( ) const
inlinenodiscard

Returns the available coordinate space format options.

Returns
A const reference to the buffer of coordinate format options.

Definition at line 499 of file UnitManager.h.

References m_coordinate_format_options.

◆ DefaultManager()

UnitManager & UnitManager::DefaultManager ( )
staticnodiscard

Returns the singleton default UnitManager instance.

Returns
A reference to the default UnitManager.

References UnitManager().

◆ determineUnit()

ConstPointer< Unit > UnitManager::determineUnit ( const Buffer< String > & unit_parts,
UnitCategory type ) const
nodiscard

Determines a unit from a set of string parts and a category.

Parameters
[in]unit_partsThe buffer of string components describing the unit.
[in]typeThe unit category to resolve against.
Returns
A const pointer to the determined unit.

◆ distanceUnitOptions()

const Buffer< ConstPointer< UnitOption > > & UnitManager::distanceUnitOptions ( ) const
inlinenodiscard

Returns the available distance unit options.

Returns
A const reference to the buffer of distance unit options.

Definition at line 479 of file UnitManager.h.

References m_distance_unit_options.

◆ finishReadingINI()

void UnitManager::finishReadingINI ( INIFactory & factory)
overridevirtual

Finalizes unit state after reading INI data.

Parameters
[in]factoryThe INI factory that was read from.

Reimplemented from INIInterface.

◆ getINI()

void UnitManager::getINI ( INIFactory & factory)
overridevirtual

Serializes or deserializes unit settings to/from an INI factory.

Parameters
[in]factoryThe INI factory to read from or write to.

Implements INIInterface.

◆ hasSpecialUnit()

bool UnitManager::hasSpecialUnit ( const StringView & name) const

Checks whether a special unit with the given name exists.

Parameters
[in]nameThe string identifier to look up.
Returns
True if a special unit with that name is registered, false otherwise.

◆ latLonUnitOptions()

const Buffer< ConstPointer< UnitOption > > & UnitManager::latLonUnitOptions ( ) const
inlinenodiscard

Returns the available latitude/longitude unit options.

Returns
A const reference to the buffer of lat/lon unit options.

Definition at line 474 of file UnitManager.h.

References m_lat_lon_unit_options.

◆ operator=()

UnitManager & UnitManager::operator= ( const UnitManager & manager)

Copy assignment operator.

Parameters
[in]managerThe UnitManager to copy from.
Returns
A reference to this UnitManager.

References UnitManager().

◆ orientationOffsetUnit()

ConstPointer< Unit > UnitManager::orientationOffsetUnit ( ) const
nodiscard

Returns the orientation offset unit used for orientation space.

Returns
A const pointer to the orientation offset unit.

◆ parseUnit()

ConstPointer< Unit > UnitManager::parseUnit ( const StringView & name,
UnitCategory type = UnitCategory::e_undefined_unit ) const
nodiscard

Parses a unit from a string name, optionally constrained to a category.

Parameters
[in]nameThe string name to parse.
[in]typeThe unit category hint for disambiguation.
Returns
A const pointer to the parsed unit.

References e_undefined_unit.

◆ prepareForINI()

void UnitManager::prepareForINI ( INIFactory & factory)
overridevirtual

Prepares internal state before INI serialization.

Parameters
[in]factoryThe INI factory being prepared for.

Reimplemented from INIInterface.

◆ removeFormatOption()

void UnitManager::removeFormatOption ( UnitCategory unit_type,
const ConstPointer< UnitOption > & format_option )

Removes a format option from the specified unit category.

Parameters
[in]unit_typeThe unit category to remove the option from.
[in]format_optionThe unit option to remove.

◆ setToDefaultImperial()

void UnitManager::setToDefaultImperial ( bool preserve_spacial)

Sets all units to default imperial values.

Parameters
[in]preserve_spacialWhether to preserve the current spatial/coordinate unit.

◆ setToDefaultMetric()

void UnitManager::setToDefaultMetric ( bool preserve_spacial)

Sets all units to default metric values.

Parameters
[in]preserve_spacialWhether to preserve the current spatial/coordinate unit.

◆ setUnit()

void UnitManager::setUnit ( UnitCategory type,
const ConstPointer< Unit > & unit )

Sets the unit for the given category.

Parameters
[in]typeThe unit category to set.
[in]unitThe unit to assign to that category.

References unit().

◆ setUnitOptions() [1/2]

void UnitManager::setUnitOptions ( UnitCategory type,
const Buffer< ConstPointer< Unit > > & options )

Sets the unit options for the given category from Unit objects.

Parameters
[in]typeThe unit category to configure.
[in]optionsThe buffer of units to create options from.

◆ setUnitOptions() [2/2]

void UnitManager::setUnitOptions ( UnitCategory type,
const Buffer< ConstPointer< UnitOption > > & options )

Sets the unit options for the given category from UnitOption objects.

Parameters
[in]typeThe unit category to configure.
[in]optionsThe buffer of unit options to assign.

◆ setUnitOptionsToDefault()

void UnitManager::setUnitOptionsToDefault ( UnitCategory type)

Resets unit options for the given category to their defaults.

Parameters
[in]typeThe unit category to reset.

◆ specialUnit()

ConstPointer< Unit > UnitManager::specialUnit ( const StringView & name)

Retrieves a special unit by name.

Parameters
[in]nameThe string identifier of the special unit.
Returns
A const pointer to the matching unit.

◆ specialUnitResource()

Resource< ConstPointer< Unit > > & UnitManager::specialUnitResource ( const StringView & name)

Retrieves the resource for a special unit by name.

Parameters
[in]nameThe string identifier of the special unit.
Returns
A reference to the unit resource.

◆ specialUnits()

const Buffer< DynamicPointer< CustomUnit > > & UnitManager::specialUnits ( ) const
inlinenodiscard

Returns all registered special (custom) units.

Returns
A const reference to the buffer of custom unit pointers.

Definition at line 504 of file UnitManager.h.

References m_special_units.

◆ tieToManager()

void UnitManager::tieToManager ( const UnitManager & manager)

Ties this manager's units to mirror changes from another UnitManager.

Parameters
[in]managerThe UnitManager to mirror.

References UnitManager().

◆ unit() [1/2]

ConstPointer< Unit > UnitManager::unit ( const StringView & name) const
nodiscard

Looks up a unit by its string name.

Parameters
[in]nameThe name of the unit to find.
Returns
A const pointer to the matching unit, or null if not found.

◆ unit() [2/2]

ConstPointer< Unit > UnitManager::unit ( UnitCategory type) const
nodiscard

Returns the currently selected unit for the given category.

Parameters
[in]typeThe unit category to query.
Returns
A const pointer to the current unit for that category.

Referenced by ActiveOption(), canBeImperial(), canBeMetric(), and setUnit().

◆ unitOptions()

Buffer< ConstPointer< UnitOption > > UnitManager::unitOptions ( UnitCategory units) const
nodiscard

Returns the unit options for the given category.

Parameters
[in]unitsThe unit category to query.
Returns
A buffer of const pointers to the available UnitOption objects.

◆ unitResource()

Resource< ConstPointer< Unit > > & UnitManager::unitResource ( UnitCategory type)
nodiscard

Returns a mutable reference to the unit resource for the given category.

Parameters
[in]typeThe unit category to query.
Returns
A reference to the unit resource.

◆ updateCoordinateBase()

void UnitManager::updateCoordinateBase ( const ConstPointer< Unit > & base)

Updates the coordinate base unit and adjusts related coordinate options.

Parameters
[in]baseThe new base unit for coordinates.

◆ volumeUnitOptions()

const Buffer< ConstPointer< UnitOption > > & UnitManager::volumeUnitOptions ( ) const
inlinenodiscard

Returns the available volume unit options.

Returns
A const reference to the buffer of volume unit options.

Definition at line 489 of file UnitManager.h.

References m_volume_unit_options.

◆ weightUnitOptions()

const Buffer< ConstPointer< UnitOption > > & UnitManager::weightUnitOptions ( ) const
inlinenodiscard

Returns the available weight unit options.

Returns
A const reference to the buffer of weight unit options.

Definition at line 494 of file UnitManager.h.

References m_weight_unit_options.


The documentation for this class was generated from the following file: