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 RL |
19 | #include <Standard.hxx> |
20 | #include <Standard_OutOfMemory.hxx> | |
7fd59977 | 21 | #include <Standard_OutOfRange.hxx> |
1145e2bc | 22 | #include <Standard_RangeError.hxx> |
7fd59977 | 23 | |
24 | #include Array1Item_hxx | |
25 | ||
1145e2bc RL |
26 | |
27 | //======================================================================= | |
28 | //function : TCollection_Array1 | |
29 | //purpose : | |
30 | //======================================================================= | |
31 | ||
32 | inline TCollection_Array1::TCollection_Array1 (const Standard_Integer Low, | |
33 | const Standard_Integer Up) : | |
34 | myLowerBound(Low), | |
35 | myUpperBound(Up), | |
36 | isAllocated(Standard_True) | |
37 | { | |
38 | Standard_RangeError_Raise_if(Up < Low,"TCollection_Array1::Create"); | |
39 | ||
40 | Array1Item* p = new Array1Item[Up-Low+1]; | |
41 | ||
42 | if (!p) Standard_OutOfMemory::Raise("Array1 : Allocation failed"); | |
43 | myStart = (void*)(p - myLowerBound); | |
44 | } | |
45 | ||
46 | //======================================================================= | |
47 | //function : TCollection_Array1 | |
48 | //purpose : C Array constructor | |
49 | //======================================================================= | |
50 | ||
51 | inline TCollection_Array1::TCollection_Array1(const Array1Item& AnItem, | |
52 | const Standard_Integer Low, | |
53 | const Standard_Integer Up) : | |
54 | myLowerBound(Low), | |
55 | myUpperBound(Up), | |
56 | isAllocated(Standard_False) | |
57 | { | |
58 | Standard_RangeError_Raise_if(Up < Low,"Array1::CArray"); | |
59 | myStart = (void*)( &AnItem - Low ); | |
60 | } | |
61 | ||
62 | //======================================================================= | |
63 | //function : Init | |
64 | //purpose : | |
65 | //======================================================================= | |
66 | ||
67 | inline void TCollection_Array1::Init (const Array1Item& V) { | |
68 | Array1Item* p = &ChangeValue(myLowerBound); | |
69 | const Standard_Integer n = Length(); | |
70 | for(Standard_Integer i = 0; i < n; i++) { | |
71 | p[i] = V; | |
72 | } | |
73 | } | |
74 | ||
75 | //======================================================================= | |
76 | //function : Destroy | |
77 | //purpose : | |
78 | //======================================================================= | |
79 | ||
80 | inline void TCollection_Array1::Destroy() | |
81 | { | |
82 | if (isAllocated) { | |
83 | delete [] &ChangeValue(myLowerBound); | |
84 | } | |
85 | } | |
86 | ||
7fd59977 | 87 | //======================================================================= |
88 | //function : Length | |
89 | //purpose : | |
90 | //======================================================================= | |
91 | ||
92 | inline Standard_Integer TCollection_Array1::Length () const | |
93 | { | |
94 | return myUpperBound - myLowerBound + 1 ; | |
95 | } | |
96 | ||
97 | ||
98 | //======================================================================= | |
99 | //function : Lower | |
100 | //purpose : | |
101 | //======================================================================= | |
102 | ||
103 | inline Standard_Integer TCollection_Array1::Lower () const | |
104 | { | |
105 | return myLowerBound ; | |
106 | } | |
107 | ||
108 | ||
109 | //======================================================================= | |
110 | //function : Upper | |
111 | //purpose : | |
112 | //======================================================================= | |
113 | ||
114 | inline Standard_Integer TCollection_Array1::Upper () const | |
115 | { | |
116 | return myUpperBound ; | |
117 | } | |
118 | ||
119 | ||
120 | //======================================================================= | |
121 | //function : IsAllocated | |
122 | //purpose : | |
123 | //======================================================================= | |
124 | ||
125 | inline Standard_Boolean TCollection_Array1::IsAllocated () const | |
126 | { | |
127 | return isAllocated; | |
128 | } | |
129 | ||
130 | //======================================================================= | |
131 | //function : Value | |
132 | //purpose : | |
133 | //======================================================================= | |
134 | ||
135 | inline const Array1Item& TCollection_Array1::Value | |
136 | (const Standard_Integer Index) const | |
137 | { | |
138 | Standard_OutOfRange_Raise_if((Index < myLowerBound || Index > myUpperBound),NULL); | |
139 | return ((Array1Item *)myStart)[Index]; | |
140 | } | |
141 | ||
142 | //======================================================================= | |
143 | //function : SetValue | |
144 | //purpose : | |
145 | //======================================================================= | |
146 | ||
147 | inline void TCollection_Array1::SetValue (const Standard_Integer Index, | |
148 | const Array1Item& Value) | |
149 | { | |
150 | Standard_OutOfRange_Raise_if((Index < myLowerBound || Index > myUpperBound),NULL); | |
151 | ||
152 | ((Array1Item *)myStart)[Index] = Value ; | |
153 | } | |
154 | ||
155 | ||
156 | //======================================================================= | |
157 | //function : ChangeValue | |
158 | //purpose : | |
159 | //======================================================================= | |
160 | ||
161 | inline Array1Item& TCollection_Array1::ChangeValue(const Standard_Integer Index) | |
162 | { | |
163 | Standard_OutOfRange_Raise_if((Index < myLowerBound || Index > myUpperBound),NULL); | |
164 | ||
165 | return ((Array1Item *)myStart)[Index]; | |
166 | } | |
167 | ||
168 | ||
169 |