arg_store. The function
set_arg_val(argv)scans the list of command-line arguments for
BARand sets the corresponding member in
arg_store. It also builds up the help message (consist of the settable state names and their default values) to be printed when the program receives a '
-help' or '
-HELP' option. The state values are initialized to the corresponding
arg_storemembers during the variable initialization stage. By doing this, a state will get its default value if it is not set on the command-line.
Targetbase class is used to specify the state that is to be made settable via command-line arguments as well as to store the name to be used on the command-line. In
CGCtarget, these are stored as a character string in a
TextTable*mappings (a pointer to a
HashTablein which the data value and index are character strings) via the overloaded
isCmdArg(const State* state), is used to check whether 'state' is to be set by a command-line argument. It calls
CGCTarget::pragma()and scans through the StringList returned for the state's name. If found, the mapped name is return. Otherwise a null string is return.
Four new protected
CodeStreamare added to
CGCTargetto store the additional codes:
cmdargStructstores the struct members.
cmdargStructstores the default values.
setargFuncstores the code segment in
setargFuncHelpstores the built-up help message.
CGCStarto generate the codes:
cmdargState()to generate the members of
struct arg_storeusing the mapped name returned by
cmdargStatesInit()to generate the default values of the settable states.
setargState()to generate the code segment to match the mapped name to the command-line options.
setargStatesHelp()to build up the help message.
CGCTarget::declareStar(CGCStar* star)function after the global and main declarations have been generated.
CGCStar::initCodeState(const State* state)is modified to generate the required initialization code if state is to be settable from the command-line.
In order for a $val state to be settable from the command-line, it has to be changed to a reference state. The
expandVal()member function is overloaded in
CGCStarto check if the "name" state is to be made settable from the command-line. If so, it is added to the list of referenced state so that it will be declared and initialized.
CGCStar::cmdargState(const State* state). The
initCodeString()member functions need to be modified accordingly to generate codes for the initialization, setting function, help message and assignment respectively of the new state variable.
Also, there is no provision to check for duplicate command-line names. If there are duplicates, Ptolemy will simply generate multiple struct members with the same name, and error will result in the generated code. To get around this, a new Tk interface could be written to specify and set the settable states and checking can be done at that level. Alternatively, it might be a better idea to use the
CodeStreamto add the struct member with its unique handle to the appropriate
CodeStream. That way, there will not be duplicate struct members and state-variables could still reference the same member, so that two or more states could be set to the same value from a single argument on the command-line.
Another limitation is that the command-line capability only works for states of blocks at the top level. It will not work for states of
Universes, and states that referenced other settable states. This could probably be solved by modifying the pragma mechanism to ensure that pragmas at the top level propagate all the way down to the contained blocks. By doing this, states will inherit pragmas from their parent
galaxiesso that these can be picked up by the
isCmdArg()function, and the appropriate codes can be generated.
Certain states will affect the overall scheduling of the whole system, e.g. the factor of
downsamplingstars, and changing these would mean that new code needs to be generated since the scheduling is hard-coded into the generated code. Thus these should not be allowed to take values from the command-line. A new attribute can be introduced to identify those states that should not be settable from the command-line. Warnings can then be generated if users attempt to specify these for command-line setting.