# Unit conversion

Gerhard Gappmeier gerhard.gappmeier at ascolab.com
Mon Sep 1 15:07:08 CEST 2008

```Hi Petri

there is also a unit conversion plasmoid in
playground/base/plasma/applets/unitconverter

This uses very generic code and just works on tables.
But the tables are very small at the moment and don't contain many units.
It's just an example.

Maybe we can put this code together with your library.
I could then use your library for my plasmoid too.

The idea behind the tables is,
that it is not necessary to make own classes for each unit that
uses a different conversion and to write the conversion code again
and again for everything.
At the moment the table is hardcoded for some units,
but this could also be loaded from a configuration file,
which would be very flexible and extensible :-)

The table works on linear conversion y=k*x+d
and so it can do all typical conversions from temperatures, over lengths, to
speed and so on.
At the moment I don't see a need for a more generic conversion routine
like logarithmic conversions, but the formula could be extended if needed.

Another important advantage is, that this way it doesn't need much resources,
and it doesn't need string parsing if you want e.g. convert "mph" to "km/h".
This would also be very fast if you need to convert thousands of values.

Of course for the runner this is not important, because you need to convert
only one value.
But I think it's a good idea anyway to separate the string parsing that is
needed in a runner from the generic conversion routines.
Especially if you want to make a library that may be used from many different
kinds of applications.

On Monday 01 September 2008 14:21:54 Petri Damstén wrote:
> Hi,
>
> I was updating converter runner and decided to make conversion code more
> generic and converted it to a library. It can be used like this:
> Value v = Converter::self()->convert(Value(25.0, "kg"), "lb");
> Or:
> Value v = Converter::self()->category("mass")->convert(Value(25.0, "kg"),
> "lb");
>
> http://websvn.kde.org/trunk/KDE/kdeplasma-
> http://websvn.kde.org/trunk/KDE/kdeplasma-
>
> Since at least weather applets have they own conversion code and there is
> unit converter applet that also does this by it's own I was wondering if
> this could be shared by other plasma applets/runners?
>
> Petri

--
mit freundlichen Grüßen / best regards

Gerhard Gappmeier
ascolab GmbH - automation systems communication laboratory
Tel.: +49 9131 691 123
Fax:  +49 9131 691 128
Web: http://www.ascolab.com
GPG-Key: http://www.ascolab.com/gpg/gg.asc

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/plasma-devel/attachments/20080901/95d7d390/attachment-0001.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/plasma-devel/attachments/20080901/95d7d390/attachment-0001.sig
```