| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Storing units in the database
Mikito Harakiri wrote:
> Misha Dorman wrote:
>>http://www.awprofessional.com/articles/article.asp?p=375705&seqNum=1,
Its quite simple[1] to set up a system so that expression is checked for dimensional/unit correctness and type safety (statically) using the TMP approach. Basically, just make the constructors-from-basic-types of the dimensioned type be protected, define constant static members of a friend "units" class named "kg", "m", "c" etc. (with the relevant values), and define a bunch of overloaded friend operators for *, /, +, - etc. taking mixtures of quantities and scalars to allow expressions like 20 * kg.
Then you can write something like:
quantity<float,mass> m = 10 * units::kg; quantity<float,accel> g = 9.81 * units::m / (units::sec*units::sec) quantity<float,force> f = m*a; //Note units are "implicit"
but not, say:
quantity<float,force> g = 9.81;
//ERROR -- no units (attempt to use protected ctor)
quantity<float,force> f = m/a; //ERROR -- incorrect dimensions
Misha
[1] In C++ terms, that is -- at best that generally means "horribly complex to write, but at least it can be tested easily and used painlessly". Received on Thu Jul 21 2005 - 14:47:54 CDT
![]() |
![]() |