|
From: Mikoláš J. <mik...@gm...> - 2009-05-01 12:34:49
|
Hi David,
technically this is possible as you can extend the option types
yourself and the rules can contain any java code.
However, it's something that I'd discourage you from doing as the
CLOPS file was meant to be as Java-independent as possible and should
express only the logic of options, not the program. There's always a
blurry line between the program and option processing, so this is a
matter of personal opinion.
mikolas
On Fri, May 1, 2009 at 12:22 AM, David W <di...@ho...> wrote:
> 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. Check it out.
> ------------------------------------------------------------------------------
> Register Now & Save for Velocity, the Web Performance & Operations
> Conference from O'Reilly Media. Velocity features a full day of
> expert-led, hands-on workshops and two days of sessions from industry
> leaders in dedicated Performance & Operations tracks. Use code vel09scf
> and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
> _______________________________________________
> Clops-users mailing list
> Clo...@li...
> https://lists.sourceforge.net/lists/listinfo/clops-users
>
>
--
Mikoláš Janota M. Sc.
School of Computer Science and Informatics,
University College Dublin,
Belfield,
Dublin 4,
Ireland
|