Code for Dealing with Parameter Files

This is a set of classes I used to define values for various parameters in programs. It allows the programmer to define default values, then override these from either a file, or from the command line. It also provides a way to dump out the values in a format that can later be read in again - in this way you can set a bunch of parameters, print them out, then later re-run the program with the same parameters.

The syntax for definitions is very simple. It consists of "name=value". Blank lines in a file are ignored as are lines beginning with #, and trailing "#...." are also stripped. Arguments in an array of strings can also be parsed - so a program can be invoked "foo name=value name=value" and the "name=value" will be read by the defaults mechanism.

The classes provide the capability of defining strings, integers, FLTD's, BOOLS and "tokens" (strings without whitespace).

To use this, you need to define a "DEFINITION_TABLE", add default definitions to it, then these can be modified and then looked up.

So typical usage might look like:


   main (args : ARRAY{STR}) is
      params ::= #DEFINITION_TABLE ;
      params . defStr("parameter-file", "none") ;
      params . defInt("size", 10) ; -- define default size to be 10
      params . setFromArgs(args) ;  -- read any parameters from the args
      -- 

      -- if the args contained a "parameter-file=" parse that
      -- too 

      --
      if params . getStr("parameter-file") /= "none" then
          params . read(params.getStr("parameter-file")) ;
      end ; 

      params . dump ;  -- dump out the params for the user

      foo : INT := params.getInt("size") ; -- get the size parameter
      foof : FLTD := params.getFloat("size") ; -- even get it as a FLTD 

   end ;

The code is almost completely uncommented. I've been using this for a while now and it seems to work nicely. It shows class structure and a few places where things need to be bent a bit to make sather happy.