Prev Next

Function Macros

Function macros are a convenient way of manipulating and formatting various element data items. Each function macro returns a result string. There are two primary ways to use the results of function macros:

  • Direct substitution of the returned string into the output, such as: %TO_LOWER(attName)%
  • Storing the returned string as part of a variable definition such as: $name = %TO_LOWER(attName)%

Function macros can take parameters, which can be passed to the macros as:

  • String literals, enclosed within double quotation marks
  • Direct substitution macros without the enclosing percent signs
  • Variable references
  • Numeric literals

Multiple parameters are passed using a comma-separated list.

Function macros are named according to the All-Caps style, as in:

     %CONVERT_SCOPE(opScope)%

The available function macros are described here. Parameters are denoted by square brackets, as in:

     FUNCTION_NAME([param]).

CONVERT_SCOPE([umlScope])

For use with supported languages, to convert [umlScope] to the appropriate scope keyword for the language being generated. This table shows the conversion of [umlScope] with respect to the given language.

Language

Conversions

C++

Package ==> public

Public ==> public

Private ==> private

Protected ==> protected

C#

Package ==> internal

Public ==> public

Private ==> private

Protected ==> protected

Delphi

Package ==> protected

Public ==> public

Private ==> private

Protected ==> protected

Java

Package ==> {blank}

Public ==> public

Private ==> private

Protected ==> protected

PHP

Package ==> public

Public ==> public

Private ==> private

Protected ==> protected

VB

Package ==> Protected

Public ==> Public

Private ==> Private

Protected ==> Protected

VB .Net

Package ==> Friend

Public ==> Public

Private ==> Private

Protected ==> Protected

COLLECTION_CLASS([language])

Gives the appropriate collection Class for the language specified for the current linked attribute.

CSTYLE_COMMENT([wrap_length])

Converts the notes for the element currently in scope to plain C-style comments, using /* and */.

DELPHI_PROPERTIES([scope], [separator], [indent])

Generates a Delphi property.

DELPHI_COMMENT([wrap_length])

Converts the notes for the element currently in scope to Delphi comments.

EXEC_ADD_IN(, [function_name],, ..., )

Invokes an Enterprise Architect Add-In function, which can return a result string.

[addin_name] and [function_name] specify the names of the Add-In and function to be invoked.

Parameters to the Add-In function can be specified via parameters [prm_1] to [prm_n].

     $result = %EXEC_ADD_IN("MyAddin", "ProcessOperation", classGUID, opGUID)%

Any function that is to be called by the EXEC_ADD_IN macro must have two parameters: an EA.Repository object, and a Variant array that contains any additional parameters from the EXEC_ADD_IN call. Return type should be Variant.

     Public Function ProcessOperation(Repository As EA.Repository, args As Variant) As Variant

FIND([src], [subString])

Position of the first instance of [subString] in [src]; -1 if none.

GET_ALIGNMENT()

Returns a string where all of the text on the current line of output is converted into spaces and tabs.

JAVADOC_COMMENT([wrap_length])

Converts the notes for the element currently in scope to javadoc -style comments.

LEFT([src], [count])

The first [count] characters of [src].

LENGTH([src])

Length of [src]. Returns a string.

MATH_ADD(x,y) MATH_MULT(x,y) and MATH_SUB(x,y)

In a code template or DDL template, these three macros perform, respectively, the mathematical functions of:

  • Addition (x+y)
  • Multiplication (x*y) and
  • Subtraction (x-y)

The arguments x and y can be integers or variables, or a combination of the two. Consider these examples, as used in a 'Class' template for C++ code generation:

  • $a = %MATH_ADD(3,4)%
  • $b = %MATH_SUB(10,3)%
  • $c = %MATH_MULT(2,3)%
  • $d = %MATH_ADD($a,$b)%
  • $e = %MATH_SUB($b,$c)%
  • $f = %MATH_MULT($a,$b)%
  • $g = %MATH_MULT($a,10)%
  • $h = %MATH_MULT(10,$b)%

