Update wikipage Code Templates. (Signed-off-by:javier).

git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@1682 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
eiffel-org
2016-11-22 13:43:32 +00:00
parent 87622036a5
commit c5f2c8b7d4

View File

@@ -19,7 +19,6 @@ There are two kinds of template:
* Targetless (or “global): applicable in all contexts, without a target.
<span id="how_do_i_use_templates"></span>
= 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
<span id="template_definition"></span>
=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, thats it!
Here is how we defined the template used in the above targeted example:
<code>
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
</code>
<span id="gui_template"></span>
=Associating GUI with Template definition=