Bayeux  3.4.1
Core Foundation library for SuperNEMO
Classes | Enumerations | Functions
datatools::units Namespace Reference

Utilities for units based on the CLHEP library's implementation. More...

Classes

class  registry
 A registry for units. More...
 
class  unit
 The description of an unit. More...
 
class  unit_dimension
 The description of an unit dimension. More...
 

Enumerations

enum  power_of_ten {
  YOCTO = -24, ZEPTO = -21, ATTO = -18, FEMTO = -15,
  PICO = -12, NANO = -9, MICRO = -6, MILLI = -3,
  CENTI = -2, DECI = -1, UNIT_POWER_OF_TEN = 0, DECA = 1,
  HECTO = 2, KILO = 3, MEGA = 6, GIGA = 9,
  TERA = 12, PETA = 15, EXA = 18, ZETTA = 21,
  YOTTA = 24
}
 SI powers of ten. More...
 
enum  power_of_two {
  UNIT_POWER_OF_TWO = 0, KIBI = 10, MEBI = 20, GIBI = 30,
  TEBI = 40, PEBI = 50, EXBI = 60, ZEBI = 70,
  YOBI = 80
}
 IEC powers of two (binary prefixes) More...
 

Functions

double yocto ()
 
double zepto ()
 
double atto ()
 
double femto ()
 
double pico ()
 
double nano ()
 
double micro ()
 
double milli ()
 
double centi ()
 
double deci ()
 
double deca ()
 
double hecto ()
 
double kilo ()
 
double mega ()
 
double giga ()
 
double tera ()
 
double peta ()
 
double exa ()
 
double zetta ()
 
double yotta ()
 
double power_of_ten_to_factor (power_of_ten)
 Return the SI prefix factor associated to a given SI power of ten. More...
 
std::string power_of_ten_to_name (power_of_ten)
 Return the SI name associated to a given SI power of ten. More...
 
std::string power_of_ten_to_symbol (power_of_ten)
 Return the SI symbol associated to a given SI power of ten. More...
 
double byte_to_bit_factor ()
 Return the IEC 80000-13 byte (octet 8 bits) to bit factor. More...
 
double power_of_two_to_factor (power_of_two)
 Return the IEC binary prefix approximated factor associated to a given IEC power of two. More...
 
std::string power_of_two_to_name (power_of_two)
 Return the IEC binary prefix name associated to a given IEC power of two. More...
 
std::string power_of_two_to_symbol (power_of_two)
 Return the IEC binary prefix symbol associated to a given IEC power of two. More...
 
size_t registered_unit_dimension_labels (std::vector< std::string > &dimension_labels_)
 
size_t registered_unit_names (std::vector< std::string > &unit_names_)
 
size_t registered_unit_symbols (std::vector< std::string > &unit_symbols_)
 
bool is_unit_in_dimension_from (const std::string &unit_id_, const std::string &unit_dimension_label_)
 
double get_unit_in_dimension_from (const std::string &unit_id_, const std::string &unit_dimension_label_)
 
double get_length_unit_from (const std::string &unit_id_)
 
double get_surface_unit_from (const std::string &)
 Get the surface unit value from a string. More...
 
double get_volume_unit_from (const std::string &)
 Get the volume unit value from a string. More...
 
double get_time_unit_from (const std::string &)
 Get the time unit value from a string. More...
 
double get_angle_unit_from (const std::string &)
 Get the angle unit value from a string. More...
 
double get_solid_angle_unit_from (const std::string &)
 Get the solid angle unit value from a string. More...
 
double get_energy_unit_from (const std::string &)
 Get the energy unit from a string. More...
 
double get_mass_unit_from (const std::string &)
 Get the mass unitvalue from a string. More...
 
double get_pressure_unit_from (const std::string &)
 Get the pressure unit value from a string. More...
 
double get_magnetic_flux_density_unit_from (const std::string &)
 Get the magnetic field unit value from a string. More...
 
double get_magnetic_field_unit_from (const std::string &)
 
double get_electric_field_unit_from (const std::string &)
 Get the electric field unit value from a string. More...
 
double get_electric_potential_unit_from (const std::string &)
 Get the electric potential unit value from a string. More...
 
double get_electric_tension_unit_from (const std::string &)
 
double get_temperature_unit_from (const std::string &)
 Get the temperature unit value from a string. More...
 
double get_density_unit_from (const std::string &)
 Get the density unit value from a string. More...
 
double get_activity_unit_from (const std::string &)
 Get the activity unit value from a string. More...
 
double get_surface_activity_unit_from (const std::string &)
 Get the surface activity unit value from a string. More...
 
double get_volume_activity_unit_from (const std::string &)
 Get the volume activity unit value from a string. More...
 
