Show in Frame No Frame
Up Previous Next Title Page Index Contents Search

Subgenerator lookup and runSuper
Subgenerator arguments

6.3.12 Subreport

Instead of defining a single large generator you can separate the generator into several subgenerators, which can call each other using either the Subgenerator template
subreport 'name' run
or simply calling the generator like a function with () (no space before the first parenthesis)
name()
The first, longer, form of the command directs all output from commands between subgenerator and run into a temporary stream, where it builds up the name of the generator to run. Normally, the only command would be a single string, e.g. ‘name’ above, but any generator commands can be used, e.g. the name of the current element’s type could be used to call different generators.

The subgenerator is executed in the same context as the parent generator is when the call is made. It thus has the same element stack as the parent, the same stack of output streams, and the same global variables (but its own new set of local variables).

Subgenerator lookup and runSuper

The subgenerator to run is looked up from the type of the current graph (in the closest containing loop), through the supertypes of that graph type to the Graph metatype. Thus graph types can override generators in their supertypes, by defining a generator with the same name. In particular, you can override the pre-defined generators from the Graph metatype by defining a generator of the same name in a graph type. For example you could add a new ‘Export graph to HTML’ generator to Class Diagram to output more detail for the individual Attributes and Operations of each class.

If the named generator is not found, a warning is shown when running from the Generator Editor; when run from elsewhere in MetaEdit+, i.e. generally by modelers, no warning is shown.

Normally when a subgenerator is called, it will be looked up from the current graph type and if not found, further up in the graph type hierarchy. However, it is also possible to look up the named generator in the supertype of the graph type containing the current generator directly using the runSuper keyword:
subreport 'generatorName' runSuper
Please note that runSuper cannot be used in Graph or in generators not stored in a particular Graph type.

Subgenerator arguments

Remember that generators can have parameters, defined as part of the generator header:
generatorName(@param1, @param2)
To pass arguments to the subgenerators, use the subreport command with an additional arguments parameter
subreport 'generatorName' arguments 'arg1', 'arg2' run
or its simplified version
generatorName('arg1', 'arg2')
In both cases, arguments are given as comma-separated list. Arguments can be also made up by multiple commands, like
subreport 'generatorName' arguments 'first' 'Arg', 'second' 'Arg' run
or
generatorName('first' 'Arg', 'second' 'Arg')
If the number of arguments supplied when calling a generator does not match the number of parameters expected by that generator, any missing parameters are given an empty string as a value, and any extra arguments are added as local variables called __extraParamN, where N is the 1-based index of the argument. A warning about this is raised when running from a Generator Editor, but not elsewhere.

Arguments to subreport calls can also be nested, e.g.
subreport 'gen1' arguments 
subreport 'gen2' arguments 'gen2arg'run 
run
or
gen1(gen2('gen2arg'))
The arguments are passed by value, and will be treated as local variables within the subgenerator. For more information about using variables, please see Section 6.5.

Show in Frame No Frame
Up Previous Next Title Page Index Contents Search