23 #ifndef O2SCL_CONVERT_UNITS_H 24 #define O2SCL_CONVERT_UNITS_H 35 #include <o2scl/misc.h> 36 #include <o2scl/constants.h> 37 #include <o2scl/string_conv.h> 39 #ifndef DOXYGEN_NO_O2NS 107 #ifndef DOXYGEN_INTERNAL 122 std::map<std::string,unit_t,std::greater<std::string> >
mcache;
125 typedef std::map<std::string,
unit_t,
126 std::greater<std::string> >::iterator
miter;
129 typedef std::map<std::string,unit_t,
130 std::greater<std::string> >::const_iterator
mciter;
145 double val,
double &converted,
146 double &factor,
bool &new_conv)
const;
161 double val,
double &converted,
162 double &factor,
bool &new_conv)
const;
172 double val,
double &converted,
173 double &factor)
const;
189 virtual double convert(std::string from, std::string to,
double val);
194 virtual double convert_const(std::string from, std::string to,
225 virtual int convert_ret(std::string from, std::string to,
double val,
233 double val,
double &converted)
const;
239 void insert_cache(std::string from, std::string to,
double conv);
262 bool hbar_1=
false,
bool K_1=
false)
const;
271 #ifndef DOXYGEN_NO_O2NS std::string t
The output unit.
bool use_gnu_units
If true, use a system call to units to derive new conversions (default true)
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
virtual double convert(std::string from, std::string to, double val)
Return the value val after converting using units from and to.
virtual double convert_const(std::string from, std::string to, double val) const
Return the value val after converting using units from and to (const version)
bool err_on_fail
If true, throw an exception when a conversion fails (default true)
int convert_gnu_units(std::string from, std::string to, double val, double &converted, double &factor, bool &new_conv) const
Attempt to use GNU units to perform a conversion.
std::string units_cmd_string
Command string to call units (default "units")
int test_cache()
Exhaustive test the cache against GNU units.
std::map< std::string, unit_t, std::greater< std::string > > mcache
The cache where unit conversions are stored.
int verbose
Verbosity (default 0)
convert_units()
Create a unit-conversion object.
void print_cache() const
Print the present unit cache to std::cout.
bool combine_two_conv
If true, allow combinations of two conversions (default true)
virtual int convert_ret(std::string from, std::string to, double val, double &converted)
Return the value val after converting using units from and to, returning a non-zero value on failure...
virtual int convert_ret_const(std::string from, std::string to, double val, double &converted) const
Return the value val after converting using units from and to, returning a non-zero value on failure ...
void insert_cache(std::string from, std::string to, double conv)
Manually insert a unit conversion into the cache.
int convert_internal(std::string from, std::string to, double val, double &converted, double &factor, bool &new_conv) const
The internal conversion function which tries the cache first and, if that failed, tries GNU units...
std::map< std::string, unit_t, std::greater< std::string > >::iterator miter
The iterator type.
void make_units_dat(std::string fname, bool c_1=false, bool hbar_1=false, bool K_1=false) const
Make a GNU units.dat file from the GSL constants.
std::string f
The input unit.
The type for caching unit conversions.
void remove_cache(std::string from, std::string to)
Manually remove a unit conversion into the cache.
int convert_cache(std::string from, std::string to, double val, double &converted, double &factor) const
Attempt to construct a conversion from the internal unit cache.
std::map< std::string, unit_t, std::greater< std::string > >::const_iterator mciter
The const iterator type.
double c
The conversion factor.