double get_mass_activity_unit_from (const std::string &)
 Get the mass activity unit value from a string. More...
 
double get_frequency_unit_from (const std::string &)
 Get the frequency unit value from a string. More...
 
double get_electric_charge_unit_from (const std::string &)
 Get the electric charge unit value from a string. More...
 
double get_electric_current_unit_from (const std::string &)
 Get the electric current unit value from a string. More...
 
double get_velocity_unit_from (const std::string &)
 Get the velocity unit value from a string. More...
 
double get_speed_unit_from (const std::string &)
 
double get_unit_from (const std::string &unit_type_, const std::string &unit_str_)
 Get the CLHEP unit value from a string specifiying the unit type. More...
 
double get_unit (const std::string &unit_str_, bool throw_=false)
 Get the CLHEP unspecified unit value from a string. More...
 
bool is_unit_label_valid (const std::string &unit_label_)
 Return an array containing the labels associated to all type of units supported by the datatools::units class. More...
 
std::string get_default_unit_symbol_from_label (const std::string &unit_label_)
 Return the symbol of the default unit associated to a unit label supported by the datatools::units class. More...
 
bool find_unit (const std::string &unit_str_, double &unit_value_, std::string &unit_label_)
 Find the specified unit and the associated unit label from a string. More...
 
double get_value_with_unit (const std::string &word_)
 Get a value from a string taking into account the unit symbol. More...
 
bool find_value_with_unit (const std::string &word_, double &value_, std::string &unit_label_, double default_unit_=std::numeric_limits< double >::quiet_NaN())
 Get a value from a string taking into account the unit symbol. More...
 
bool parse_value_with_unit (const std::string &word, double &value, std::string &unit_symbol, std::string &unit_label, uint32_t flags=0)
 Parse a value from a string taking into account the unit symbol, set the value, the unit symbol and unit label. More...
 

Detailed Description

Utilities for units based on the CLHEP library's implementation.

The units namespace provides some methods to manipulate units values through strings. It is based on the system of units in the CLHEP package. A system registry of units (class datatools::units::unit) is provided to register arbitrary SI based units. Extension tools are provided beyond the CLHEP material.

Enumeration Type Documentation

◆ power_of_ten

SI powers of ten.

Enumerator
YOCTO 
ZEPTO 
ATTO 
FEMTO 
PICO 
NANO 
MICRO 
MILLI 
CENTI 
DECI 
UNIT_POWER_OF_TEN 
DECA 
HECTO 
KILO 
MEGA 
GIGA 
TERA 
PETA 
EXA 
ZETTA 
YOTTA 

◆ power_of_two

IEC powers of two (binary prefixes)

Enumerator
UNIT_POWER_OF_TWO 
KIBI 
MEBI 
GIBI 
TEBI 
PEBI 
EXBI 
ZEBI 
YOBI 

Function Documentation

◆ atto()

double datatools::units::atto ( )

◆ byte_to_bit_factor()

double datatools::units::byte_to_bit_factor ( )

Return the IEC 80000-13 byte (octet 8 bits) to bit factor.

◆ centi()

double datatools::units::centi ( )

◆ deca()

double datatools::units::deca ( )

◆ deci()

double datatools::units::deci ( )

◆ exa()

double datatools::units::exa ( )

◆ femto()

double datatools::units::femto ( )

◆ find_unit()

bool datatools::units::find_unit ( const std::string &  unit_str_,
double &  unit_value_,
std::string &  unit_label_ 
)

Find the specified unit and the associated unit label from a string.

Example:

double unit_value;
string unit_label;
bool ok = datatools::units::find_unit("cm", unit_value, unit_label);
cout << "Unit value = " << unit_value << "\n";
cout << "Unit label = '" << unit_label << "'\n";
bool ok2 = datatools::units::find_unit("centimeter", unit_value, unit_label);
cout << "Unit value = " << unit_value << "\n";
cout << "Unit label = '" << unit_label << "'\n";

◆ find_value_with_unit()

bool datatools::units::find_value_with_unit ( const std::string &  word_,
double &  value_,
std::string &  unit_label_,
double  default_unit_ = std::numeric_limits< double >::quiet_NaN() 
)

Get a value from a string taking into account the unit symbol.

Example:

double value;
string unit_label;
bool ok = datatools::units::find_value_with_unit("2.54 cm", value, unit_label);

◆ get_activity_unit_from()

double datatools::units::get_activity_unit_from ( const std::string &  )

Get the activity unit value from a string.

◆ get_angle_unit_from()

double datatools::units::get_angle_unit_from ( const std::string &  )

Get the angle unit value from a string.

