Advanced: Creating Customized OSIs : Customizing API Definitions : Features that Facilitate API Definition : Conditional Expressions in API Definitions

Conditional Expressions in API Definitions

The OSDT also allows the use of conditional expressions in API definitions. This feature allows the inclusion of a certain string if the condition is met and the inclusion of an alternative string if the condition is not met. Basically, the feature mimics the C conditional expression, “? :”, although the syntax is slightly different.

The basic syntax is as follows:

?<begin> expression 1 ?<?> expression 2 ?<:> expression 3 ?<end>

If expression 1 evaluates to true, then expression 2 will be used in the API definition; otherwise, expression 3 will be used.

Example of using conditional expressions:

?<begin> $<prop1> ?<==> prop1val ?<?> expression when yes ?<:> expression when no ?<end>

 

In the above example, the string used in the API definition will be expression when yes if $<prop1> evaluates to prop1val. Otherwise, the string used will be expression when no.

When defining the condition (expression 1), the following symbols can be used:

?<==> (equal strings)

?<!=> (not equal strings)

?<&&> (logical AND)

?<||> (logical OR)

Expression 2 and expression 3 referred to above can consist of any expression that is legal in the API definition, including additional conditional expressions.

The following is a more complex example, which uses nested conditional expressions.

Some prefix code ?<begin> $<prop1> ?<==> prop1val

?<&&> $<prop1.1> ?<==> prop1.1val ?<?> ?<begin>

$<prop2> ?<==> prop2val ?<||> $<prop2.1> ?<==>

prop2.1val ?<?> exp 1.1 when yes ?<:> exp 1.2 when no

?<end> ?<:> exp 2 when no ?<end> Some postfix code,

then another conditional expression ?<begin> $<prop3>

?<==> prop3val ?<?> exp 3.1 when yes ?<:> exp 3.2 when

no ?<end>

 

Start with the inner conditional expression:

?<begin> $<prop2> ?<==> prop2val ?<||> $<prop2.1> ?<==> prop2.1val ?<?> exp 1.1 when yes ?<:> exp 1.2 when no ?<end>

 

This expression will evaluate to exp 1.1 when yes if either $<prop2> evaluates to “prop2val” or $<prop2.1> evaluates to “prop2.1val”. If neither of these conditions are met, then the expression will evaluate to exp 1.2 when no.

Now look at the outer conditional expression, replacing the result of the inner expression with the string “result of inner conditional expression”:

?<begin> $<prop1> ?<==> prop1val ?<&&> $<prop1.1> ?<==>

prop1.1val ?<?> result of inner conditional expression ?<:> exp 2 when no ?<end>

 

This expression will evaluate to the result of the inner conditional expression if $<prop1> evaluates to prop1val and $<prop1.1> evaluates to prop1.1val. Otherwise, the expression will evaluate to exp 2 when no.

So, assuming that:

$<prop1> = prop1val

$<prop1.1> = prop1.1val

$<prop2> <> prop2val

$<prop2.1> <> prop2.1val

$<prop3> <> prop3val

The API result will be:

Some prefix code exp 1.2 when no Some postfix code, then another conditional expression exp 3.2 when no