Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Units - Can't figure out how to use it
From: Brandon Olivares (programmer2188_at_[hidden])
Date: 2009-12-23 14:28:17


On 2009-12-23, Steven Watanabe wrote:
> AMDG
>
> Brandon Olivares wrote:
>> I have a few other questions now though.
>>
>> It is able to do scaling of units I know, but let's say you want to
>> use kilometer for instance. It appears you cannot have two length
>> units under the same system (correct?), so would you have to create
>> a new system just for that unit?
>>
>> More practically, I need to use most of the astronomical units, or
>> at least light years, parsecs, and astronomical units. It seems I
>> can't put them under the same system, so must I have a separate
>> system for each of them, or am I missing something?
>>
>
> You can just use the ::unit_type typedef in each base unit, if you
> don't want to worry about systems.
>

I have one more question about unit_type vs. system.

If I want a unit composed of several base units, how would I do that if I
just use unit_type as you were suggesting?

For instance, right now I have something like the following, just for
testing.

#ifndef BOOST_UNITS_ASTRONOMICAL_LIGHT_SECOND_HPP
#define BOOST_UNITS_ASTRONOMICAL_LIGHT_SECOND_HPP

#include <boost/units/base_units/astronomical/light_second.hpp>
#include <boost/units/base_units/si/second.hpp>
#include <boost/units/physical_dimensions/length.hpp>
#include <boost/units/physical_dimensions/velocity.hpp>
#include <boost/units/systems/astronomical/base.hpp>

namespace boost
{
namespace units
{
namespace light_second
{

typedef make_system<
boost::units::astronomical::light_second_base_unit,
boost::units::si::second_base_unit>::type system;

typedef unit<dimensionless_type, system> dimensionless;
typedef unit<length_dimension, system> length;
typedef unit<velocity_dimension, system> velocity;

BOOST_UNITS_STATIC_CONSTANT(light_second, length);
BOOST_UNITS_STATIC_CONSTANT(light_seconds, length);
BOOST_UNITS_STATIC_CONSTANT(light_second_per_second, velocity);
BOOST_UNITS_STATIC_CONSTANT(light_seconds_per_second, velocity);

} // namespace light_second
} // namespace units
} // namespace boost

#endif

Let's just say for instance that I wanted also light_year as a unit, and
perhaps light_speed (light_year/year) or something like that. Using a system
as above, it'd be impossible to define them in the same way, so I'm curious
how you'd use unit_type as you mentioned to do this. I think you can do
something like:

BOOST_UNITS_STATIC_CONSTANT(light_year,boost::units::astronomical::light_yea
r_base_unit::unit_type);

But I don't know how you can combine two units to get velocity.

Brandon

> In Christ,
> Steven Watanabe
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

--
Brandon
www.creatorspiritus.com
Blog and forum discussing living a Christ-centered life
Follow me on Twitter: http://twitter.com/devbanana

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net