◆ get_default_unit_symbol_from_label()

std::string datatools::units::get_default_unit_symbol_from_label ( const std::string &  unit_label_)

Return the symbol of the default unit associated to a unit label supported by the datatools::units class.

◆ get_density_unit_from()

double datatools::units::get_density_unit_from ( const std::string &  )

Get the density unit value from a string.

◆ get_electric_charge_unit_from()

double datatools::units::get_electric_charge_unit_from ( const std::string &  )

Get the electric charge unit value from a string.

◆ get_electric_current_unit_from()

double datatools::units::get_electric_current_unit_from ( const std::string &  )

Get the electric current unit value from a string.

◆ get_electric_field_unit_from()

double datatools::units::get_electric_field_unit_from ( const std::string &  )

Get the electric field unit value from a string.

◆ get_electric_potential_unit_from()

double datatools::units::get_electric_potential_unit_from ( const std::string &  )

Get the electric potential unit value from a string.

◆ get_electric_tension_unit_from()

double datatools::units::get_electric_tension_unit_from ( const std::string &  )
Deprecated:
Get the electric tension unit value from a string.

◆ get_energy_unit_from()

double datatools::units::get_energy_unit_from ( const std::string &  )

Get the energy unit from a string.

◆ get_frequency_unit_from()

double datatools::units::get_frequency_unit_from ( const std::string &  )

Get the frequency unit value from a string.

◆ get_length_unit_from()

double datatools::units::get_length_unit_from ( const std::string &  unit_id_)

Get the length unit value from a string.

Parameters
unit_id_the name or the symbol of the unit
Returns
the value associated to the unit
double mm = get_length_unit_from("mm"); // success
double xx = get_length_unit_from("kg"); // throw an exception
double yy = get_length_unit_from("yy"); // throw an exception

◆ get_magnetic_field_unit_from()

double datatools::units::get_magnetic_field_unit_from ( const std::string &  )
Deprecated:
Get the magnetic field unit value from a string.

◆ get_magnetic_flux_density_unit_from()

double datatools::units::get_magnetic_flux_density_unit_from ( const std::string &  )

Get the magnetic field unit value from a string.

◆ get_mass_activity_unit_from()

double datatools::units::get_mass_activity_unit_from ( const std::string &  )

Get the mass activity unit value from a string.

◆ get_mass_unit_from()

double datatools::units::get_mass_unit_from ( const std::string &  )

Get the mass unitvalue from a string.

◆ get_pressure_unit_from()

double datatools::units::get_pressure_unit_from ( const std::string &  )

Get the pressure unit value from a string.

◆ get_solid_angle_unit_from()

double datatools::units::get_solid_angle_unit_from ( const std::string &  )

Get the solid angle unit value from a string.

◆ get_speed_unit_from()

double datatools::units::get_speed_unit_from ( const std::string &  )
Deprecated:
Get the speed unit value from a string.

◆ get_surface_activity_unit_from()

double datatools::units::get_surface_activity_unit_from ( const std::string &  )

Get the surface activity unit value from a string.

◆ get_surface_unit_from()

double datatools::units::get_surface_unit_from ( const std::string &  )

Get the surface unit value from a string.

◆ get_temperature_unit_from()

double datatools::units::get_temperature_unit_from ( const std::string &  )

Get the temperature unit value from a string.

◆ get_time_unit_from()

double datatools::units::get_time_unit_from ( const std::string &  )

Get the time unit value from a string.

◆ get_unit()

double datatools::units::get_unit ( const std::string &  unit_str_,
bool  throw_ = false 
)

Get the CLHEP unspecified unit value from a string.

Example:

double u = datatools::units::get_unit("cm");

◆ get_unit_from()

double datatools::units::get_unit_from ( const std::string &  unit_type_,
const std::string &  unit_str_ 
)

Get the CLHEP unit value from a string specifiying the unit type.

Example:

double lu = datatools::units::get_unit_from("length", "cm");

◆ get_unit_in_dimension_from()

double datatools::units::get_unit_in_dimension_from ( const std::string &  unit_id_,
const std::string &  unit_dimension_label_ 
)

Return the unit value associated to an unit given its id (name or symbol) and dimension

Parameters
unit_id_the name or the symbol of the unit
unit_dimension_label_the label of the unit dimension
Returns
the value associated to the unit
double mm = get_unit_in_dimension_from("mm", "length"); // success
double xx = get_unit_in_dimension_from("kg", "length"); // throw an exception
double kg = get_unit_in_dimension_from("kg", "mass"); // success

◆ get_value_with_unit()

double datatools::units::get_value_with_unit ( const std::string &  word_)

Get a value from a string taking into account the unit symbol.

