Pecunia 0.9.0-alpha.22
Library using the ISO-4217 currency standard & a fixed monetary unit size
Loading...
Searching...
No Matches
pecunia::MoneyParts Class Reference

Represents the components of a monetary value separated into major, minor, sub-minor units and its associated currency. More...

#include <MoneyParts.hpp>

Collaboration diagram for pecunia::MoneyParts:

Public Member Functions

PECUNIA_EXPORT MoneyParts ()
 Constructs an empty object with default initialised values.
 
PECUNIA_EXPORT MoneyParts (const Currency code, const MajorUnit major, const std::optional< MinorUnit > minorOnly, const MinorUnit subMinor=0)
 Full initialisation constructor that fully initialises the object.
 
PECUNIA_EXPORT const Currencycode () const noexcept
 Retrieves the currency code of the monetary value.
 
PECUNIA_EXPORT const MajorUnit & full () const noexcept
 Retrieves the full monetary value represented in its major unit including all minor components.
 
PECUNIA_EXPORT const MajorUnit & major () const noexcept
 Retrieves the major unit part of the monetary value.
 
PECUNIA_EXPORT const std::optional< MinorUnit > & minorOnly () const noexcept
 Retrieves the minor-only part of a monetary value, excluding other components.
 
PECUNIA_EXPORT const MinorUnit & minorWithSub () const noexcept
 Retrieves the combined value of the minor and sub-minor units.
 
PECUNIA_EXPORT const MinorUnit & subMinor () const noexcept
 Retrieves the sub-minor unit associated with the monetary value. This provides fine-grained detail of the monetary amount, particularly when precision to the smallest unit (e.g., fractional cents) is required.
 

Friends

class Money
 

Detailed Description

Represents the components of a monetary value separated into major, minor, sub-minor units and its associated currency.

It is designed to facilitate the manipulation and representation of complex monetary values by providing segmented access to the major, minor, and sub-minor components, along with the currency. It is primarily used for scenarios requiring precise control and interpretation of monetary values, formatting, etc.

Constructor & Destructor Documentation

◆ MoneyParts() [1/2]

PECUNIA_EXPORT pecunia::MoneyParts::MoneyParts ( )

Constructs an empty object with default initialised values.

This constructor is primarily used to create an instance with zero values for all its member properties, and a default currency code of XXX, usually as a placeholder or initial state.

◆ MoneyParts() [2/2]

PECUNIA_EXPORT pecunia::MoneyParts::MoneyParts ( const Currency code,
const MajorUnit major,
const std::optional< MinorUnit > minorOnly,
const MinorUnit subMinor = 0 )

Full initialisation constructor that fully initialises the object.

Exceptions
InvalidArgumentWhen the monetary value does not support minor units and minor units are supplied.
Parameters
codeThe currency of the monetary value.
majorThe major monetary value.
minorOnlyThe minor monetary value, if the currency supports it.
subMinorThe sub-minor monetary value.

Member Function Documentation

◆ code()

PECUNIA_EXPORT const Currency & pecunia::MoneyParts::code ( ) const
nodiscardnoexcept

Retrieves the currency code of the monetary value.

Returns
The currency code of the monetary value, e.g. USD, GBP, EUR, etc.

◆ full()

PECUNIA_EXPORT const MajorUnit & pecunia::MoneyParts::full ( ) const
nodiscardnoexcept

Retrieves the full monetary value represented in its major unit including all minor components.

This method provides access to the total monetary value as represented in the major unit of the currency, incorporating all minor and sub-minor units.

Returns
The full monetary value in the form MajorMinorSub-minor.

◆ major()

PECUNIA_EXPORT const MajorUnit & pecunia::MoneyParts::major ( ) const
nodiscardnoexcept

Retrieves the major unit part of the monetary value.

This method is used to extract only the integral, major unit component of a monetary value, excluding any minor or sub-minor parts.

Returns
The major unit value of this monetary object.

◆ minorOnly()

PECUNIA_EXPORT const std::optional< MinorUnit > & pecunia::MoneyParts::minorOnly ( ) const
nodiscardnoexcept

Retrieves the minor-only part of a monetary value, excluding other components.

Returns
The minor unit of the monetary value, if it exists, null when it does not.

◆ minorWithSub()

PECUNIA_EXPORT const MinorUnit & pecunia::MoneyParts::minorWithSub ( ) const
nodiscardnoexcept

Retrieves the combined value of the minor and sub-minor units.

This method provides access to the aggregated minor and sub-minor components of a monetary value.

Returns
The combined value of minor and sub-minor units in the form MinorSub-minor.

◆ subMinor()

PECUNIA_EXPORT const MinorUnit & pecunia::MoneyParts::subMinor ( ) const
nodiscardnoexcept

Retrieves the sub-minor unit associated with the monetary value. This provides fine-grained detail of the monetary amount, particularly when precision to the smallest unit (e.g., fractional cents) is required.

Returns
The sub-minor unit of the monetary value.

Friends And Related Symbol Documentation

◆ Money

friend class Money
friend