GyotoConverters.h
Go to the documentation of this file.
/*
Copyright 2011-2016 Thibaut Paumard
This file is part of Gyoto.
Gyoto is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gyoto is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GyotoConverters_H_
#define __GyotoConverters_H_
#include <GyotoUtils.h>
#include <GyotoSmartPointer.h>
#ifdef HAVE_UDUNITS
#include <udunits2.h>
#endif
#include <string>
#include <sstream>
namespace Gyoto {
namespace Metric {
class Generic;
}
namespace Units {
#ifdef HAVE_UDUNITS
class Unit;
class Converter;
ut_system * getSystem();
#endif
void Init();
double ToMeters(double value, const std::string &unit,
const Gyoto::SmartPointer<Gyoto::Metric::Generic> &gg=NULL);
double FromMeters(double value, const std::string &unit,
const Gyoto::SmartPointer<Gyoto::Metric::Generic> &gg=NULL);
double ToSeconds(double value, const std::string &unit,
const Gyoto::SmartPointer<Gyoto::Metric::Generic> &gg=NULL);
double FromSeconds(double value, const std::string &unit,
const Gyoto::SmartPointer<Gyoto::Metric::Generic> &gg=NULL);
double ToKilograms(double value, const std::string & unit);
double FromKilograms(double value, const std::string & unit);
double ToGeometrical(double value, const std::string & unit,
const Gyoto::SmartPointer<Gyoto::Metric::Generic> & gg);
double FromGeometrical(double value, const std::string & unit,
const Gyoto::SmartPointer<Gyoto::Metric::Generic> & gg);
double ToGeometricalTime(double value, const std::string & unit,
const Gyoto::SmartPointer<Gyoto::Metric::Generic> & gg);
double FromGeometricalTime(double value, const std::string & unit,
const Gyoto::SmartPointer<Gyoto::Metric::Generic> &gg);
double ToHerz(double value, const std::string &unit);
double FromHerz(double value, const std::string &unit);
# ifdef HAVE_UDUNITS
bool areConvertible(const Unit &unit1, const Unit &unit2);
# endif
}
}
#ifdef HAVE_UDUNITS
class Gyoto::Units::Unit : public Gyoto::SmartPointee {
friend class Gyoto::SmartPointer<Gyoto::Units::Unit>;
friend class Gyoto::Units::Converter;
private:
ut_unit * unit_;
std::string kind_;
public:
Unit(const std::string &unit);
Unit(char const * const unit);
~Unit();
double To (double val, const Unit &from_unit);
double From (double val, const Unit &to_unit);
operator std::string() const ;
operator ut_unit*() const ;
};
class Gyoto::Units::Converter : public Gyoto::SmartPointee {
friend class Gyoto::SmartPointer<Gyoto::Units::Converter>;
private:
cv_converter * converter_;
public:
Converter();
Converter(const Gyoto::Units::Unit& from,
const Gyoto::Units::Unit& to);
~Converter();
void reset();
void reset(const Gyoto::Units::Unit& from,
const Gyoto::Units::Unit& to);
double operator()(double value) const ;
};
#endif
#endif
GyotoSmartPointer.h
Reference-counting pointers.
GyotoUtils.h
GYOTO utilities.
Gyoto::Metric::Generic
Base class for metrics.
Definition GyotoMetric.h:162
Gyoto::SmartPointee
Can be pointed to by a SmartPointer.
Definition GyotoSmartPointer.h:81
Gyoto::SmartPointer
Pointers performing reference counting.
Definition GyotoSmartPointer.h:135
Gyoto::Units::Converter
Wrapper around ut_converter from udunits.
Definition GyotoConverters.h:472
Gyoto::Units::Converter::converter_
cv_converter * converter_
Underlying ut_converter object from udunits.
Definition GyotoConverters.h:475
Gyoto::Units::Converter::reset
void reset()
Reset to trivial Converter (Converter()(x)==x).
Gyoto::Units::Converter::Converter
Converter()
Construct trivial Converter (Converter()(x)==x).
Gyoto::Units::Unit
Wrapper around ut_unit from udunits.
Definition GyotoConverters.h:403
Gyoto::Units::Unit::From
double From(double val, const Unit &to_unit)
Convert from Unit.
Gyoto::Units::Unit::unit_
ut_unit * unit_
the underlying ut_unit (from udunits)
Definition GyotoConverters.h:407
Gyoto::Units::Unit::To
double To(double val, const Unit &from_unit)
Convert to Unit.
Gyoto::Units::Unit::kind_
std::string kind_
the string used to instantiate this unit
Definition GyotoConverters.h:408
Gyoto::Units::Unit::Unit
Unit(const std::string &unit)
Build Unit described by string.
Gyoto::Metric
Access to metrics.
Definition GyotoAstrobj.h:47
Gyoto::Units
Units-related classes and functions.
Definition GyotoConverters.h:98
Gyoto::Units::FromSeconds
double FromSeconds(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
Convert to arbitrary time unit from seconds.
Gyoto::Units::ToGeometricalTime
double ToGeometricalTime(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
Convert from arbitrary time unit to geometrical units.
Gyoto::Units::ToGeometrical
double ToGeometrical(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
Convert from arbitrary length unit to geometrical units.
Gyoto::Units::areConvertible
bool areConvertible(const Unit &unit1, const Unit &unit2)
Is it possible to convert between unit1 and unit2?
Gyoto::Units::getSystem
ut_system * getSystem()
Retrieve the unit system used in all of Gyoto.
Gyoto::Units::FromKilograms
double FromKilograms(double value, const std::string &unit)
Convert to arbitrary mass unit from kilograms.
Gyoto::Units::FromGeometricalTime
double FromGeometricalTime(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
Convert to arbitrary time unit from geometrical units.
Gyoto::Units::FromGeometrical
double FromGeometrical(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
Convert to arbitrary length unit from geometrical units.
Gyoto::Units::FromHerz
double FromHerz(double value, const std::string &unit)
Convert to arbitrary frequency unit from Herz.
Gyoto::Units::ToSeconds
double ToSeconds(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
Convert from arbitrary time unit to seconds.
Gyoto::Units::ToMeters
double ToMeters(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
Convert from arbitrary length unit to meters.
Gyoto::Units::FromMeters
double FromMeters(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
Convert to arbitrary length unit from meters.
Gyoto::Units::ToKilograms
double ToKilograms(double value, const std::string &unit)
Convert from arbitrary mass unit to kilograms.
Gyoto::Units::Init
void Init()
Load and initialize all (non-context-sensitive) units.
Gyoto::Units::ToHerz
double ToHerz(double value, const std::string &unit)
Convert from arbitrary frequency unit to Herz.
Gyoto
Namespace for the Gyoto library.
Definition GyotoAstrobj.h:44