Enums to strings
Frank Koormann
frank.koormann at INTEVATION.DE
Sat Sep 17 09:40:55 EDT 2005
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