arg_store
. The function set_arg_val(argv)
scans the list of command-line arguments for FOO
and BAR
and 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 '-h
', '-help
' or '-HELP
' option. The state values are initialized to the corresponding arg_store
members during the variable initialization stage. By doing this, a state will get its default value if it is not set on the command-line.
Target
base 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 HashTable
in which the data value and index are character strings) via the overloaded pragma()
member functions.A function,
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
CodeStream
are added to CGCTarget
to store the additional codes:
cmdargStruct
stores the struct members.
cmdargStruct
stores the default values.
setargFunc
stores the code segment in set_arg_val()
.
setargFuncHelp
stores the built-up help message.
CGCStar
to generate the codes:
cmdargStates()
calls cmdargState()
to generate the members ofstruct arg_store
using the mapped name returned by isCmdArg()
.
cmdargStatesInits()
calls cmdargStatesInit()
to generate the default values of the settable states.
setargStates()
calls setargState()
to generate the code segment to match the mapped name to the command-line options.
setargStatesHelps()
calls 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 CGCStar
to 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 cmdargStatesInit()
, setargState()
, setargStatesHelp()
and 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
put()
method in CodeStream
to 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
Galaxies
and 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 galaxies
so 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
upsampling
and downsampling
stars, 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.