Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
conversion.hpp File Reference

Template for defining conversions between quantities. More...

#include <boost/units/detail/conversion_impl.hpp>
Include dependency graph for conversion.hpp:
This graph shows which files directly or indirectly include this file:

Classes

struct  boost::units::conversion_helper< From, To >
 

Namespaces

 boost
 Duration formatting facet for input.
 
 boost::units
 

Macros

#define BOOST_UNITS_DEFINE_CONVERSION_FACTOR(Source, Destination, type_, value_)
 Defines the conversion factor from a base unit to any unit or to another base unit with the correct dimensions. More...
 
#define BOOST_UNITS_DEFINE_CONVERSION_FACTOR_TEMPLATE(Params, Source, Destination, type_, value_)
 Defines the conversion factor from a base unit to any other base unit with the same dimensions. More...
 
#define BOOST_UNITS_DEFAULT_CONVERSION(Source, Dest)
 Specifies the default conversion to be applied when no direct conversion is available. More...
 
#define BOOST_UNITS_DEFAULT_CONVERSION_TEMPLATE(Params, Source, Dest)
 Specifies the default conversion to be applied when no direct conversion is available. More...
 
#define BOOST_UNITS_DEFINE_BASE_UNIT_WITH_CONVERSIONS(namespace_, name_, name_string_, symbol_string_, factor, unit, id)
 INTERNAL ONLY Users should not create their units in namespace boost::units. More...
 

Functions

template<class FromUnit , class ToUnit >
one_to_double_type< typename
detail::conversion_factor_helper
< FromUnit, ToUnit >::type >
::type 
boost::units::conversion_factor (const FromUnit &, const ToUnit &)
 Find the conversion factor between two units. More...
 

Detailed Description

Template for defining conversions between quantities.

Macro Definition Documentation

#define BOOST_UNITS_DEFAULT_CONVERSION (   Source,
  Dest 
)
Value:
namespace boost { \
namespace units { \
template<> \
{ \
static const bool is_defined = true; \
typedef Dest::unit_type type; \
}; \
} \
} \
void boost_units_require_semicolon()
void
Definition: is_convertible.hpp:460
Duration formatting facet for input.
Definition: accumulators_fwd.hpp:55
adjacency_iterator typedef T::adjacency_iterator type
Definition: graph_traits.hpp:42

Specifies the default conversion to be applied when no direct conversion is available.

Source is a base unit. Dest is any unit with the same dimensions.

#define BOOST_UNITS_DEFAULT_CONVERSION_TEMPLATE (   Params,
  Source,
  Dest 
)
Value:
namespace boost { \
namespace units { \
template<BOOST_PP_SEQ_ENUM(Params)> \
struct unscaled_get_default_conversion<Source> \
{ \
static const bool is_defined = true; \
typedef typename Dest::unit_type type; \
}; \
} \
} \
void boost_units_require_semicolon()
void
Definition: is_convertible.hpp:460
Duration formatting facet for input.
Definition: accumulators_fwd.hpp:55
adjacency_iterator typedef T::adjacency_iterator type
Definition: graph_traits.hpp:42

Specifies the default conversion to be applied when no direct conversion is available.

Params is a PP Sequence of template arguments. Source is a base unit. Dest is any unit with the same dimensions. The source must not be a scaled base unit.

#define BOOST_UNITS_DEFINE_BASE_UNIT_WITH_CONVERSIONS (   namespace_,
  name_,
  name_string_,
  symbol_string_,
  factor,
  unit,
  id 
)
Value:
namespace boost { \
namespace units { \
namespace namespace_ { \
struct name_ ## _base_unit \
: base_unit<name_ ## _base_unit, unit::dimension_type, id> { \
static const char* name() { return(name_string_); } \
static const char* symbol() { return(symbol_string_); }; \
}; \
} \
} \
} \
BOOST_UNITS_DEFINE_CONVERSION_FACTOR(namespace_::name_ ## _base_unit, unit, double, factor); \
BOOST_UNITS_DEFAULT_CONVERSION(namespace_::name_ ## _base_unit, unit)
#define BOOST_UNITS_DEFINE_CONVERSION_FACTOR(Source, Destination, type_, value_)
Defines the conversion factor from a base unit to any unit or to another base unit with the correct d...
Definition: conversion.hpp:65
Duration formatting facet for input.
Definition: accumulators_fwd.hpp:55
const int name
Definition: gzip.hpp:94
symbol_type const symbol
Definition: unicode.hpp:461
#define BOOST_UNITS_DEFAULT_CONVERSION(Source, Dest)
Specifies the default conversion to be applied when no direct conversion is available.
Definition: conversion.hpp:118

INTERNAL ONLY Users should not create their units in namespace boost::units.

If we want to make this public it needs to allow better control over the namespaces. –SJW. template that defines a base_unit and conversion to another dimensionally-consistent unit

#define BOOST_UNITS_DEFINE_CONVERSION_FACTOR (   Source,
  Destination,
  type_,
  value_ 
)
Value:
namespace boost { \
namespace units { \
template<> \
struct select_base_unit_converter< \
> \
{ \
typedef Source source_type; \
typedef reduce_unit<Destination::unit_type>::type destination_type; \
}; \
template<> \
{ \
static const bool is_defined = true; \
typedef type_ type; \
static type value() { return(value_); } \
}; \
} \
} \
void boost_units_require_semicolon()
void
Definition: is_convertible.hpp:460
Duration formatting facet for input.
Definition: accumulators_fwd.hpp:55
typed_value< T > * value()
Creates a typed_value instance.
adjacency_iterator typedef T::adjacency_iterator type
Definition: graph_traits.hpp:42

Defines the conversion factor from a base unit to any unit or to another base unit with the correct dimensions.

Uses of this macro must appear at global scope. If the destination unit is a base unit or a unit that contains only one base unit which is raised to the first power (e.g. feet->meters) the reverse (meters->feet in this example) need not be defined explicitly.

#define BOOST_UNITS_DEFINE_CONVERSION_FACTOR_TEMPLATE (   Params,
  Source,
  Destination,
  type_,
  value_ 
)
Value:
namespace boost { \
namespace units { \
template<BOOST_PP_SEQ_ENUM(Params)> \
struct base_unit_converter< \
Source, \
BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Destination, typename Source::dimension_type)\
> \
{ \
static const bool is_defined = true; \
typedef type_ type; \
static type value() { return(value_); } \
}; \
} \
} \
void boost_units_require_semicolon()
void
Definition: is_convertible.hpp:460
Duration formatting facet for input.
Definition: accumulators_fwd.hpp:55
#define BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(BaseUnit, Dimensions)
INTERNAL ONLY.
Definition: heterogeneous_system.hpp:95
typed_value< T > * value()
Creates a typed_value instance.
adjacency_iterator typedef T::adjacency_iterator type
Definition: graph_traits.hpp:42

Defines the conversion factor from a base unit to any other base unit with the same dimensions.

Params should be a Boost.Preprocessor Seq of template parameters, such as (class T1)(class T2) All uses of must appear at global scope. The reverse conversion will be defined automatically. This macro is a little dangerous, because, unlike the non-template form, it will silently fail if either base unit is scaled. This is probably not an issue if both the source and destination types depend on the template parameters, but be aware that a generic conversion to kilograms is not going to work.