Purpose | The <arr> clause is used to define an array within a class. It is not the same as the <arr> statement. There is a syntactical difference in the format of the two: the <arr> statement uses no curly braces around its initial element values whereas the <arr> clause does. Also, the purposes of the two are different. The <arr> clause defines a member array of a class, whereas the <arr> statement merely defines an array which is stand-alone. | |
Format |
<arr type="{datatype}" name="{name and size}"> {comma-separated elements bounded by curly braces} <arr>
| |
{datatype} | the datatype of the array and all its elements | |
{name and size} | the name of the array followed by the number of elements in the array bounded by square brackets | |
{comma-separated elements bounded by curly braces} | (optional) the initial values of the array elements should be separated by commas | |
What an Array defined in an Object looks like in Run-Time Memory | ||
An array which is defined in a class will be created in an object when the object is instantiated. Let us assume that the object is called MyStudent and inherits from a class which contains the following array definition: <arr type="int" name="score[5]"> {100,50,75,90,95} </arr>
The MyStudent object will look like this in run-time memory (assuming run-time memory was empty beforehand): where xppRAM is the memory object. |
||
Renderings of an Array with Various Datatypes in Run-Time Memory | ||
Datatype | Rendering in Run-Time Memory | |
bool | arr_bool_{array name}.{array size}.="{values}" /> | |
date | arr_date_{array name}.{array size}.="{values}" /> | |
double | arr_double_{array name}.{array size}.="{values}" /> | |
float | arr_float_{array name}.{array size}.="{values}" /> | |
int | arr_int_{array name}.{array size}.="{values}" /> | |
long | arr_long_{array name}.{array size}.="{values}" /> | |
short | arr_short_{array name}.{array size}.="{values}" /> | |
string | arr_string_{array name}.{array size}.="{values}" /> | |
{array name} | name of the array | |
{array size} | number of elements in the array | |
{values} | comma-separated list of the values of the array bounded by curly braces | |
Example #1 |
<class name="XStudent" inherit=""> <construct /> <scope type="public"> <arr type="int" name="score[5]"> {100,50,75,90,95} </arr> </scope> </class> Defines an array called score which has 5 elements: the value of the 1st element is 100, the value of the 2nd is 50 and so on. |
|
Example #2 |
<class name="XStudent" inherit=""> <construct /> <scope type="public"> <arr type="int" name="score[5]"> {100,50,75,90,95} </arr> </scope> </class>
<node name="MyStudent" class="XStudent" /> The same array, score[5], is defined in the class XStudent and the string The 3rd array element has the value 75 is sent to the output stream because 75 is returned as the value of score[2]. |
|
Example #3 |
<class name="XStudent" inherit=""> <construct /> <scope type="public"> <arr type="int" name="score[5]"> {100,50,75,90,95} </arr> </scope> </class>
<node name="MyStudent" class="XStudent" /> The same array, score[5], is defined in the class XStudent. The MyStudent object is instantiated with the default values. Then the <eval> statement sets the score[2] is set to 99. The string The 3rd array element has the value 99 is sent to the output stream because 99 is returned as the value of score[2]. |