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

Represents a monetary value in minor units, with associated currency code and sign/affinity. More...

#include <Money.hpp>

Collaboration diagram for pecunia::Minor:

Public Member Functions

 Minor ()
 
 Minor (const Currency &code, const MajorUnit minor=0u, const MinorUnit subMinor=0u)
 Full initialisation constructor for a currency that requires a minor value.
 
 Minor (const Currency &code, const std::optional< MajorUnit > minor, const MinorUnit subMinor=0u)
 Full initialisation constructor representing a monetary value in its associated currency with minor (when supported) and sub-minor units.
 
 Minor (const MajorUnit subMinor, const Currency &code)
 Sub-minor initialisation constructor. This is largely useful for currencies that do not support minor currencies and need to have a negative sub-minor value.
 
Sign affinity () const noexcept
 An accessor to the sign/affinity of the minor currency.
 
Currency code () const noexcept
 Retrieves the currency code associated with the monetary value.
 
std::optional< MinorUnit > minorOnly () const noexcept
 Retrieves the minor unit representation of the monetary value, if available.
 
MajorUnit minorWithSub () const noexcept
 Computes the total monetary value in minor units, including any sub-minor adjustments, based on the stored amount, currency code, and affinity (sign).
 
MinorUnit subMinor () const noexcept
 Returns the sub-minor unit representation of the monetary value. This value represents finer resolution units beneath the primary minor unit of currency.
 

Public Attributes

enum PECUNIA_EXPORT Neither
 The minor value is neither positive nor negative, i.e. zero.
 
enum PECUNIA_EXPORT Positive
 The minor value is positive.
 
enum PECUNIA_EXPORT Sign: std::uint8_t { Negative
 When working only with minor units, this represents the positivity or negativity of a minor value.
 

Detailed Description

Represents a monetary value in minor units, with associated currency code and sign/affinity.

Constructor & Destructor Documentation

◆ Minor() [1/4]

pecunia::Minor::Minor ( )

Default unknown currency constructor.

◆ Minor() [2/4]

pecunia::Minor::Minor ( const MajorUnit subMinor,
const Currency & code )

Sub-minor initialisation constructor. This is largely useful for currencies that do not support minor currencies and need to have a negative sub-minor value.

Parameters
subMinorSpecifies the value for the sub-minor portion of the minor unit.
codeRepresents the currency code associated with the monetary value.

◆ Minor() [3/4]

pecunia::Minor::Minor ( const Currency & code,
const MajorUnit minor = 0u,
const MinorUnit subMinor = 0u )
explicit

Full initialisation constructor for a currency that requires a minor value.

Exceptions
InvalidArgumentThrown if the `minor` value is provided while the currency does not support minor digits.
InvalidArgumentThrown if the `minor` value is /not/ provided while the currency does support minor digits.
OverflowErrorThrown if the `minor` value exceeds the maximum allowable value for the given currency’s minor digits.
OverflowErrorThrown if the `subMinor` value exceeds the maximum allowable sub-minor value.
Parameters
codeThe currency associated with this instance.
minorA value representing the minor unit of the monetary value.
subMinorA value representing the sub-minor unit of the monetary value.

◆ Minor() [4/4]

pecunia::Minor::Minor ( const Currency & code,
const std::optional< MajorUnit > minor,
const MinorUnit subMinor = 0u )

Full initialisation constructor representing a monetary value in its associated currency with minor (when supported) and sub-minor units.

Exceptions
InvalidArgumentThrown if the `minor` value is provided while the currency does not support minor digits.
InvalidArgumentThrown if the `minor` value is /not/ provided while the currency does support minor digits.
OverflowErrorThrown if the `minor` value exceeds the maximum allowable value for the given currency’s minor digits.
OverflowErrorThrown if the `subMinor` value exceeds the maximum allowable sub-minor value.
Parameters
codeThe currency associated with this instance.
minorAn optional value representing the minor unit of the monetary value.
subMinorA value representing the sub-minor unit of the monetary value.

Member Function Documentation

◆ affinity()

Sign pecunia::Minor::affinity ( ) const
nodiscardnoexcept

An accessor to the sign/affinity of the minor currency.

Returns
The affinity/sign of the object.

◆ code()

Currency pecunia::Minor::code ( ) const
nodiscardnoexcept

Retrieves the currency code associated with the monetary value.

Returns
The currency code of the monetary value’s currency.

◆ minorOnly()

std::optional< MinorUnit > pecunia::Minor::minorOnly ( ) const
nodiscardnoexcept

Retrieves the minor unit representation of the monetary value, if available.

Returns
When the currency supports minor units, the minor unit value, or an empty value when it does not.

◆ minorWithSub()

MajorUnit pecunia::Minor::minorWithSub ( ) const
nodiscardnoexcept

Computes the total monetary value in minor units, including any sub-minor adjustments, based on the stored amount, currency code, and affinity (sign).

Returns
The value representing the full monetary amount in minor units, adjusted for sub-minor details and the sign affinity.

◆ subMinor()

MinorUnit pecunia::Minor::subMinor ( ) const
nodiscardnoexcept

Returns the sub-minor unit representation of the monetary value. This value represents finer resolution units beneath the primary minor unit of currency.

Returns
The sub-minor unit equivalent of the monetary value.

Member Data Documentation

◆ Neither

enum PECUNIA_EXPORT pecunia::Minor::Neither

The minor value is neither positive nor negative, i.e. zero.

◆ Positive

enum PECUNIA_EXPORT pecunia::Minor::Positive

The minor value is positive.

◆ Sign

enum PECUNIA_EXPORT pecunia::Minor::Sign
strong

When working only with minor units, this represents the positivity or negativity of a minor value.