7fd59977 |
1 | generic class Array1 from TCollection (Array1Item as any) |
2 | |
3 | raises RangeError from Standard, |
4 | DimensionMismatch from Standard, |
5 | OutOfRange from Standard, |
6 | OutOfMemory from Standard |
7 | |
8 | ---Purpose: The class Array1 represents unidimensionnal arrays |
9 | -- of fixed size dynamically dimensioned at construction time.. |
10 | -- |
11 | -- The range of the index is user defined. |
12 | -- |
13 | -- As with a C array, the access time to an Array1 |
14 | -- indexed item is constant and is |
15 | -- array-size-independent. Arrays are commonly |
16 | -- used as elementary data structures for more complex objects. |
17 | -- Array1 is a generic class, which depends on |
18 | -- Item, the type of element in the array. |
19 | -- An array1 can be constructed with a "C array". |
20 | -- This functionality is useful to call methods expecting |
21 | -- an Array1. It allows to carry the bounds inside the arrays. |
22 | -- |
23 | -- Examples: Item tab[100]; // An example with a C array |
24 | -- Array1OfItem ttab (tab[0],1,100); |
25 | -- |
26 | -- Array1OfItem tttab (ttab(10),10,20); // a slice of ttab |
27 | -- |
28 | -- If you want to reindex an array from 1 to Length do : |
29 | -- |
30 | -- Array1 tab1(tab(tab.Lower()),1,tab.Length()); |
31 | -- |
32 | -- Warning: Programs client of such a class must be independant |
33 | -- of the range of the first element. Then, a C++ for |
34 | -- loop must be written like this |
35 | -- |
36 | -- for (i = A.Lower(); i <= A.Upper(); i++) |
37 | |
38 | |
39 | |
40 | is |
41 | |
42 | Create (Low, Up: Integer from Standard) |
43 | returns Array1 from TCollection |
44 | ---Purpose: Creates an array of lower bound <Low> and upper |
45 | -- bound <Up>. Range error is raised when <Up> is |
46 | -- less than <Low>. |
47 | raises |
48 | RangeError from Standard, |
49 | OutOfMemory from Standard; |
50 | |
51 | Create(Item : Array1Item; |
52 | Low, Up: Integer from Standard) |
53 | returns Array1 from TCollection |
54 | ---Purpose: Creates an array sharing datas with a C array. |
55 | -- Example: |
56 | -- Item tab[100]; |
57 | -- Array1OfItem thetab (tab[0],1,100); |
58 | -- |
59 | -- Warning: The validity of Low and Up values are under the responsability |
60 | -- of the user. |
61 | -- The C array must be a validate address during the life of |
62 | -- the Array1. |
63 | raises |
64 | RangeError from Standard; |
65 | |
66 | Init (me: in out; V: Array1Item); |
67 | ---Purpose: Initializes the array with a given value. |
68 | |
69 | Destroy (me: in out); |
70 | ---Purpose: Frees the allocated area corresponding to the |
71 | -- array. If the array was constructed either from a |
72 | -- C Array (when method Allocated returns False) |
73 | -- the Destroy doesn't delete the area. |
74 | -- |
75 | ---C++: alias ~ |
76 | |
77 | IsAllocated (me) returns Boolean from Standard; |
78 | ---Purpose: Returns True if the data was allocated by the array constructors. |
79 | -- (i.e not a slice neither a C array) |
80 | ---C++: inline |
81 | |
82 | Assign (me: in out; Other: Array1 from TCollection) |
83 | returns Array1 from TCollection |
84 | ---Purpose: Copies the contents of <Other> into <me>. <Other> |
85 | -- and <me> must have the same dimension. |
86 | -- This method is an alias of operator =. |
87 | -- Example |
88 | -- TColStd_Array1OfInteger |
89 | -- t1(1,20), t2(1,20); |
90 | -- t1.Init(3); |
91 | -- t2 = t1; |
92 | -- assert ( t2(10) == 3 ); |
93 | -- Exceptions |
94 | -- Standard_DimensionMismatch if this array |
95 | -- and array Other do not have the same dimension. |
96 | ---C++: alias operator = |
97 | ---C++: return const & |
98 | raises DimensionMismatch from Standard; |
99 | |
100 | Length (me) returns Integer from Standard; |
101 | ---Purpose: Returns the number of elements of <me>. |
102 | -- |
103 | ---C++: inline |
104 | |
105 | Lower (me) returns Integer from Standard; |
106 | ---Purpose: Returns the lower bound. |
107 | -- Warning |
108 | --Client programs of the Array1 class must be independent of the first item range.-- |
109 | ---C++: inline |
110 | |
111 | Upper (me) returns Integer from Standard; |
112 | ---Purpose: Returns the upper bound. |
113 | -- Warning |
114 | --Client programs of the Array1 class must be independent of the first item range.-- |
115 | ---C++: inline |
116 | |
117 | SetValue (me : out; Index: Integer from Standard; Value: Array1Item) |
118 | ---Purpose: Assigns the value <Value> to the <Index>-th item of this array. |
119 | -- Example |
120 | -- TColStd_Array1OfInteger |
121 | -- array(0,100); |
122 | -- array.SetValue(3,1515); |
123 | -- assert (array(3) == 1515 ); |
124 | -- Exceptions |
125 | -- Standard_OutOfRange if Index lies outside the bounds of this array. |
126 | ---C++: inline |
127 | raises OutOfRange from Standard; |
128 | |
129 | Value (me; Index:Integer from Standard) returns any Array1Item |
130 | ---Purpose: Return the value of the <Index>th element of the |
131 | -- array. |
132 | -- |
133 | ---C++: alias operator () |
134 | ---C++: return const & |
135 | ---C++: inline |
136 | raises OutOfRange from Standard; |
137 | |
138 | ChangeValue (me: in out; Index:Integer from Standard) returns any Array1Item |
139 | ---Purpose: return the value of the <Index>th element of the |
140 | -- array. |
141 | -- |
142 | ---C++: alias operator () |
143 | ---C++: return & |
144 | ---C++: inline |
145 | raises OutOfRange from Standard; |
146 | |
147 | Create (AnArray : Array1 from TCollection) |
148 | returns Array1 from TCollection |
149 | is private; |
150 | ---Purpose: Creates an Array1 by copy of an Array1. |
151 | |
152 | fields |
153 | |
154 | myLowerBound : Integer; |
155 | myUpperBound : Integer; |
156 | myStart : Address; |
157 | isAllocated : Boolean; |
158 | |
159 | end Array1 ; |
160 | |