Gyoto::Units::Converter Class Reference

Wrapper around ut_converter from udunits. More...

`#include <GyotoConverters.h>`

Inheritance diagram for Gyoto::Units::Converter:

## Public Types

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

## Public Member Functions

| Converter ()
| Construct trivial Converter (Converter()(x)==x).
| Converter (const Gyoto::Units::Unit &from, const Gyoto::Units::Unit &to)
| Construct Converter from two Unit.
| ~Converter ()
| Destruct converter, freeing converter_.
void | reset ()
| Reset to trivial Converter (Converter()(x)==x).
void | reset (const Gyoto::Units::Unit &from, const Gyoto::Units::Unit &to)
| Reset to converter from "from" to "to".
double | operator() (double value) const
| Actually convert data.
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

cv_converter * | converter_
| Underlying ut_converter object from udunits.
int | refCount
| Reference counter.
pthread_mutex_t | mutex_
| A mutex.

## Friends

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

## Detailed Description

Wrapper around ut_converter from udunits.

A Gyoto::Units::Converter object is a functor and can be used to convert efficiently between the two units specified at instantiation time:

Gyoto::Units::Unit from_unit ("erg.s-1.cm-2.sr-1.Hz-1"),
to_unit ("mJy/µas²");
double data_in[1000], data_out[1000];
Converter conv(from_unit, to_unit);
for (size_t i=0; i<1000; ++i) data_out[i] = conv(data_in[i]);
Gyoto::Units::Converter::Converter
Converter()
Construct trivial Converter (Converter()(x)==x).
Gyoto::Units::Unit
Wrapper around ut_unit from udunits.
Definition GyotoConverters.h:403

Since std::string cast automatically to Gyoto::Units::Unit object, this is equivalent:

Converter conv("erg.s-1.cm-2.sr-1.Hz-1", "mJy/µas²");
for (size_t i=0; i<1000; ++i) data_out[i] = conv(data_in[i]);

## 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().

## Member Function Documentation

## operator()()

double Gyoto::Units::Converter::operator() | ( | double | value | ) | const

Actually convert data.

The entire Gyoto::Units::Converter class is there just for this operator, which converts value from unit "from" to unit "to" where "from" and "to" are the two Units passed to the constructor Gyoto::Units::Converter::Converter(const Gyoto::Units::Unit& from, const Gyoto::Units::Unit& to).

Parameters

  value | double expressed in Unit from

Returns
  converted value expressed in Unit to

## Member Data Documentation

## mutex_

pthread_mutex_t Gyoto::SmartPointee::mutex_

private inherited

A mutex.

When compiled with libpthread

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

- GyotoConverters.h