Re: [Quantity-users] Re: [Quantity-devel] generating a list of all units for a certain quantity
Brought to you by:
berndspeiser
|
From: Bernd S. <ber...@un...> - 2004-07-06 15:38:02
|
I'm sending this to quantity-devel only, since this is technical stuff. The problem Kai detected is difficult to solve. In fact, regrettably, I hadn't even really tested the constructor Variable (value, unit) in the situation where unit is generated by lookup of the unit string. the lookup function AllUnits::unit (std::string) returns a pointer the the base class of the unit found, i.e. TimeUnit if a Minute is found. That's ok if we just need one of the virtual functions of this object, e.g. standard () (see, method read_value in Variable.h). If we want to use the constructor above, it relies on the correctness of the type of the unit object passed, since it does check (at compile time) whether this type occurs in the list of units of the quantity in question. Of course, the base class is not in the list!! On the other hand, I think, we can not know at compile time the string of the unit symbol anyway, can we? It might be supplied by the user through a GUI for example. Thus, there is no way to compile time check the correctness of the unit object anyway. I suggest to have another constructor Variable (value, std::string) which generates the corresponding unit object at run time through AllUnits::unit (), does the necessary computation and the throws away this object. Note, that a statement like Time t (1.0, Minute ()) generates a Time object which stores its value in seconds, the Minute just indicates that the value 1.0 is to be interpreted as a minute! An object which stores in minutes would be MinuteTime! This would also solve the problem of having the caller require to delete the generated object. It could be done hidden inside the constructor. Maybe AllUnits::unit should then be made private. Would that help? Bernd -- ======================================================================= Bernd Speiser Institut f"ur Organische Chemie Auf der Morgenstelle 18 D-72076 T"ubingen Germany phone: +49-7071-2976205 (office) +49-7071-2976242 (laboratory) fax: +49-7071-295518 e-mail: ber...@un... Internet: http://www.uni-tuebingen.de/speiser ======================================================================= |