Boost logo

Boost :

From: Martin Bonner (martin.bonner_at_[hidden])
Date: 2006-06-09 04:00:02


----Original Message----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Andy Little Sent:
08 June 2006 17:46 To: boost_at_[hidden]
Subject: Re: [boost] [review] pqs

> Although liter is equivalent to 1 dm^3, technically its not an SI
> unit. Its not in the review version of PQS, but it is possible to
> add a liter unit to volume header and get output as
>
> 1 L
>
> or whatever is preferred... I just did this in my local version of
> PQS.
>
> The sequence of steps is
>
> 1) In <boost/pqs/meta/components/of_volume.hpp>
>
> Add a typedef for the liter in the incoherent_unit struct (starts
> at line 47).
[SNIP]

That is not good. Not good at all.

As far as I am concerned, a third party library file is (almost)
sacrosanct. I would not want to edit it except to fix the most extreme
bug - what happens when I upgrade to the next version of PQS.

Can I add liter support externally to PQS? (For example, so I can refer
to "litre").
>
> typedef meta::unit<
> boost::pqs::meta::rational<-3>,
> meta::rational<1>::type,
> boost::mpl::int_<1>
> > liter;
>
> 2)
>
> In <boost/pqs/t1_quantity/types/volume.hpp>
>
> Add the typedef for liter to the other member typedefs:
>
> typedef t1_quantity<
> type,
> typename incoherent_unit::liter,
> Value_type
> > liter;
>
> 3) In <boost/pqs/t1_quantity/types/out/volume.hpp> add the stream
> output
> overload for the liter unit:
>
> inline
> std::ostream&
> operator <<(
> std::ostream & os,
> t1_quantity_units_out<
> meta::components::of_volume::type,
> meta::components::of_volume::incoherent_unit::liter
> >
> )
> {
> os << "L";
> return os;
> }
>
>
> Check it works:
>
> #include <boost/pqs/t1_quantity/types/out/volume.hpp>
> using boost::pqs::volume;
>
> int main()
> {
> volume::liter v(1);
> std::cout << v <<'\n';
> volume::m3 v1 = v;
> std::cout << v1 <<'\n';
> }
>
> Outputs:
>
> 1 L
> 0.001 m3
>
> Because liter isnt an SI unit you would need to add cL and mL in the
> same way (I
> guess that would be the next question!)
>
> regards
> Andy Little

-- 
Martin Bonner
Martin.Bonner_at_[hidden]
Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB4 6WZ,
ENGLAND Tel: +44 (0)1223 203894

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