Boost logo

Boost :

From: Janek Kozicki (janek_listy_at_[hidden])
Date: 2006-06-17 19:23:22


Hello,

Actually when I was writing a review I have written a leghty paragraph
about unit scaling during serialization. But later I decided that review
is not a good place to put it, so I'm pasting it now below:

    One of my first thoughts was about making it easier for the end user to
perform serialization, more precisely, consider the first screenshot in
following URL:

    http://yade.berlios.de/index.php?m=700:70
    
    You can see here "File Generator" window, in the bottom part of this window
all attributes registered for serialization of class BoxStack (which derives
from FileGenerator) are displayed. Yade has it's own serialization library
which currently supports binary format, xml and QT dialog boxes, so basically
here visible is the result of serialization with QT backend.

    The idea is about user interface for this dialog box. I would like to add a
drop-down menu next to the each phisical quantity in this window. So for
example (as seen on the screenshot) single line:

                   +-----------------------+
    dampingForce : | |
                   +-----------------------+

    would now look like:

                   +----------------+ +----+
    dampingForce : | | | kN |
                   +----------------+ +-\/-+

    Where the drop-down menu would show for example "N","kN","MN", etc...
Either all of them (including even uN), or more preferably only those
that have been typedefind (or included) by the user of the library.

    Then yade user willl be able to chose the unit he wants from the menu,
then enter the value.

    To acheive this in the library I would need following interface, first a
function which returns a list of all allowed names for a given named_quantity,
for example:
    
    const std::vector<std::string>& get_unit_names();

    With this list I can initialize the drop-down menu. Next I need the ability
to initialize a named quantity by a combo of numerical_value and std::string.
Where std::string is of course the unit name chosen by the user (eg. "kN"),
like this:

    // in some place of code (in BoxStack.hpp, actually)
    pqs::force::N dampingForce;

    // then inside qt-serialization backend:
    // this value is typed by the user into the dialog box
    double forceValue;

    // unit magnitude is selected by the user from the drop-down menu
    std::string unitName="kN";

    // call constructor to assign the value intended by the user
    dampingForce=pqs::force::N(forceValue,unitName);

    I'm sure that above interface would be similarly useful to give greater
functionality to plain old cin >> . Actually cin >> seems to have exactly those
problems which above could solve:

#include <boost/pqs/t1_quantity/types/out/length.hpp>
#include <boost/pqs/t1_quantity/io/input.hpp>
namespace pqs = boost::pqs;
int main()
{
        pqs::length::mm length;

        // type "123 mm" - and it works, type "123 m" - and it doesn't work
        std::cin >> length;
        std::cout << length << '\n';
}

    I presume that only t2_quantity gives what I need above. But if
conversion from t2_quantity to t1_quantity is possible, then maybe all
that t1_quantity -> t2_quantity -> t1_quantity conversions could be
hidden from the user behind the interface? So that only those two
interface functions I mentioned above will be used.

PS: please note that this comment is *old* so I'm still using here old
names (t1, t2,...) and other stufff that likely is already decided that
it will be modified to better suit the needs/suggestions/comments of all
people. But the need for described above interface still remains.

-- 
Janek Kozicki                                                         |

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk