QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
Related Functions | List of all members
Quantity Class Reference

Amount of a commodity. More...

#include <quantity.hpp>

+ Collaboration diagram for Quantity:

Public Member Functions

Constructors
 Quantity ()=default
 
 Quantity (CommodityType commodityType, UnitOfMeasure unitOfMeasure, Real amount)
 
Inspectors
const CommodityTypecommodityType () const
 
const UnitOfMeasureunitOfMeasure () const
 
Real amount () const
 
Quantity rounded () const
 
Quantity arithmetics

See below for non-member functions and for settings which determine the behavior of the operators.

Quantity operator+ () const
 
Quantity operator- () const
 
Quantityoperator+= (const Quantity &)
 
Quantityoperator-= (const Quantity &)
 
Quantityoperator*= (Real)
 
Quantityoperator/= (Real)
 

Related Functions

(Note that these are not member functions.)

Quantity operator+ (const Quantity &, const Quantity &)
 
Quantity operator- (const Quantity &, const Quantity &)
 
Quantity operator* (const Quantity &, Real)
 
Quantity operator* (Real, const Quantity &)
 
Quantity operator/ (const Quantity &, Real)
 
Real operator/ (const Quantity &, const Quantity &)
 
bool operator== (const Quantity &, const Quantity &)
 
bool operator!= (const Quantity &, const Quantity &)
 
bool operator< (const Quantity &, const Quantity &)
 
bool operator<= (const Quantity &, const Quantity &)
 
bool operator> (const Quantity &, const Quantity &)
 
bool operator>= (const Quantity &, const Quantity &)
 
bool close (const Quantity &, const Quantity &, Size n=42)
 
bool close_enough (const Quantity &, const Quantity &, Size n=42)
 

Conversion settings

These parameters are used for combining quantity amounts in different currencies

enum  ConversionType { NoConversion , BaseUnitOfMeasureConversion , AutomatedConversion }
 
static ConversionType conversionType = Quantity::NoConversion
 
static UnitOfMeasure baseUnitOfMeasure = UnitOfMeasure()
 
CommodityType commodityType_
 
UnitOfMeasure unitOfMeasure_
 
Real amount_ = 0.0
 
std::ostream & operator<< (std::ostream &, const Quantity &)
 

Detailed Description

Amount of a commodity.

Definition at line 34 of file quantity.hpp.

Member Enumeration Documentation

◆ ConversionType

Enumerator
NoConversion 

do not perform conversions

BaseUnitOfMeasureConversion 

convert both operands to the base unitOfMeasure before converting

AutomatedConversion 

return the result in the unitOfMeasure of the first operand

Definition at line 67 of file quantity.hpp.

Constructor & Destructor Documentation

◆ Quantity() [1/2]

Quantity ( )
default
+ Here is the caller graph for this function:

◆ Quantity() [2/2]

Quantity ( CommodityType  commodityType,
UnitOfMeasure  unitOfMeasure,
Real  amount 
)

Definition at line 124 of file quantity.hpp.

Member Function Documentation

◆ commodityType()

const CommodityType & commodityType ( ) const

Definition at line 128 of file quantity.hpp.

+ Here is the caller graph for this function:

◆ unitOfMeasure()

const UnitOfMeasure & unitOfMeasure ( ) const

Definition at line 132 of file quantity.hpp.

+ Here is the caller graph for this function:

◆ amount()

Real amount ( ) const

Definition at line 136 of file quantity.hpp.

+ Here is the caller graph for this function:

◆ rounded()

Quantity rounded ( ) const

Definition at line 140 of file quantity.hpp.

+ Here is the call graph for this function:

◆ operator+()

Quantity operator+ ( ) const

Definition at line 146 of file quantity.hpp.

◆ operator-()

Quantity operator- ( ) const

Definition at line 150 of file quantity.hpp.

+ Here is the call graph for this function:

◆ operator+=()

Quantity & operator+= ( const Quantity m)

Definition at line 50 of file quantity.cpp.

◆ operator-=()

Quantity & operator-= ( const Quantity m)

Definition at line 68 of file quantity.cpp.

◆ operator*=()

Quantity & operator*= ( Real  x)

Definition at line 154 of file quantity.hpp.

◆ operator/=()

Quantity & operator/= ( Real  x)

Definition at line 159 of file quantity.hpp.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const Quantity quantity 
)
friend

Definition at line 202 of file quantity.cpp.

◆ operator+()

Quantity operator+ ( const Quantity ,
const Quantity  
)
related

Definition at line 165 of file quantity.hpp.

◆ operator-()

Quantity operator- ( const Quantity ,
const Quantity  
)
related

Definition at line 171 of file quantity.hpp.

◆ operator*() [1/2]

Quantity operator* ( const Quantity ,
Real   
)
related

Definition at line 177 of file quantity.hpp.

◆ operator*() [2/2]

Quantity operator* ( Real  ,
const Quantity  
)
related

Definition at line 183 of file quantity.hpp.

◆ operator/() [1/2]

Quantity operator/ ( const Quantity ,
Real   
)
related

Definition at line 187 of file quantity.hpp.

◆ operator/() [2/2]

Real operator/ ( const Quantity ,
const Quantity  
)
related

Definition at line 86 of file quantity.cpp.

+ Here is the call graph for this function:

◆ operator==()

bool operator== ( const Quantity ,
const Quantity  
)
related

Definition at line 105 of file quantity.cpp.

+ Here is the call graph for this function:

◆ operator!=()

bool operator!= ( const Quantity ,
const Quantity  
)
related

Definition at line 193 of file quantity.hpp.

◆ operator<()

bool operator< ( const Quantity ,
const Quantity  
)
related

Definition at line 125 of file quantity.cpp.

+ Here is the call graph for this function:

◆ operator<=()

bool operator<= ( const Quantity ,
const Quantity  
)
related

Definition at line 144 of file quantity.cpp.

+ Here is the call graph for this function:

◆ operator>()

bool operator> ( const Quantity ,
const Quantity  
)
related

Definition at line 197 of file quantity.hpp.

◆ operator>=()

bool operator>= ( const Quantity ,
const Quantity  
)
related

Definition at line 201 of file quantity.hpp.

◆ close()

bool close ( const Quantity ,
const Quantity ,
Size  n = 42 
)
related

Definition at line 163 of file quantity.cpp.

+ Here is the call graph for this function:

◆ close_enough()

bool close_enough ( const Quantity ,
const Quantity ,
Size  n = 42 
)
related

Definition at line 182 of file quantity.cpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ conversionType

Definition at line 76 of file quantity.hpp.

◆ baseUnitOfMeasure

UnitOfMeasure baseUnitOfMeasure = UnitOfMeasure()
static

Definition at line 77 of file quantity.hpp.

◆ commodityType_

CommodityType commodityType_
private

Definition at line 82 of file quantity.hpp.

◆ unitOfMeasure_

UnitOfMeasure unitOfMeasure_
private

Definition at line 83 of file quantity.hpp.

◆ amount_

Real amount_ = 0.0
private

Definition at line 84 of file quantity.hpp.