Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DSDP - Real-Time Software Components (RTSC) » Listing named values of an enum from .xs script.
Listing named values of an enum from .xs script. [message #923437] Tue, 25 September 2012 23:00 Go to next message
James Lockwood is currently offline James LockwoodFriend
Messages: 30
Registered: July 2009
Member
How can I list all of the named values of a particular enum from a script?

For example If I had the following decalred in a module IMuxOptions:
	metaonly enum Gpio0MuxSettings {
		GPIO0_MUXVALUE_GPIO = 0,			/*! GPIO (0) */
		GPIO0_MUXVALUE_U0Rx = 1,			/*! U0Rx (1) */
		GPIO0_MUXVALUE_I2C1SCL = 8,			/*! I2C1SCL (8) */
		GPIO0_MUXVALUE_U1Rx = 9				/*! U1Rx (9) */
	};


I want to first get the number of items in Gpio0MuxSettings, then cycle through each and extract the strings. So given an object, where I find <obj>.$category == "EnumVal", I want to determine which enum value it is bound to (in this case "Gpio0MuxSettings"), the number of possible named enumeration settings, and what these names are. The output would ideally be something like this:


The object is: gpio0.mux,
gpio0.mux is an enum of type "IMuxOptions.Gpio0MuxSettings",
There are 4 named values. They are:

GPIO0_MUXVALUE_GPIO
GPIO0_MUXVALUE_U0Rx
GPIO0_MUXVALUE_I2C1SCL
GPIO0_MUXVALUE_U1Rx

Thanks in advance. It would seem straightforward, but it is eluding me.

James Lockwood
Re: Listing named values of an enum from .xs script. - Solved [message #923830 is a reply to message #923437] Wed, 26 September 2012 08:28 Go to previous messageGo to next message
James Lockwood is currently offline James LockwoodFriend
Messages: 30
Registered: July 2009
Member
Just got something that works and thought I'd share.

var names;
var myenum = IMuxOptions.$spec.getDecl("Gpio7MuxSettings");
var myvals = myenum.getVals();
for (i=0; i < myvals.size(); i++) {
	print("array at index" + i + " = " + myvals.get(i).getName() );
}


In general, I find the documentation and examples for RTSC very good. However, the stuff about the Java functions and how to use $spec is lacking. There was a lot of trial and error to get this working.
Re: Listing named values of an enum from .xs script. - Solved [message #924556 is a reply to message #923830] Thu, 27 September 2012 00:11 Go to previous message
Sasha Slijepcevic is currently offline Sasha SlijepcevicFriend
Messages: 90
Registered: July 2009
Member
James,
just wanted to confirm that the solution you found is pretty much the only one that would work. There is a Java object that keeps track of all values for an enumeration type, but there is no public function or field to look up its content.
Even the code that generates C constants out of an enumeration (when needed) uses $spec to find all defined enumeration constants.
Previous Topic:console input during debugging
Next Topic:file name too long error (windows)
Goto Forum:
  


Current Time: Fri Dec 19 22:47:22 GMT 2014

Powered by FUDForum. Page generated in 0.01562 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software