X(P a r a m)

Home Page

Samples of XParam Usage

Here is a sample session of what working with a program that uses XParam is like, for the user of that program. The examples make use of three programs ("simple", "involved" and "calculator"), all of which can be found in the Examples section of the User's Guide. All these programs are trivial to create with XParam.

~/bin> simple --help
This program asks you to guess an integer between 1-20
and checks whether it is larger or smaller than the
integer in file my_number.txt

Usage: progname <param1>=<val1> <param2>=<val2> -<flag1> -no_<flag2>...
Use any unambiguous prefix of the parameter names
In case of multiple assignment to the same parameter, the last holds.

Name      Type   I/O Default Value Description                         
====      ====   === ============= ===========                         
num       int     I  [ required ]  The number you've guessed           
name      string  I  "John Doe"    Your name                           
my_number int     O                This is the number in my_number.txt 

XParam tells the user what the program expects and what it prints out.

~/bin> simple num=1
John Doe, the number you guessed was too small.
my_number = 17
;

XParam handles default values, makes sure that all parameters are of the expected types, and finds suitable conversion paths if they are not.

~/bin> cat > my_shape.txt
 shape = [ Circle(Point(15,15),12), Circle(Point(9,9),4),
           Circle(Point(21,9),4), Circle(Point(15,19),6) ]
~/bin> involved @my_shape.txt

With XParam you can redirect your arguments and handle complex initializations. Here, XParam initializes an object of type Shape*, where Shape is an abstract class. It does so by assigning a Composite*, where Composite is a derivative class of Shape. XParam chose the "Composite" concrete class because it was the only derivative of shape that had a suitable constructor: one from an std::vector<Shape*>. XParam likewise determines the concrete type of each of the four elements in the vector.

In this program, class "Circle" was completely unknown to the original program. XParam loaded it dynamically when it became relevant.

~bin> calculator
 add(3.5,mul(6,5))
33.5
 def(tax,add(1,div(17,100)))
 tax
1.17
 E
0.0
 34
34.0
 mul(tax,50)
58.5
 @data/constants.dat
 E
2.71828
 Pi
3.14159
 sqrt(Pi)
1.77245
 ln(E)
1.0

The main program needed to create this calculator fits into an xterm. All it contains is the following instructions: read an expression; if that expression is an arithmetic value, evaluate it and output the result, If it is not, process it without emitting any output. All the rest is done by XParam.

An added touch here are the "ln" and "sqrt" commands. These are completely unfamiliar to the calculator program. They are loaded dynamically by XParam when they are needed, just as the "Circle" class was loaded in the previous example. The calculator shows how XParam's support for polymorphism can immediately be put to use in managing plug-ins.

User's Guide
Download
Credits
Legal Info
Help XParam
Samples
SourceForge
Files
 
 
Powered by:
SourceForge Logo