Example:

double val = datatools::units::get_value_with_unit("2.54 cm");

◆ get_velocity_unit_from()

double datatools::units::get_velocity_unit_from ( const std::string &  )

Get the velocity unit value from a string.

◆ get_volume_activity_unit_from()

double datatools::units::get_volume_activity_unit_from ( const std::string &  )

Get the volume activity unit value from a string.

◆ get_volume_unit_from()

double datatools::units::get_volume_unit_from ( const std::string &  )

Get the volume unit value from a string.

◆ giga()

double datatools::units::giga ( )

◆ hecto()

double datatools::units::hecto ( )

◆ is_unit_in_dimension_from()

bool datatools::units::is_unit_in_dimension_from ( const std::string &  unit_id_,
const std::string &  unit_dimension_label_ 
)

Check if a unit value given by id (name or symbol) is in a dimension

Parameters
unit_id_the name or the symbol of the unit
unit_dimension_label_the label of the unit dimension
Returns
the value associated to the unit
double mm = get_unit_in_dimension_from("mm", "length"); // success
double xx = get_unit_in_dimension_from("kg", "length"); // throw an exception
double kg = get_unit_in_dimension_from("kg", "mass"); // success

◆ is_unit_label_valid()

bool datatools::units::is_unit_label_valid ( const std::string &  unit_label_)

Return an array containing the labels associated to all type of units supported by the datatools::units class.

Check if a unit type with a given label is supported by the datatools::units class. Example:

{
std::cout << "A unit of type 'length' is possible." << std::endl;
}
{
std::cout << "A unit of type 'color' is not supported." << std::endl;
}

◆ kilo()

double datatools::units::kilo ( )

◆ mega()

double datatools::units::mega ( )

◆ micro()

double datatools::units::micro ( )

◆ milli()

double datatools::units::milli ( )

◆ nano()

double datatools::units::nano ( )

◆ parse_value_with_unit()

bool datatools::units::parse_value_with_unit ( const std::string &  word,
double &  value,
std::string &  unit_symbol,
std::string &  unit_label,
uint32_t  flags = 0 
)

Parse a value from a string taking into account the unit symbol, set the value, the unit symbol and unit label.

Example:

double value;
string unit_symbol;
string unit_label;
bool ok = datatools::units::parse_value_with_unit("2.54 cm", value, unit_symbol, unit_label);

This will output: value = 25.4 // because native unit for length is "mm" unit_symbol = "cm" unit_label = "length"

◆ peta()

double datatools::units::peta ( )

◆ pico()

double datatools::units::pico ( )

◆ power_of_ten_to_factor()

double datatools::units::power_of_ten_to_factor ( power_of_ten  )

Return the SI prefix factor associated to a given SI power of ten.

◆ power_of_ten_to_name()

std::string datatools::units::power_of_ten_to_name ( power_of_ten  )

Return the SI name associated to a given SI power of ten.

◆ power_of_ten_to_symbol()

std::string datatools::units::power_of_ten_to_symbol ( power_of_ten  )

Return the SI symbol associated to a given SI power of ten.

◆ power_of_two_to_factor()

double datatools::units::power_of_two_to_factor ( power_of_two  )

Return the IEC binary prefix approximated factor associated to a given IEC power of two.

◆ power_of_two_to_name()

std::string datatools::units::power_of_two_to_name ( power_of_two  )

Return the IEC binary prefix name associated to a given IEC power of two.

◆ power_of_two_to_symbol()

std::string datatools::units::power_of_two_to_symbol ( power_of_two  )

Return the IEC binary prefix symbol associated to a given IEC power of two.

◆ registered_unit_dimension_labels()

size_t datatools::units::registered_unit_dimension_labels ( std::vector< std::string > &  dimension_labels_)

Build the list of system registered dimension labels

Parameters
dimension_labels_a vector of string to be filled by unit dimension labels
Returns
the number of unit dimension labels

◆ registered_unit_names()

size_t datatools::units::registered_unit_names ( std::vector< std::string > &  unit_names_)

Build the list of system registered unit names

Parameters
unit_names_a vector of string to be filled by unit names
Returns
the number of unit names

◆ registered_unit_symbols()

size_t datatools::units::registered_unit_symbols ( std::vector< std::string > &  unit_symbols_)

Build the list of system registered unit symbols

Parameters
unit_symbols_a vector of string to be filled by unit symbols
Returns
the number of unit symbols

◆ tera()

double datatools::units::tera ( )

◆ yocto()

double datatools::units::yocto ( )

◆ yotta()

double datatools::units::yotta ( )

◆ zepto()

double datatools::units::zepto ( )

◆ zetta()

double datatools::units::zetta ( )