|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60448 - branches/units/autoprefix/libs/units/example
From: pbristow_at_[hidden]
Date: 2010-03-10 15:42:05
Author: pbristow
Date: 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
New Revision: 60448
URL: http://svn.boost.org/trac/boost/changeset/60448
Log:
\detailed changed to \details to satisfy Doxygen.
Text files modified:
branches/units/autoprefix/libs/units/example/autoprefixes.cpp | 92 ++++++++++++++++-----------
branches/units/autoprefix/libs/units/example/complex.cpp | 134 ++++++++++++++++++++--------------------
branches/units/autoprefix/libs/units/example/composite_output.cpp | 14 ++--
branches/units/autoprefix/libs/units/example/conversion.cpp | 36 +++++-----
branches/units/autoprefix/libs/units/example/conversion_factor.cpp | 12 +-
branches/units/autoprefix/libs/units/example/dimension.cpp | 28 ++++----
branches/units/autoprefix/libs/units/example/heterogeneous_unit.cpp | 2
branches/units/autoprefix/libs/units/example/kitchen_sink.cpp | 2
branches/units/autoprefix/libs/units/example/non_base_dimension.cpp | 2
branches/units/autoprefix/libs/units/example/performance.cpp | 2
branches/units/autoprefix/libs/units/example/quantity.cpp | 2
branches/units/autoprefix/libs/units/example/quaternion.cpp | 2
branches/units/autoprefix/libs/units/example/radar_beam_height.cpp | 2
branches/units/autoprefix/libs/units/example/systems.cpp | 2
branches/units/autoprefix/libs/units/example/temperature.cpp | 2
branches/units/autoprefix/libs/units/example/tutorial.cpp | 54 ++++++++-------
branches/units/autoprefix/libs/units/example/unit.cpp | 2
17 files changed, 207 insertions(+), 183 deletions(-)
Modified: branches/units/autoprefix/libs/units/example/autoprefixes.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/autoprefixes.cpp (original)
+++ branches/units/autoprefix/libs/units/example/autoprefixes.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -18,19 +18,30 @@
Output:
@verbatim
-
+autoprefixes.cpp
+using native typeof
+Linking...
+Embedding manifest...
+Autorun "j:\Cpp\Misc\debug\autoprefixes.exe"
+2.345 m
+2.345 km
+5.49902 MJ
+5.49902 megajoule
+2.048 kb
+2 Kib
+2345.6
+23456
+2345.6
+23456
+m
+meter
+0
+1
+@endverbatim
//[autoprefixes_output
-L = m
-meter*meter = m^2
-M*(L/T)*(L/T) = m^2 kg s^-2
-M*(L/T)^2 = m^2 kg s^-2
-L^3 = m^3
-L^(3/2) = m^(3/2)
-2vM = kg^(1/2)
-(3/2)vM = kg^(2/3)
+
//] [/autoprefixes_output
-_at_endverbatim
**/
#include <iostream>
@@ -43,63 +54,70 @@
struct byte_base_unit : boost::units::base_unit<byte_base_unit, boost::units::dimensionless_type, 3>
{
- static const char* name() { return("byte"); }
- static const char* symbol() { return("b"); }
+ static const char* name() { return("byte"); }
+ static const char* symbol() { return("b"); }
};
int main()
{
using std::cout;
using std::endl;
+
using namespace boost::units;
using namespace boost::units::si;
+ //[autoprefixes_snippet_1
using boost::units::binary_prefix;
using boost::units::engineering_prefix;
+ using boost::units::no_prefix;
- //[autoprefixes_snippet_1
quantity<length> l = 2.345 * meters; // A quantity of length, in units of meters.
- cout << boost::units::engineering_prefix << l << endl; // Outputs "2.345 m".
- //l = l * 1000; // Increase it by 1000, so expect a k prefix.// Note Fails if integer.
-
- l = 1000. * l; // Increase it by 1000, so expect a k prefix.
- cout << boost::units::engineering_prefix << l << endl; // Output autoprefixed with k to "2.345 km".
+ cout << engineering_prefix << l << endl; // Outputs "2.345 m".
+ l = 1000.0 * l; // Increase it by 1000, so expect a k prefix.
+ // Note that a double 1000.0 is required - an integer will fail to compile.
+ cout << engineering_prefix << l << endl; // Output autoprefixed with k to "2.345 km".
quantity<energy> e = kilograms * pow<2>(l / seconds); // A quantity of energy.
- cout << boost::units::engineering_prefix << e << endl; // 5.49902 MJ
- cout << name_format << boost::units::engineering_prefix << e << endl; // 5.49902 megaJoule
-
+ cout << engineering_prefix << e << endl; // 5.49902 MJ
+ cout << name_format << engineering_prefix << e << endl; // 5.49902 megaJoule
//] [/autoprefixes_snippet_1]
-
//[autoprefixes_snippet_2
- // Don't forget that the name or symbol format specification is persistent.
- cout << symbol_format << endl; // So this resets the format to the default symbol.
-
- quantity<byte_base_unit, dimensionless> b = 2048. * byte_base_unit::unit_type();
-
- cout << b << endl;
- cout << symbol_format << binary_prefix << b << endl; // "2 kibibyte"
-
+ // Don't forget that the units name or symbol format specification is persistent.
+ cout << symbol_format << endl; // Resets the format to the default symbol format.
+ quantity<byte_base_unit::unit_type> b = 2048. * byte_base_unit::unit_type();
+ cout << engineering_prefix << b << endl; // 2.048 kb
+ cout << symbol_format << binary_prefix << b << endl; // "2 kib"
//] [/autoprefixes_snippet_2]
- //[autoprefixes_snippet_3
// Note that scalar dimensionless values are *not* prefixed automatically by the engineering_prefix or binary_prefix iostream manipulators.
+ //[autoprefixes_snippet_3
const double s1 = 2345.6;
const long x1 = 23456;
- cout << boost::units::engineering_prefix << s1 << endl; // 2345.6
- cout << boost::units::engineering_prefix << x1 << endl; // 23456
+ cout << engineering_prefix << s1 << endl; // 2345.6
+ cout << engineering_prefix << x1 << endl; // 23456
- cout << boost::units::binary_prefix << s1 << endl; // 2345.6
- cout << boost::units::binary_prefix << x1 << endl; // 23456
+ cout << binary_prefix << s1 << endl; // 2345.6
+ cout << binary_prefix << x1 << endl; // 23456
+ //] [/autoprefixes_snippet_3]
+ //[autoprefixes_snippet_4
const length L; // A unit of length (but not a quantity of length).
- cout << L << endl; // default length unit is meter,
+ cout << L << endl; // Default length unit is meter,
// but default is symbol format so output is just "m".
cout << name_format << L << endl; // default length name is "meter".
- //] [/autoprefixes_snippet_3]
+ //] [/autoprefixes_snippet_4]
+ //[autoprefixes_snippet_5
+ no_prefix(cout); // Clear any prefix flag.
+ cout << no_prefix << endl; // Clear any prefix flag using `no_prefix` manipulator.
+ //] [/autoprefixes_snippet_5]
+
+ //[autoprefixes_snippet_6
+ cout << boost::units::get_autoprefix(cout) << endl; // 8 is `autoprefix_binary` from `enum autoprefix_mode`.
+ cout << boost::units::get_format(cout) << endl; // 1 is `name_fmt` from `enum format_mode`.
+ //] [/autoprefixes_snippet_6]
return 0;
} // int main()
Modified: branches/units/autoprefix/libs/units/example/complex.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/complex.cpp (original)
+++ branches/units/autoprefix/libs/units/example/complex.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -1,4 +1,4 @@
-// Boost.Units - A C++ library for zero-overhead dimensional analysis and
+// Boost.Units - A C++ library for zero-overhead dimensional analysis and
// unit/quantity manipulation and conversion
//
// Copyright (C) 2003-2008 Matthias Christian Schabel
@@ -8,12 +8,12 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-/**
+/**
\file
-
+
\brief complex.cpp
-\detailed
+\details
Demonstrate a complex number class that functions correctly with quantities.
Output:
@@ -65,29 +65,29 @@
namespace units {
-/// replacement complex class
+/// replacement complex class
template<class T>
class complex
{
public:
typedef complex<T> this_type;
-
+
complex(const T& r = 0,const T& i = 0) : r_(r),i_(i) { }
complex(const this_type& source) : r_(source.r_),i_(source.i_) { }
-
+
this_type& operator=(const this_type& source)
{
if (this == &source) return *this;
-
+
r_ = source.r_;
i_ = source.i_;
-
+
return *this;
}
-
+
T& real() { return r_; }
T& imag() { return i_; }
-
+
const T& real() const { return r_; }
const T& imag() const { return i_; }
@@ -96,53 +96,53 @@
r_ += val;
return *this;
}
-
+
this_type& operator-=(const T& val)
{
r_ -= val;
return *this;
}
-
+
this_type& operator*=(const T& val)
{
r_ *= val;
i_ *= val;
return *this;
}
-
+
this_type& operator/=(const T& val)
{
r_ /= val;
i_ /= val;
return *this;
}
-
+
this_type& operator+=(const this_type& source)
{
r_ += source.r_;
i_ += source.i_;
return *this;
}
-
+
this_type& operator-=(const this_type& source)
{
r_ -= source.r_;
i_ -= source.i_;
return *this;
}
-
+
this_type& operator*=(const this_type& source)
{
*this = *this * source;
return *this;
}
-
+
this_type& operator/=(const this_type& source)
{
*this = *this / source;
return *this;
}
-
+
private:
T r_,i_;
};
@@ -168,7 +168,7 @@
operator+(const complex<X>& x)
{
typedef typename unary_plus_typeof_helper<X>::type type;
-
+
return complex<type>(x.real(),x.imag());
}
@@ -177,7 +177,7 @@
operator-(const complex<X>& x)
{
typedef typename unary_minus_typeof_helper<X>::type type;
-
+
return complex<type>(-x.real(),-x.imag());
}
@@ -186,7 +186,7 @@
operator+(const complex<X>& x,const complex<Y>& y)
{
typedef typename boost::units::add_typeof_helper<X,Y>::type type;
-
+
return complex<type>(x.real()+y.real(),x.imag()+y.imag());
}
@@ -195,7 +195,7 @@
operator-(const complex<X>& x,const complex<Y>& y)
{
typedef typename boost::units::subtract_typeof_helper<X,Y>::type type;
-
+
return complex<type>(x.real()-y.real(),x.imag()-y.imag());
}
@@ -204,23 +204,23 @@
operator*(const complex<X>& x,const complex<Y>& y)
{
typedef typename boost::units::multiply_typeof_helper<X,Y>::type type;
-
+
return complex<type>(x.real()*y.real() - x.imag()*y.imag(),
x.real()*y.imag() + x.imag()*y.real());
// fully correct implementation has more complex return type
//
// typedef typename boost::units::multiply_typeof_helper<X,Y>::type xy_type;
-//
+//
// typedef typename boost::units::add_typeof_helper<
// xy_type,xy_type>::type xy_plus_xy_type;
// typedef typename
// boost::units::subtract_typeof_helper<xy_type,xy_type>::type
// xy_minus_xy_type;
-//
+//
// BOOST_STATIC_ASSERT((boost::is_same<xy_plus_xy_type,
// xy_minus_xy_type>::value == true));
-//
+//
// return complex<xy_plus_xy_type>(x.real()*y.real()-x.imag()*y.imag(),
// x.real()*y.imag()+x.imag()*y.real());
}
@@ -236,7 +236,7 @@
(y.real()*y.real()+y.imag()*y.imag()),
(x.imag()*y.real()-x.real()*y.imag())/
(y.real()*y.real()+y.imag()*y.imag()));
-
+
// fully correct implementation has more complex return type
//
// typedef typename boost::units::multiply_typeof_helper<X,Y>::type xy_type;
@@ -263,13 +263,13 @@
}
template<class Y>
-complex<Y>
+complex<Y>
pow(const complex<Y>& x,const Y& y)
{
std::complex<Y> tmp(x.real(),x.imag());
-
+
tmp = std::pow(tmp,y);
-
+
return complex<Y>(tmp.real(),tmp.imag());
}
@@ -282,80 +282,80 @@
}
/// specialize power typeof helper for complex<Y>
-template<class Y,long N,long D>
-struct power_typeof_helper<complex<Y>,static_rational<N,D> >
-{
+template<class Y,long N,long D>
+struct power_typeof_helper<complex<Y>,static_rational<N,D> >
+{
typedef complex<
typename power_typeof_helper<Y,static_rational<N,D> >::type
- > type;
-
- static type value(const complex<Y>& x)
- {
+ > type;
+
+ static type value(const complex<Y>& x)
+ {
const static_rational<N,D> rat;
const Y m = Y(rat.numerator())/Y(rat.denominator());
-
+
return boost::units::pow(x,m);
}
};
/// specialize root typeof helper for complex<Y>
-template<class Y,long N,long D>
-struct root_typeof_helper<complex<Y>,static_rational<N,D> >
-{
+template<class Y,long N,long D>
+struct root_typeof_helper<complex<Y>,static_rational<N,D> >
+{
typedef complex<
typename root_typeof_helper<Y,static_rational<N,D> >::type
- > type;
-
- static type value(const complex<Y>& x)
- {
+ > type;
+
+ static type value(const complex<Y>& x)
+ {
const static_rational<N,D> rat;
const Y m = Y(rat.denominator())/Y(rat.numerator());
-
+
return boost::units::pow(x,m);
}
};
/// specialize power typeof helper for complex<quantity<Unit,Y> >
-template<class Y,class Unit,long N,long D>
+template<class Y,class Unit,long N,long D>
struct power_typeof_helper<complex<quantity<Unit,Y> >,static_rational<N,D> >
-{
+{
typedef typename
power_typeof_helper<Y,static_rational<N,D> >::type value_type;
typedef typename
power_typeof_helper<Unit,static_rational<N,D> >::type unit_type;
typedef quantity<unit_type,value_type> quantity_type;
- typedef complex<quantity_type> type;
-
- static type value(const complex<quantity<Unit,Y> >& x)
- {
+ typedef complex<quantity_type> type;
+
+ static type value(const complex<quantity<Unit,Y> >& x)
+ {
const complex<value_type> tmp =
pow<static_rational<N,D> >(complex<Y>(x.real().value(),
x.imag().value()));
-
+
return type(quantity_type::from_value(tmp.real()),
quantity_type::from_value(tmp.imag()));
}
};
/// specialize root typeof helper for complex<quantity<Unit,Y> >
-template<class Y,class Unit,long N,long D>
+template<class Y,class Unit,long N,long D>
struct root_typeof_helper<complex<quantity<Unit,Y> >,static_rational<N,D> >
-{
+{
typedef typename
root_typeof_helper<Y,static_rational<N,D> >::type value_type;
typedef typename
root_typeof_helper<Unit,static_rational<N,D> >::type unit_type;
typedef quantity<unit_type,value_type> quantity_type;
- typedef complex<quantity_type> type;
-
- static type value(const complex<quantity<Unit,Y> >& x)
- {
+ typedef complex<quantity_type> type;
+
+ static type value(const complex<quantity<Unit,Y> >& x)
+ {
const complex<value_type> tmp =
root<static_rational<N,D> >(complex<Y>(x.real().value(),
x.imag().value()));
-
+
return type(quantity_type::from_value(tmp.real()),
quantity_type::from_value(tmp.imag()));
}
@@ -371,14 +371,14 @@
using namespace boost::math;
using namespace boost::units;
using namespace boost::units::test;
-
+
{
//[complex_snippet_1
typedef quantity<length,complex<double> > length_dimension;
-
+
length_dimension L(complex<double>(2.0,1.0)*meters);
//]
-
+
std::cout << "+L = " << +L << std::endl
<< "-L = " << -L << std::endl
<< "L+L = " << L+L << std::endl
@@ -391,14 +391,14 @@
<< "(3/2)vL = " << root< static_rational<3,2> >(L) << std::endl
<< std::endl;
}
-
+
{
//[complex_snippet_2
typedef complex<quantity<length> > length_dimension;
-
+
length_dimension L(2.0*meters,1.0*meters);
//]
-
+
std::cout << "+L = " << +L << std::endl
<< "-L = " << -L << std::endl
<< "L+L = " << L+L << std::endl
Modified: branches/units/autoprefix/libs/units/example/composite_output.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/composite_output.cpp (original)
+++ branches/units/autoprefix/libs/units/example/composite_output.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -1,4 +1,4 @@
-// Boost.Units - A C++ library for zero-overhead dimensional analysis and
+// Boost.Units - A C++ library for zero-overhead dimensional analysis and
// unit/quantity manipulation and conversion
//
// Copyright (C) 2003-2008 Matthias Christian Schabel
@@ -8,12 +8,12 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-/**
+/**
\file
-
+
\brief composite_output.cpp
-\detailed An example of textual representations of units.
+\details An example of textual representations of units.
Output:
@verbatim
@@ -80,14 +80,14 @@
}
-int main()
+int main()
{
using namespace boost::units;
using boost::units::cgs::centimeter;
using boost::units::cgs::gram;
using boost::units::cgs::second;
using boost::units::cgs::dyne;
-
+
//[composite_output_snippet_2]
std::cout << 2.0 * dyne << std::endl
<< symbol_format << 2.0 * dyne << std::endl
@@ -111,6 +111,6 @@
<< symbol_format << si::nano*gram*centimeter/second << std::endl
<< name_format << si::nano*gram*centimeter/second << std::endl;
//]
-
+
return 0;
}
Modified: branches/units/autoprefix/libs/units/example/conversion.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/conversion.cpp (original)
+++ branches/units/autoprefix/libs/units/example/conversion.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -1,4 +1,4 @@
-// Boost.Units - A C++ library for zero-overhead dimensional analysis and
+// Boost.Units - A C++ library for zero-overhead dimensional analysis and
// unit/quantity manipulation and conversion
//
// Copyright (C) 2003-2008 Matthias Christian Schabel
@@ -8,12 +8,12 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-/**
+/**
\file
-
+
\brief conversion.cpp
-\detailed
+\details
Test explicit and implicit unit conversion.
Output:
@@ -65,21 +65,21 @@
quantity<si::length> L1 = quantity<si::length,int>(int(2.5)*si::meters);
quantity<si::length,int> L2(quantity<si::length,double>(2.5*si::meters));
//]
-
+
//[conversion_snippet_3
quantity<si::length,int> L3 = static_cast<quantity<si::length,int> >(L1);
//]
-
+
//[conversion_snippet_4
quantity<cgs::length> L4 = static_cast<quantity<cgs::length> >(L1);
//]
-
+
quantity<si::length,int> L5(4*si::meters),
L6(5*si::meters);
quantity<cgs::length> L7(L1);
-
+
swap(L5,L6);
-
+
std::cout << "L1 = " << L1 << std::endl
<< "L2 = " << L2 << std::endl
<< "L3 = " << L3 << std::endl
@@ -89,32 +89,32 @@
<< "L7 = " << L7 << std::endl
<< std::endl;
}
-
+
// test explicit unit system conversion
{
//[conversion_snippet_5
- quantity<si::volume> vs(1.0*pow<3>(si::meter));
+ quantity<si::volume> vs(1.0*pow<3>(si::meter));
quantity<cgs::volume> vc(vs);
quantity<si::volume> vs2(vc);
-
- quantity<si::energy> es(1.0*si::joule);
+
+ quantity<si::energy> es(1.0*si::joule);
quantity<cgs::energy> ec(es);
quantity<si::energy> es2(ec);
-
- quantity<si::velocity> v1 = 2.0*si::meters/si::second,
+
+ quantity<si::velocity> v1 = 2.0*si::meters/si::second,
v2(2.0*cgs::centimeters/cgs::second);
//]
-
+
std::cout << "volume (m^3) = " << vs << std::endl
<< "volume (cm^3) = " << vc << std::endl
<< "volume (m^3) = " << vs2 << std::endl
<< std::endl;
-
+
std::cout << "energy (joules) = " << es << std::endl
<< "energy (ergs) = " << ec << std::endl
<< "energy (joules) = " << es2 << std::endl
<< std::endl;
-
+
std::cout << "velocity (2 m/s) = " << v1 << std::endl
<< "velocity (2 cm/s) = " << v2 << std::endl
<< std::endl;
Modified: branches/units/autoprefix/libs/units/example/conversion_factor.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/conversion_factor.cpp (original)
+++ branches/units/autoprefix/libs/units/example/conversion_factor.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -1,4 +1,4 @@
-// Boost.Units - A C++ library for zero-overhead dimensional analysis and
+// Boost.Units - A C++ library for zero-overhead dimensional analysis and
// unit/quantity manipulation and conversion
//
// Copyright (C) 2003-2008 Matthias Christian Schabel
@@ -8,12 +8,12 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-/**
+/**
\file
-
+
\brief conversion_factor.cpp
-\detailed An example of using conversion_factor.
+\details An example of using conversion_factor.
Output:
@verbatim
@@ -49,7 +49,7 @@
using namespace boost::units;
//[conversion_factor_snippet_1
-
+
double dyne_to_newton =
conversion_factor(cgs::dyne,si::newton);
std::cout << dyne_to_newton << std::endl;
@@ -69,7 +69,7 @@
double acceleration_conversion =
conversion_factor(cgs::gal,si::meter_per_second_squared);
std::cout << acceleration_conversion << std::endl;
-
+
//]
return 0;
Modified: branches/units/autoprefix/libs/units/example/dimension.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/dimension.cpp (original)
+++ branches/units/autoprefix/libs/units/example/dimension.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -1,4 +1,4 @@
-// Boost.Units - A C++ library for zero-overhead dimensional analysis and
+// Boost.Units - A C++ library for zero-overhead dimensional analysis and
// unit/quantity manipulation and conversion
//
// Copyright (C) 2003-2008 Matthias Christian Schabel
@@ -8,12 +8,12 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-/**
+/**
\file
-
+
\brief dimension.cpp
-\detailed
+\details
Test dimension list manipulation.
Output:
@@ -44,7 +44,7 @@
namespace mpl = boost::mpl;
int main(void)
-{
+{
using namespace boost::units;
BOOST_MPL_ASSERT((boost::is_same<
@@ -61,7 +61,7 @@
dim<mass_base_dimension, static_rational<1L, 1L> >
>::type
>));
- BOOST_MPL_ASSERT((boost::is_same<energy_dimension,
+ BOOST_MPL_ASSERT((boost::is_same<energy_dimension,
mpl::push_front<
mpl::push_front<
mpl::push_front<
@@ -69,7 +69,7 @@
dim<time_base_dimension, static_rational<-2L, 1L> > >::type,
dim<mass_base_dimension, static_rational<1L, 1L> > >::type,
dim<length_base_dimension, static_rational<2L, 1L> > >::type>));
-
+
std::cout << "length_dimension = "
<< simplify_typename(length_dimension()) << std::endl
<< "mass_dimension = "
@@ -78,7 +78,7 @@
<< simplify_typename(time_dimension()) << std::endl
<< "energy_dimension = "
<< simplify_typename(energy_dimension()) << std::endl;
-
+
//[dimension_snippet_1
typedef mpl::times<length_dimension,mass_dimension>::type LM_type;
typedef mpl::divides<length_dimension,time_dimension>::type L_T_type;
@@ -87,31 +87,31 @@
static_rational<2>
>::type V_type;
//]
-
- BOOST_MPL_ASSERT((boost::is_same<LM_type,
+
+ BOOST_MPL_ASSERT((boost::is_same<LM_type,
mpl::push_front<
mpl::push_front<
dimensionless_type,
dim<mass_base_dimension, static_rational<1L, 1L> > >::type,
dim<length_base_dimension, static_rational<1L, 1L> > >::type>));
- BOOST_MPL_ASSERT((boost::is_same<L_T_type,
+ BOOST_MPL_ASSERT((boost::is_same<L_T_type,
mpl::push_front<
mpl::push_front<
dimensionless_type,
dim<time_base_dimension, static_rational<-1L, 1L> > >::type,
dim<length_base_dimension, static_rational<1L, 1L> > >::type>));
- BOOST_MPL_ASSERT((boost::is_same<V_type,
+ BOOST_MPL_ASSERT((boost::is_same<V_type,
mpl::push_front<
mpl::push_front<
dimensionless_type,
dim<time_base_dimension, static_rational<-1L, 1L> > >::type,
dim<length_base_dimension, static_rational<1L, 1L> > >::type>));
-
+
std::cout << "LM_type = " << simplify_typename(LM_type()) << std::endl
<< "L_T_type = " << simplify_typename(L_T_type()) << std::endl
<< "V_type = " << simplify_typename(V_type()) << std::endl;
-
+
return 0;
}
Modified: branches/units/autoprefix/libs/units/example/heterogeneous_unit.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/heterogeneous_unit.cpp (original)
+++ branches/units/autoprefix/libs/units/example/heterogeneous_unit.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -13,7 +13,7 @@
\brief heterogeneous_unit.cpp
-\detailed
+\details
Test heterogeneous units and quantities.
Output:
Modified: branches/units/autoprefix/libs/units/example/kitchen_sink.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/kitchen_sink.cpp (original)
+++ branches/units/autoprefix/libs/units/example/kitchen_sink.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -13,7 +13,7 @@
\brief kitchen_sink.cpp
-\detailed
+\details
More extensive quantity tests.
Output:
Modified: branches/units/autoprefix/libs/units/example/non_base_dimension.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/non_base_dimension.cpp (original)
+++ branches/units/autoprefix/libs/units/example/non_base_dimension.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -13,7 +13,7 @@
\brief non_base_dimension.cpp
-\detailed
+\details
Another example of user-defined units with conversions.
Output:
Modified: branches/units/autoprefix/libs/units/example/performance.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/performance.cpp (original)
+++ branches/units/autoprefix/libs/units/example/performance.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -13,7 +13,7 @@
\brief performance.cpp
-\detailed
+\details
Test runtime performance.
Output:
Modified: branches/units/autoprefix/libs/units/example/quantity.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/quantity.cpp (original)
+++ branches/units/autoprefix/libs/units/example/quantity.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -13,7 +13,7 @@
\brief quantity.cpp
-\detailed
+\details
Test quantity algebra.
Output:
Modified: branches/units/autoprefix/libs/units/example/quaternion.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/quaternion.cpp (original)
+++ branches/units/autoprefix/libs/units/example/quaternion.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -13,7 +13,7 @@
\brief quaternion.cpp
-\detailed
+\details
Demonstrate interoperability with Boost.Quaternion.
Output:
Modified: branches/units/autoprefix/libs/units/example/radar_beam_height.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/radar_beam_height.cpp (original)
+++ branches/units/autoprefix/libs/units/example/radar_beam_height.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -13,7 +13,7 @@
\brief radar_beam_height.cpp
-\detailed
+\details
Demonstrate library usage for user test cases suggested by Michael Fawcett.
Output:
Modified: branches/units/autoprefix/libs/units/example/systems.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/systems.cpp (original)
+++ branches/units/autoprefix/libs/units/example/systems.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -13,7 +13,7 @@
\brief systems.cpp
-\detailed
+\details
Test various non-si units
Output:
Modified: branches/units/autoprefix/libs/units/example/temperature.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/temperature.cpp (original)
+++ branches/units/autoprefix/libs/units/example/temperature.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -13,7 +13,7 @@
\brief temperature.cpp
-\detailed
+\details
Conversions between Fahrenheit and Kelvin for absolute temperatures and
temperature differences.
Modified: branches/units/autoprefix/libs/units/example/tutorial.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/tutorial.cpp (original)
+++ branches/units/autoprefix/libs/units/example/tutorial.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -2,23 +2,28 @@
// unit/quantity manipulation and conversion
//
// Copyright (C) 2003-2008 Matthias Christian Schabel
-// Copyright (C) 2008 Steven Watanabe
+// Copyright (C) 2010 Steven Watanabe
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-/**
-\file
+/*!
+\file tutorial.cpp
-\brief tutorial.cpp
+\brief Basic tutorial using SI units.
-\detailed
-Basic tutorial using si units.
+\details
+Tutorial
+Defines a function that computes the work, in joules,
+done by exerting a force in newtons over a specified distance
+in meters and outputs the result to std::cout.
+
+Also code for computing the complex impedance
+using std::complex<double> as the value type.
Output:
@verbatim
-
//[tutorial_output
F = 2 N
dx = 2 m
@@ -30,9 +35,8 @@
I*Z = (12.5,0) V
I*Z == V? true
//]
-
@endverbatim
-**/
+*/
//[tutorial_code
#include <complex>
@@ -52,37 +56,39 @@
using namespace boost::units::si;
quantity<energy>
-work(const quantity<force>& F,const quantity<length>& dx)
+work(const quantity<force>& F, const quantity<length>& dx)
{
- return F*dx;
+ return F * dx; // Defines the relation: work = force * distance.
}
int main()
{
- /// test calcuation of work
- quantity<force> F(2.0*newton);
- quantity<length> dx(2.0*meter);
- quantity<energy> E(work(F,dx));
+ /// Test calculation of work.
+ quantity<force> F(2.0 * newton); // Define a quantity of force.
+ quantity<length> dx(2.0 * meter); // and a distance,
+ quantity<energy> E(work(F,dx)); // and calculate the work done.
std::cout << "F = " << F << std::endl
<< "dx = " << dx << std::endl
<< "E = " << E << std::endl
<< std::endl;
- /// check complex quantities
- typedef std::complex<double> complex_type;
+ /// Test and check complex quantities.
+ typedef std::complex<double> complex_type; // double real and imaginary parts.
- quantity<electric_potential,complex_type> v = complex_type(12.5,0.0)*volts;
- quantity<current,complex_type> i = complex_type(3.0,4.0)*amperes;
- quantity<resistance,complex_type> z = complex_type(1.5,-2.0)*ohms;
+ // Define some complex electrical quantities.
+ quantity<electric_potential, complex_type> v = complex_type(12.5, 0.0) * volts;
+ quantity<current, complex_type> i = complex_type(3.0, 4.0) * amperes;
+ quantity<resistance, complex_type> z = complex_type(1.5, -2.0) * ohms;
std::cout << "V = " << v << std::endl
<< "I = " << i << std::endl
- << "Z = " << z << std::endl
- << "I*Z = " << i*z << std::endl
- << "I*Z == V? " << std::boolalpha << (i*z == v) << std::endl
+ << "Z = " << z << std::endl
+ // Calculate from Ohm's law voltage = current * resistance.
+ << "I * Z = " << i * z << std::endl
+ // Check defined V is equal to calculated.
+ << "I * Z == V? " << std::boolalpha << (i * z == v) << std::endl
<< std::endl;
-
return 0;
}
//]
Modified: branches/units/autoprefix/libs/units/example/unit.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/unit.cpp (original)
+++ branches/units/autoprefix/libs/units/example/unit.cpp 2010-03-10 15:42:00 EST (Wed, 10 Mar 2010)
@@ -13,7 +13,7 @@
\brief unit.cpp
-\detailed
+\details
Test unit algebra.
Output:
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk