Gyoto
GyotoConverters.h
Go to the documentation of this file.
1
61
62/*
63 Copyright 2011-2016 Thibaut Paumard
64
65 This file is part of Gyoto.
66
67 Gyoto is free software: you can redistribute it and/or modify
68 it under the terms of the GNU General Public License as published by
69 the Free Software Foundation, either version 3 of the License, or
70 (at your option) any later version.
71
72 Gyoto is distributed in the hope that it will be useful,
73 but WITHOUT ANY WARRANTY; without even the implied warranty of
74 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75 GNU General Public License for more details.
76
77 You should have received a copy of the GNU General Public License
78 along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
79 */
80
81#ifndef __GyotoConverters_H_
82#define __GyotoConverters_H_
83
84#include <GyotoUtils.h>
85#include <GyotoSmartPointer.h>
86
87#ifdef HAVE_UDUNITS
88#include <udunits2.h>
89#endif
90
91#include <string>
92#include <sstream>
93
94namespace Gyoto {
95 namespace Metric {
96 class Generic;
97 }
98 namespace Units {
103#ifdef HAVE_UDUNITS
111 class Unit;
112
137 class Converter;
138
142 ut_system * getSystem();
143#endif
144
152 void Init();
153
177 double ToMeters(double value, const std::string &unit,
179
203 double FromMeters(double value, const std::string &unit,
205
226 double ToSeconds(double value, const std::string &unit,
228
249 double FromSeconds(double value, const std::string &unit,
251
265 double ToKilograms(double value, const std::string & unit);
266
280 double FromKilograms(double value, const std::string & unit);
281
297 double ToGeometrical(double value, const std::string & unit,
299
315 double FromGeometrical(double value, const std::string & unit,
317
331 double ToGeometricalTime(double value, const std::string & unit,
333
347 double FromGeometricalTime(double value, const std::string & unit,
349
350
364 double ToHerz(double value, const std::string &unit);
365
379 double FromHerz(double value, const std::string &unit);
380
381# ifdef HAVE_UDUNITS
397 bool areConvertible(const Unit &unit1, const Unit &unit2);
398# endif
399 }
400}
401
402#ifdef HAVE_UDUNITS
405 friend class Gyoto::Units::Converter;
406 private:
407 ut_unit * unit_;
408 std::string kind_;
409 public:
410
418 Unit(const std::string &unit);
419
428 Unit(char const * const unit);
429
436
445 double To (double val, const Unit &from_unit);
446
455 double From (double val, const Unit &to_unit);
456
462 operator std::string() const ;
463
469 operator ut_unit*() const ;
470};
471
474 private:
475 cv_converter * converter_;
476
477 public:
479 Converter(const Gyoto::Units::Unit& from,
480 const Gyoto::Units::Unit& to);
484
485 void reset();
486 void reset(const Gyoto::Units::Unit& from,
487 const Gyoto::Units::Unit& to);
489
503 double operator()(double value) const ;
504};
505
506#endif
507
508#endif
Reference-counting pointers.
GYOTO utilities.
Base class for metrics.
Definition GyotoMetric.h:162
Can be pointed to by a SmartPointer.
Definition GyotoSmartPointer.h:81
Pointers performing reference counting.
Definition GyotoSmartPointer.h:135
Wrapper around ut_converter from udunits.
Definition GyotoConverters.h:472
cv_converter * converter_
Underlying ut_converter object from udunits.
Definition GyotoConverters.h:475
void reset()
Reset to trivial Converter (Converter()(x)==x).
Converter()
Construct trivial Converter (Converter()(x)==x).
Wrapper around ut_unit from udunits.
Definition GyotoConverters.h:403
double From(double val, const Unit &to_unit)
Convert from Unit.
ut_unit * unit_
the underlying ut_unit (from udunits)
Definition GyotoConverters.h:407
double To(double val, const Unit &from_unit)
Convert to Unit.
std::string kind_
the string used to instantiate this unit
Definition GyotoConverters.h:408
Unit(const std::string &unit)
Build Unit described by string.
Access to metrics.
Definition GyotoAstrobj.h:47
Units-related classes and functions.
Definition GyotoConverters.h:98
double FromSeconds(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
Convert to arbitrary time unit from seconds.
double ToGeometricalTime(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
Convert from arbitrary time unit to geometrical units.
double ToGeometrical(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
Convert from arbitrary length unit to geometrical units.
bool areConvertible(const Unit &unit1, const Unit &unit2)
Is it possible to convert between unit1 and unit2?
ut_system * getSystem()
Retrieve the unit system used in all of Gyoto.
double FromKilograms(double value, const std::string &unit)
Convert to arbitrary mass unit from kilograms.
double FromGeometricalTime(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
Convert to arbitrary time unit from geometrical units.
double FromGeometrical(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg)
Convert to arbitrary length unit from geometrical units.
double FromHerz(double value, const std::string &unit)
Convert to arbitrary frequency unit from Herz.
double ToSeconds(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
Convert from arbitrary time unit to seconds.
double ToMeters(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
Convert from arbitrary length unit to meters.
double FromMeters(double value, const std::string &unit, const Gyoto::SmartPointer< Gyoto::Metric::Generic > &gg=NULL)
Convert to arbitrary length unit from meters.
double ToKilograms(double value, const std::string &unit)
Convert from arbitrary mass unit to kilograms.
void Init()
Load and initialize all (non-context-sensitive) units.
double ToHerz(double value, const std::string &unit)
Convert from arbitrary frequency unit to Herz.
Namespace for the Gyoto library.
Definition GyotoAstrobj.h:44