[Tfug] Developer question

Jude Nelson judecn at gmail.com
Mon Jul 2 22:49:09 MST 2007


/*
This is a slightly different approach (i.e. depends on calling a run-time
method just as the program starts), but it will ensure that for each
color in color_t there exists a string form:
*/

#include <map>
#include <string>

using namespace std;

enum color_t {
       // By convention, must begin with '0'
       RED = 0,
       GREEN,
       BLUE,
};

// map colors in the enum to strings
map< int, string > colorMap;

#define TO_STRING( x )   #x
#define MAKE_COLOR( color ) ( colorMap[ color ] = string( TO_STRING( color )
) )

// call this before anything else
void init( void ) {

colorMap = map< int, string >();

// color definitions go here as macro code
MAKE_COLOR( RED );
MAKE_COLOR( GREEN );
MAKE_COLOR( BLUE );

}

// main function, etc.
int main( int argc, char** argv ) {

init();

/* Code goes here */
}

On 7/2/07, jblais <joe.blais at pti-instruments.com> wrote:
>
>
>
> > -----Original Message-----
> > From: tfug-bounces at tfug.org [mailto:tfug-bounces at tfug.org]On Behalf Of
> > Robert Hunter
> > Sent: Monday, July 02, 2007 6:01 PM
> > To: Tucson Free Unix Group
> >        GREEN,
> >        BLUE,
> >        /* add new colors above this line */
> >        COLOR_T_ENTRIES
> > };
> >
> > static const char *
> > colornames[COLOR_T_ENTRIES] = {
> >        "Red",
> >        "Green",
> >        "Blue",
> > };
> >
> >
> > --
> > Rob
> >
>
>
> I was a bit slow -- joe
>
> _______________________________________________
> Tucson Free Unix Group - tfug at tfug.org
> Subscription Options:
> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
>



More information about the tfug mailing list