Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1998-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
3 | // | |
4 | // The content of this file is subject to the Open CASCADE Technology Public | |
5 | // License Version 6.5 (the "License"). You may not use the content of this file | |
6 | // except in compliance with the License. Please obtain a copy of the License | |
7 | // at http://www.opencascade.org and read it completely before using this file. | |
8 | // | |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
11 | // | |
12 | // The Original Code and all software distributed under the License is | |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
14 | // Initial Developer hereby disclaims all such warranties, including without | |
15 | // limitation, any warranties of merchantability, fitness for a particular | |
16 | // purpose or non-infringement. Please see the License for the specific terms | |
17 | // and conditions governing the rights and limitations under the License. | |
18 | ||
1145e2bc | 19 | #include <Standard.hxx> |
7fd59977 | 20 | #include <Standard_OutOfRange.hxx> |
21 | ||
22 | #include Array2Item_hxx | |
23 | ||
1145e2bc RL |
24 | //======================================================================= |
25 | //function : TCollection_Array2 | |
26 | //purpose : | |
27 | //======================================================================= | |
28 | ||
29 | inline TCollection_Array2::TCollection_Array2 (const Standard_Integer R1, | |
30 | const Standard_Integer R2, | |
31 | const Standard_Integer C1, | |
32 | const Standard_Integer C2) : | |
33 | myLowerRow(R1), | |
34 | myLowerColumn(C1), | |
35 | myUpperRow(R2), | |
36 | myUpperColumn(C2), | |
37 | myDeletable(Standard_True) | |
38 | { | |
39 | Allocate (); | |
40 | } | |
41 | ||
42 | //======================================================================= | |
43 | //function : TCollection_Array2 | |
44 | //purpose : User allocated data | |
45 | //======================================================================= | |
46 | ||
47 | inline TCollection_Array2::TCollection_Array2 (const Array2Item& Item, | |
48 | const Standard_Integer R1, | |
49 | const Standard_Integer R2, | |
50 | const Standard_Integer C1, | |
51 | const Standard_Integer C2) : | |
52 | myLowerRow(R1), | |
53 | myLowerColumn(C1), | |
54 | myUpperRow(R2), | |
55 | myUpperColumn(C2), | |
56 | myDeletable(Standard_False), | |
57 | myData((void*)&Item) | |
58 | { | |
59 | Allocate (); | |
60 | } | |
61 | ||
62 | //======================================================================= | |
63 | //function : Init | |
64 | //purpose : | |
65 | //======================================================================= | |
66 | ||
67 | inline void TCollection_Array2::Init (const Array2Item& V) | |
68 | { | |
69 | Standard_Integer Size = RowLength() * ColLength(); | |
70 | Array2Item* p = &(ChangeValue(myLowerRow,myLowerColumn)); | |
71 | for (Standard_Integer I = 0; I < Size ; I++) p[I] = V; | |
72 | } | |
73 | ||
74 | //======================================================================= | |
75 | //function : Destroy | |
76 | //purpose : | |
77 | //======================================================================= | |
78 | ||
79 | inline void TCollection_Array2::Destroy () | |
80 | { | |
81 | Array2Item** anItemPtr = ((Array2Item**)myData + myLowerRow); | |
82 | ||
83 | // delete the data | |
84 | // | |
85 | if (myDeletable) | |
86 | delete [] &ChangeValue(myLowerRow,myLowerColumn); | |
87 | ||
88 | // delete the indirection table | |
89 | Standard::Free((void*&)anItemPtr); | |
90 | } | |
91 | ||
7fd59977 | 92 | //======================================================================= |
93 | //function : ColLength | |
94 | //purpose : | |
95 | //======================================================================= | |
96 | inline Standard_Integer TCollection_Array2::ColLength () const | |
97 | { | |
98 | return myUpperRow - myLowerRow + 1 ; | |
99 | } | |
100 | ||
101 | //======================================================================= | |
102 | //function : LowerCol | |
103 | //purpose : | |
104 | //======================================================================= | |
105 | inline Standard_Integer TCollection_Array2::LowerCol () const | |
106 | { | |
107 | return myLowerColumn ; | |
108 | } | |
109 | ||
110 | //======================================================================= | |
111 | //function : LowerRow | |
112 | //purpose : | |
113 | //======================================================================= | |
114 | inline Standard_Integer TCollection_Array2::LowerRow () const | |
115 | { | |
116 | return myLowerRow; | |
117 | } | |
118 | ||
119 | //======================================================================= | |
120 | //function : RowLength | |
121 | //purpose : | |
122 | //======================================================================= | |
123 | inline Standard_Integer TCollection_Array2::RowLength () const | |
124 | { | |
125 | return myUpperColumn - myLowerColumn + 1 ; | |
126 | } | |
127 | ||
128 | //======================================================================= | |
129 | //function : UpperRow | |
130 | //purpose : | |
131 | //======================================================================= | |
132 | inline Standard_Integer TCollection_Array2::UpperRow () const | |
133 | { | |
134 | return myUpperRow ; | |
135 | } | |
136 | ||
137 | //======================================================================= | |
138 | //function : UpperCol | |
139 | //purpose : | |
140 | //======================================================================= | |
141 | inline Standard_Integer TCollection_Array2::UpperCol () const | |
142 | { | |
143 | return myUpperColumn ; | |
144 | } | |
145 | ||
146 | //======================================================================= | |
147 | //function : SetValue | |
148 | //purpose : | |
149 | //======================================================================= | |
150 | ||
151 | inline void TCollection_Array2::SetValue ( const Standard_Integer Row, | |
152 | const Standard_Integer Col, | |
153 | const Array2Item& Value ) | |
154 | { | |
155 | Standard_OutOfRange_Raise_if((Row < myLowerRow || Row > myUpperRow || | |
156 | Col < myLowerColumn || Col > myUpperColumn), | |
157 | NULL); | |
158 | ||
159 | ((Array2Item **)myData)[Row][Col] = Value ; | |
160 | } | |
161 | ||
162 | //======================================================================= | |
163 | //function : Value | |
164 | //purpose : | |
165 | //======================================================================= | |
166 | inline const Array2Item& TCollection_Array2::Value(const Standard_Integer Row, | |
167 | const Standard_Integer Col) const | |
168 | { | |
169 | Standard_OutOfRange_Raise_if((Row < myLowerRow || Row > myUpperRow || | |
170 | Col < myLowerColumn || Col > myUpperColumn), | |
171 | NULL); | |
172 | ||
173 | return ((Array2Item **)myData)[Row][Col]; | |
174 | } | |
175 | ||
176 | //======================================================================= | |
177 | //function : ChangeValue | |
178 | //purpose : | |
179 | //======================================================================= | |
180 | ||
181 | inline Array2Item& TCollection_Array2::ChangeValue(const Standard_Integer Row, | |
182 | const Standard_Integer Col) | |
183 | { | |
184 | Standard_OutOfRange_Raise_if((Row < myLowerRow || Row > myUpperRow || | |
185 | Col < myLowerColumn || Col > myUpperColumn), | |
186 | NULL); | |
187 | ||
188 | return ((Array2Item **)myData)[Row][Col]; | |
189 | } | |
190 | ||
191 | ||
192 |