|
Boost Users : |
Subject: Re: [Boost-users] boost::units units symbols/names
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2011-07-26 16:29:56
On 7/26/2011 8:30 AM, Michael Powell wrote:
> Boost::units users,
>
> How do I get at the unit symbol or name? I think this type thing would
> be essential when receiving and parsing textual quantities from a client
> side application. So say I am given "1.0 in" or "2.3 m/s^2" and so on,
> and be able to translate that into the appropriate compile-time
> dimensional quantity.
Units are streamable and thus also can be lexical_cast.
template < typename Unit >
std::string label(Unit u) { return lexical_cast<std::string>(u); }
Being able to read them in the other way would be as simple as matching
the unit you expect to the one you've gotten. I can't think of any way
to match some generic unit and return it since every unit is a different
type. You simply have to know what to expect with this library.
What you might be looking for here is a runtime unit system. I devised
such a system around the boost quantity system that somewhat works.
Unfortunately I can't share it. Basically I have a unit that does
conversions, a quantity that stores a value, and these types convert
to/from the boost versions of the same dimension before going into math
functions. All forms of I/O and user interaction are done in this
wrapped thing and all formulas are done in a particular boost::units
system. It wasn't too difficult (except for some unfortunate things I
was forced into--such as treating 3 different kinds of flow as the same
variable).
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