Gyoto::Units::Converter Class Reference

Wrapper around ut_converter from udunits. More...

#include <GyotoConverters.h>

Inheritance diagram for Gyoto::Units::Converter:

List of all members.

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.


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 (""),
                    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]);

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

 Converter conv("", "mJy/µas²");
 for (size_t i=0; i<1000; ++i) data_out[i] = conv(data_in[i]);

Member Typedef Documentation

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

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

value double expressed in Unit from
converted value expressed in Unit to

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

Generated on 23 Oct 2019 for Gyoto by  doxygen 1.6.1