Download PIMPL Organizing Files
Transcript
4.7. Library-part
Aalborg University
trees. This is solved by always connecting an else to the nearest if statement that does not
contain an else.
Persistent variable
A Persistent variable is a fixed variable, which is set at the first run of a Selector. The
listing in 4.28, shows a Persistent String fileType, which is set to the Result of the Calculator
function MostFrequentFileTypeCalc. This Calculator will therefore only be called once,
despite the Selector running on each file in the WorkFolder. Calculators are described
more in section 4.7.4. If a Persistent variable is declared in a Foreach statement, then this
value is assigned one time, while all other statements in a Foreach is run n2 times. The
Persistent variable is reset every time a rule executes.
Selector MostFrequentFileType ()
{
Persistent String fileType = MostFrequentFileTypeCalc ();
If ( ThisFile (’ FileExtension ’) == Undefined OR ThisFile (’ FileExtension ’)
== fileType )
Selected ;
Else
Deselected ;
}
Listing 4.28. An example showing a Selector that uses an If-Else and a Persistent variable.
4.7.2
Subprograms
The Library-part contains subprograms, namely Selectors and Calculators. This section
describes the formal- and actual parameters that is similar for both subprogram. After
this, the Selectors and Calculators are described in depth. PIMPL supports parse by value
parameters. The scope rules in PIMPL is static.
Formal parameters
When creating a subprogram in PIMPL, parameters can be specified to give the
subprogram some parameters to work according to. These parameters are written after
the function name in parenthesis. The code of listing 4.29 shows how formal parameters
are written, here the two parameters are of type Date, and the two variable names in the
Selector is called “start” and “end”. These can then be used in the body of the subprogram
between the two braces.
Selector FilesBetweenDates (Date start , Date end)
{
...
}
Listing 4.29. Formal parameters of the Selector FilesBetweenDates.
41