comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Best way to share 'enum' between various functions
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Best way to share 'enum' between various functions [message #77774] Mon, 26 September 2011 09:40
Brian Wolven is currently offline  Brian Wolven
Messages: 94
Registered: May 2011
Member
Another method is to define a structure, each tag of which corresponds to one of the constant definitions you may need. You can write a function that simply defines the structure and returns it to the calling procedure. In use it would look something like this:

my_con = my_constants()

some_variable = my_con.maritime
other variable = my_con.urban

You can also easily "browse" your definitions:

help,/struct,my_constants()
Re: Best way to share 'enum' between various functions [message #77787 is a reply to message #77774] Sat, 24 September 2011 06:05 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Robin Wilson writes:

> I have a number of constant definitions that I'm using to do what an
> enum would do in other languages:
>
> MARITIME = 1
> CLOUD = 2
> URBAN = 3
> ...
>
> I want these definitions to be available to a lot of different functions
> and procedures (all in different files) in my code - they are used a lot
> in IF statements and various assignments.
>
> Obviously I don't want to replicate the definitions in loads of
> different files, as if I ever change them (or add extra ones) then it
> will get *very* confusing.
>
> What's the best way to do this?

Many of the people I know who do this have a list
of system variables that they create in a start-up
file. Like programs themselves, you have to keep
one eye open for naming conflicts, but it seems
to work reasonably well.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Line plot with arrows
Next Topic: Re: Black background in IDL 8.1 map projections?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:20:21 PDT 2025

Total time taken to generate the page: 0.00467 seconds