Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2004-01-02 07:31:06


Hi to all at boost,

    Continuing experiments with the physical-quantities type have shown it
to be very suitable as the basis for a runtime modifiable unit physical
quantity type, which I know is something that has been requested quite a few
times
Sample code/use for a runtime modifiable type based on the physical-quantity
type below.--->
(Capacitance used here but any physical-quantity can be substituted (D.A
checked), by changing the params)
For those interested I hope to update the download on my site to include the
runtime type sometime before Thursday 8th Jan.2004
http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/index.html
In the longer run I also hope to provide more safe conversions for those
that require them, but that is further off.
To all those who have tried out the type .... apologies about the
discrepancies in the pq_types headers... will try to unify them all asap.
One day I hope to put the code back up on boost files... but the docs are
lagging way behind the coding.

regards
Andy Little
-----------------------------------------------------
#include "../pqs.hpp"
#include "rt_quantity.hpp" // runtime type header
using namespace physical_quantities;

int main()
{ // example p_quantity for initialising rt_quantity
    q_capacitance::uF uF(1);

    // rt_quantity initialised by uF ie internal units --> uF
    rt_quantity<q_capacitance::zbase,double> Capacitance(uF);
    std::cout << "uF: ";
    Capacitance.put(std::cout);
    std::cout << '\n';

    // convert internal units to nF , also modifies Capacitance internal
value to new units
    Capacitance.set_units<q_capacitance::nF>();
    std::cout << "nF: ";
    Capacitance.put(std::cout);
    std::cout << '\n';

    // return a cast to a p_quantity in Farads
    // (internal value and units of Capacitance unchanged)
    std::cout << "to Farads: " <<
Capacitance.p_quantity_cast<q_capacitance::F>() << '\n';
}
/*
output
uF: 1 uF
nF: 1000 nF
to Farads: 1e-006 F
*/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk