Enums to strings

Steve Lime steve.lime at DNR.STATE.MN.US
Mon Sep 19 14:50:47 EDT 2005


Option number 2 it is then (with unknown)...

>>> Frank Koormann <frank.koormann at INTEVATION.DE> 09/17/05 8:40 AM >>>
Dear all,

* Frank Warmerdam <warmerdam at POBOX.COM> [050917 05:53]:
> On 9/16/05, Steve Lime <steve.lime at dnr.state.mn.us> wrote:
> > I was thinking of just parking the array of strings right next to the enum in map.h, but the function sounds fine too. Were you thinking of something like:
> > 
> > static char **msGetUnitsStrings()
> > {
> >   static char **values = ...;
> >   return values;
> > }
> > 
> > or something like:
> > 
> > static char *msGetUnitsString(int code)
> > {
> >   switch (code) {
> >     case 0: return "meters";
> >     case 1: return "feet";
> >       ...
> >    }
> > 
> >    return NULL;
> > }
> > 
> > The last element being the count is a good idea. We're doing that with the error codes in maperror.h but no where else I believe.
> 
> Steve,
> 
> Either way works, but the (very small) advantage of the second is that
> it is easier to convert a enum code into a string into the middle of
> an expression, such as the arguments to a debug or error message.

just a thought since the original need for this function has been template 
processing: The second option also would allow to add i18n in the furture.

Regards,

        Frank Koormann
-- 
Frank Koormann                             <frank.koormann at intevation.de>
 Professional Service around Free Software       (http://intevation.net/)
 FreeGIS Project                                 (http://freegis.org/)



More information about the mapserver-dev mailing list