|
Boost : |
Subject: Re: [boost] Units of data
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-07-02 00:26:48
AMDG
Zachary Turner wrote:
> Thanks for your response. I got this working mostly, but I'm still
> having difficulty seeing how to tie it all together. I added the
> following:
>
> typedef boost::units::make_system<bit_base_unit>::type data_system;
> typedef boost::units::unit<data_base_dimension::dimension_type,
> data_system> capacity;
>
> But I'm still not sure how to create and manipulate values with these
> units. For example, I can do:
>
> quantity<capacity> compressed_size;
>
> but if I try to assign it to anything I get errors. I tried using the
> BOOST_UNITS_STATIC_CONSTANT macro to create aliases such as bytes,
> megabytes, etc but I think this is the wrong approach, is it because
> all the units above are defined as base units?
>
> Ideally I want to be able to type:
>
> quantity<capacity> compressed_size = 10000 * bytes;
>
That won't quite work. Implicit conversions are banned.
typedef byte_base_unit::unit_type bytes;
quantity<capacity> compressed_size(10000 * bytes());
You can also use
BOOST_UNITS_STATIC_CONSTANT(bytes, byte_base_unit::unit_type);
to allow
10000 * bytes;
> quantity<capacity> total_size = 400000 * bytes;
>
> float ratio = compressed_size / total_size; //should be dimensionless
>
This ought to work.
> quantity<time> duration = 300 * seconds;
>
> quantity<data_rate> = total_size / duration; //has dimensions capacity/tim
This should work if data_rate is defined correctly.
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk