Gyoto
Public Types | Public Member Functions | Private Attributes | Friends | List of all members
Gyoto::Units::Unit Class Reference

Wrapper around ut_unit from udunits. More...

#include <GyotoConverters.h>

Inheritance diagram for Gyoto::Units::Unit:
Gyoto::SmartPointee

Public Types

typedef Gyoto::SmartPointer< Gyoto::SmartPointeeSubcontractor_t(Gyoto::FactoryMessenger *, std::vector< std::string > const &)
 A subcontractor builds an object upon order from the Factory. More...
 

Public Member Functions

 Unit (const std::string &unit)
 Build Unit described by string. More...
 
 Unit (char const *const unit)
 Build Unit described by C string. More...
 
 ~Unit ()
 Destructor. More...
 
double To (double val, const Unit &from_unit)
 Convert to Unit. More...
 
double From (double val, const Unit &to_unit)
 Convert from Unit. More...
 
 operator std::string () const
 Cast to string. More...
 
 operator ut_unit * () const
 Cast to ut_unit*. More...
 
void incRefCount ()
 Increment the reference counter. Warning: Don't mess with the counter.
 
int decRefCount ()
 Decrement the reference counter and return current value. Warning: Don't mess with the counter.
 
int getRefCount ()
 Get the current number of references.
 

Private Attributes

ut_unit * unit_
 the underlying ut_unit (from udunits)
 
std::string kind_
 the string used to instantiate this unit
 

Friends

class Gyoto::SmartPointer< Gyoto::Units::Unit >
 
class Gyoto::Units::Converter
 

Detailed Description

Wrapper around ut_unit from udunits.

Gyoto::Units::Unit objects usually cast seamlessly to and from udunits2 ut_unit* and std::string.

Member Typedef Documentation

◆ Subcontractor_t

typedef Gyoto::SmartPointer<Gyoto::SmartPointee> Gyoto::SmartPointee::Subcontractor_t(Gyoto::FactoryMessenger *, std::vector< std::string > const &)
inherited

A subcontractor builds an object upon order from the Factory.

Various classes need to provide a subcontractor to be able to instantiate themselves upon order from the Factory. A subcontractor is a function (often a static member function) which accepts a pointer to a FactoryMessenger as unique parameter, communicates with the Factory using this messenger to read an XML description of the object to build, and returns this objet. SmartPointee::Subcontractor_t* is just generic enough a typedef to cast to and from other subcontractor types: Astrobj::Subcontractor_t, Metric::Subcontractor_t, Spectrum::Subcontractor_t. A subcontractor needs to be registered using the relevant Register() function: Astrobj::Register(), Metric::Register(), Spectrum::Register().

Constructor & Destructor Documentation

◆ Unit() [1/2]

Gyoto::Units::Unit::Unit ( const std::string &  unit)

Build Unit described by string.

Throws a Gyoto::Error if anything goes wrong.

Parameters
unitstring description of the unit, e.g. "mJy/sr2" or "sunmass".

◆ Unit() [2/2]

Gyoto::Units::Unit::Unit ( char const *const  unit)

Build Unit described by C string.

Throws a Gyoto::Error if anything goes wrong.

Parameters
unitchar const * const description of the unit, e.g. "mJy/sr2" or "sunmass".

◆ ~Unit()

Gyoto::Units::Unit::~Unit ( )

Destructor.

Frees unit_.

Member Function Documentation

◆ From()

double Gyoto::Units::Unit::From ( double  val,
const Unit to_unit 
)

Convert from Unit.

Parameters
valdouble to convert
to_unitUnit to which to convert
Returns
value converted to "to_unit".

◆ operator std::string()

Gyoto::Units::Unit::operator std::string ( ) const

Cast to string.

Returns
kind_

◆ operator ut_unit *()

Gyoto::Units::Unit::operator ut_unit * ( ) const

Cast to ut_unit*.

Returns
unit_

◆ To()

double Gyoto::Units::Unit::To ( double  val,
const Unit from_unit 
)

Convert to Unit.

Parameters
valdouble to convert
from_unitUnit from which to convert
Returns
value converted to unit_.

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