Boost logo

Boost Users :

Subject: [Boost-users] [Units] Defining units with conversions local to class instances
From: Andrew Hundt (athundt_at_[hidden])
Date: 2010-11-29 14:59:34


I'm looking to define local units specific to each instance of a class. In
this specific case I need to define a unit called "ticks" that is an angle
defined relative to degree_base_unit and radian_base_unit. Local unit
definitions are required because I am dealing with varying physical motors
that measure their position in "ticks". The number of ticks per radian is
arbitrarily defined by the manufacturer, so each class needs an independent
"ticks" definition for that specific device loaded by a config file at
runtime (so the user is not required to recompile every time they use a new
motor). Some of the pieces I need look to be there within a combination of
the examples:

http://www.boost.org/doc/libs/1_45_0/libs/units/example/runtime_conversion_factor.cpp
-
Defines a runtime conversion for global units defined to exist at compile
time
<http://www.boost.org/doc/libs/1_45_0/libs/units/example/runtime_conversion_factor.cpp>
http://www.boost.org/doc/libs/1_45_0/libs/units/example/radar_beam_height.cpp -
Defines a global unit defined at compile time
<http://www.boost.org/doc/libs/1_45_0/libs/units/example/radar_beam_height.cpp>
http://www.boost.org/doc/libs/1_45_0/libs/units/example/runtime_unit.cpp -
Only works for units defined at compile time

The key problem here is that I need to define my units locally since they
are irrelevant anywhere else while retaining the conversion and type safety
of boost.units. It looks like the
macros BOOST_UNITS_DEFINE_CONVERSION_FACTOR
and BOOST_UNITS_DEFINE_CONVERSION_FACTOR_TEMPLATE both require definition in
the global namespace.

Any thoughts would be greatly appreciated.

Cheers!
Andrew Hundt



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