|
From: David W <di...@ho...> - 2009-04-30 23:22:56
|
Fintan, thanks. I hadn't even looked at the fly rules and didn't
realize how powerful they could be. I tried out what you described and
that worked.
I don't suppose there would be a way to use fly
rules and virtual options to create a new instance of a user defined
object? With the method mentioned previously, I would just need to pass
an enum value to a factory if I needed to create objects of a specific
type. I was wondering if I could even bypass the creation of this
factory and have CLOPS return back a new object of the type that I need
(they would all be subclasses of a single base class). So basically, it
would be nice if I could define an arg with type "Command" and then be
able to return back "CMD1Command" and "CMD2Command" depending on which
command was set.
Date: Thu, 30 Apr 2009 19:14:44 +0100
Subject: Re: [Clops-users] usage after parsing
From: fi...@gm...
To: di...@ho...
CC: clo...@li...
Hi David,
Thanks for the question. If I understand you correctly, what I would recommend is this:
-Create a "virtual option" (i.e. an option that is not reachable in the FORMAT:: section, but is defined in ARGS::) of type "enum".
e.g.
ChosenCommand:{}:{enum}:[choices="CMD1,CMD2,CMD3"]
-Create some fly rules to set the ChosenCommand option when any of your commands are set. I'm not sure if you know about fly rules, but they are rules that can are triggered when a certain option is set.
e.g.
CMD1 {$(CMD1)} -> ChosenCommand := {"CMD1"};
There's quite a bit going on in that example, so I'll break it down. The first CMD1 indicates that it is a rule that should be fired when option CMD1 is set. The curly braces are used to delimit where you can write arbitrary Java code. In the first case the code must be a boolean expression. In the second case it is an expression that is of the correct type for the object we are assigning to, which in this case is a String for ChosenCommand.
You could read the whole rule as: If CMD1 is set then check if CMD1 is
true. If it is true set ChosenCommand to the value "CMD1".
The $(CMD1) inside the braces is a placeholder that is converted into code that gets the value for the CMD1 option. I'm assuming your commands are all boolean options? If they are booleans and you are not allowing the user to write CMD1=false (disallow by setting property allowarg="false" in the option definition), then you can omit the {$(CMD1)} as this will always be true. Thus:
CMD1 -> ChosenCommand := {"CMD1"};
-In the code where you direct the program's execution by the option values, you can simply get the value of the option ChosenCommand. Note that if you use the enum option type, we automatically generate an enum with the choices you provided in the option's specification. The enum definition will appear in the generated OptionInterface, and will be the return type for the getChosenCommand() method.
I hope I've answered your question. If any of the above is not clear, or you want to know more, just ask.
Cheers,
Fintan
_________________________________________________________________
Rediscover Hotmail®: Get e-mail storage that grows with you.
http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Storage2_042009 |