From c5f2c8b7d491ebe39c9f7a9168cf814b4cb23e0c Mon Sep 17 00:00:00 2001 From: eiffel-org Date: Tue, 22 Nov 2016 13:43:32 +0000 Subject: [PATCH] Update wikipage Code Templates. (Signed-off-by:javier). git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@1682 abb3cda0-5349-4a8f-a601-0c33ac3a8c38 --- .../eiffelstudio-editor/Code-Templates.wiki | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/documentation/trunk/eiffelstudio/eiffelstudio-reference/eiffelstudio-editor/Code-Templates.wiki b/documentation/trunk/eiffelstudio/eiffelstudio-reference/eiffelstudio-editor/Code-Templates.wiki index 8f809cbe..dc20cab1 100644 --- a/documentation/trunk/eiffelstudio/eiffelstudio-reference/eiffelstudio-editor/Code-Templates.wiki +++ b/documentation/trunk/eiffelstudio/eiffelstudio-reference/eiffelstudio-editor/Code-Templates.wiki @@ -19,7 +19,6 @@ There are two kinds of template: * Targetless (or “global’): applicable in all contexts, without a target. - = How do I use templates in EiffelStudio? = @@ -57,6 +56,44 @@ To offer the template menus seen above, EiffelStudio looks in two locations: Standard templates, found in User-defined templates, which you can add at + +=What does a template definition look like?= + +It is very easy to define a template. It is all done in Eiffel, of course. You simply define a class that inherits from TEMPLATE, with any number of routines, each of which introduces one template, applicable to targets of the corresponding type. If the routine has arguments, those will be the arguments of the template. Basically, that’s it! +Here is how we defined the template used in the above targeted example: + + +class ARRAY_TEMPLATE [T -> COMPARABLE] inherit + + TEMPLATE [ARRAY [T]] + +feature -- Templates + + maximum: T + -- Maximum of `target' array. + note + tags: "Algorithm, Maximum, ARRAY" + do + across target as element loop + Result := Result.max (element.item) + end + end + + slice_maximum (low, high: INTEGER): T + -- Maximum of an array, + -- where the interval is defined by default + -- by array.lower |..| array.upper. + note + tags: "Algorithm, Maximum, ARRAY" + default: "target.lower, target.upper" + do + across low |..| high as i loop + Result := Result.max (target [i.item]) + end + end +end + + =Associating GUI with Template definition=