These compute, in the same sequence, to:

  • a = 3 + 4 = $a
  • b = 10 - 3 = $b
  • c = 2 * 3 = $c
  • d = a + b = $d
  • e = b - c = $e
  • f = a * b = $f
  • g = a * 10 = $g
  • h = 10 * b = $h

When the code is generated, the .h file (for C++) contains these corresponding strings:

  • a = 3 + 4 = 7
  • b = 10 - 3 = 7
  • c = 2 * 3 = 6
  • d = a + b = 14
  • e = b - c = 1
  • f = a * b = 49
  • g = a * 10 = 70
  • h = 10 * b = 70

MID([src], [start]) MID([src], [start], [count])

Substring of [src] starting at [start] and including [count] characters. Where [count] is omitted the rest of the string is included.

PI([option], [value], {[option], [value]})

Sets the PI for the current template to [value]. Valid values for [value] are:

  • "\n"
  • "\t "
  • “ “
  • “”

<option> controls when the new PI takes effect. Valid values for <option> are:

  • I, Immediate: the new PI is generated before the next non-empty template line
  • N, Next: the new PI is generated after the next non-empty template line

Multiple pairs of options are allowed in one call. An example of the situation where this would used is where one keyword is always on a new line, as illustrated here:

%PI=" "%

%classAbstract ? "abstract"%

%if classTag:"macro" != ""%

%PI("I", "\n", "N", " ")%

%classTag:"macro"%

%endIf%

class

%className%

For more details, see The Processing Instruction (PI) Macro.

PROCESS_END_OBJECT([template_name])

Enables the Classes that are one Class further away from the base Class, to be transformed into objects (such as attributes, operations, Packages, parameters and columns) of the base Class. [template_name] refers to the working template that temporarily stores the data.

REMOVE_DUPLICATES([source], [separator])

Where [source] is a [separator] separated list; this removes any duplicate or empty strings.

REPLACE([string], [old], [new])

Replaces all occurrences of [old] with [new] in the given string <string>.

RESOLVE_OP_NAME()

Resolves clashes in interface names where two method-from interfaces have the same name.

RESOLVE_QUALIFIED_TYPE() RESOLVE_QUALIFIED_TYPE([separator]) RESOLVE_QUALIFIED_TYPE([separator], [default])

Generates a qualified type for the current attribute, linked attribute, linked parent, operation, or parameter. Enables the specification of a separator other than. and a default value for when some value is required.

RIGHT([src], [count])

The last [count] characters of [src].

TO_LOWER([string])

Converts [string] to lower case.

TO_UPPER([string])

Converts [string] to upper case.

TRIM([string]) TRIM([string], [trimChars])

Removes trailing and leading white spaces from [string]. If [trimChars] is specified, all leading and trailing characters in the set of <trimChars> are removed.

TRIM_LEFT([string]) TRIM_LEFT([string], [trimChars])

Removes the specified leading characters from <string>.

TRIM_RIGHT([string]) TRIM_RIGHT([string], [trimChars])

Removes the specified trailing characters from <string>.

VB_COMMENT([wrap_length])

Converts the notes for the element currently in scope to Visual Basic style comments.

WRAP_COMMENT([comment], [wrap_length], [indent], [start_string])

Wraps the text [comment] at width [wrap_length] putting [indent] and [start_string] at the beginning of each line.

     $behavior = %WRAP_COMMENT(opBehavior, "40", "  ", "//")%

<wrap_length> must still be passed as a string, even though WRAP_COMMENT treats this parameter as an integer.

WRAP_LINES([text], [wrap_length], [start_string] {, [end_string] })

Wraps [text] as designated to be [wrap_length], adding [start_string] to the beginning of every line and [end_string] to the end of the line if it is specified.

XML_COMMENT([wrap_length])

Converts the notes for the element currently in scope to XML-style comments.

Learn more