Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 | 2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 3 | // |
973c2be1 | 4 | // This file is part of Open CASCADE Technology software library. |
b311480e | 5 | // |
d5f74e42 | 6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
10 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 11 | // |
973c2be1 | 12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. | |
b311480e | 14 | |
1145e2bc | 15 | #include <Standard.hxx> |
7fd59977 | 16 | #include <Standard_OutOfRange.hxx> |
1145e2bc | 17 | #include <Standard_RangeError.hxx> |
7fd59977 | 18 | |
19 | #include Array1Item_hxx | |
20 | ||
1145e2bc RL |
21 | |
22 | //======================================================================= | |
23 | //function : TCollection_Array1 | |
24 | //purpose : | |
25 | //======================================================================= | |
26 | ||
27 | inline TCollection_Array1::TCollection_Array1 (const Standard_Integer Low, | |
28 | const Standard_Integer Up) : | |
29 | myLowerBound(Low), | |
30 | myUpperBound(Up), | |
31 | isAllocated(Standard_True) | |
32 | { | |
33 | Standard_RangeError_Raise_if(Up < Low,"TCollection_Array1::Create"); | |
34 | ||
35 | Array1Item* p = new Array1Item[Up-Low+1]; | |
36 | ||
1145e2bc RL |
37 | myStart = (void*)(p - myLowerBound); |
38 | } | |
39 | ||
40 | //======================================================================= | |
41 | //function : TCollection_Array1 | |
42 | //purpose : C Array constructor | |
43 | //======================================================================= | |
44 | ||
45 | inline TCollection_Array1::TCollection_Array1(const Array1Item& AnItem, | |
46 | const Standard_Integer Low, | |
47 | const Standard_Integer Up) : | |
48 | myLowerBound(Low), | |
49 | myUpperBound(Up), | |
50 | isAllocated(Standard_False) | |
51 | { | |
52 | Standard_RangeError_Raise_if(Up < Low,"Array1::CArray"); | |
53 | myStart = (void*)( &AnItem - Low ); | |
54 | } | |
55 | ||
1145e2bc RL |
56 | //======================================================================= |
57 | //function : Destroy | |
58 | //purpose : | |
59 | //======================================================================= | |
60 | ||
61 | inline void TCollection_Array1::Destroy() | |
62 | { | |
63 | if (isAllocated) { | |
64 | delete [] &ChangeValue(myLowerBound); | |
65 | } | |
66 | } | |
67 | ||
7fd59977 | 68 | //======================================================================= |
69 | //function : Length | |
70 | //purpose : | |
71 | //======================================================================= | |
72 | ||
73 | inline Standard_Integer TCollection_Array1::Length () const | |
74 | { | |
75 | return myUpperBound - myLowerBound + 1 ; | |
76 | } | |
77 | ||
78 | ||
79 | //======================================================================= | |
80 | //function : Lower | |
81 | //purpose : | |
82 | //======================================================================= | |
83 | ||
84 | inline Standard_Integer TCollection_Array1::Lower () const | |
85 | { | |
86 | return myLowerBound ; | |
87 | } | |
88 | ||
89 | ||
90 | //======================================================================= | |
91 | //function : Upper | |
92 | //purpose : | |
93 | //======================================================================= | |
94 | ||
95 | inline Standard_Integer TCollection_Array1::Upper () const | |
96 | { | |
97 | return myUpperBound ; | |
98 | } | |
99 | ||
100 | ||
101 | //======================================================================= | |
102 | //function : IsAllocated | |
103 | //purpose : | |
104 | //======================================================================= | |
105 | ||
106 | inline Standard_Boolean TCollection_Array1::IsAllocated () const | |
107 | { | |
108 | return isAllocated; | |
109 | } | |
110 | ||
111 | //======================================================================= | |
112 | //function : Value | |
113 | //purpose : | |
114 | //======================================================================= | |
115 | ||
116 | inline const Array1Item& TCollection_Array1::Value | |
117 | (const Standard_Integer Index) const | |
118 | { | |
119 | Standard_OutOfRange_Raise_if((Index < myLowerBound || Index > myUpperBound),NULL); | |
120 | return ((Array1Item *)myStart)[Index]; | |
121 | } | |
122 | ||
123 | //======================================================================= | |
124 | //function : SetValue | |
125 | //purpose : | |
126 | //======================================================================= | |
127 | ||
128 | inline void TCollection_Array1::SetValue (const Standard_Integer Index, | |
129 | const Array1Item& Value) | |
130 | { | |
131 | Standard_OutOfRange_Raise_if((Index < myLowerBound || Index > myUpperBound),NULL); | |
132 | ||
133 | ((Array1Item *)myStart)[Index] = Value ; | |
134 | } | |
135 | ||
136 | ||
137 | //======================================================================= | |
138 | //function : ChangeValue | |
139 | //purpose : | |
140 | //======================================================================= | |
141 | ||
142 | inline Array1Item& TCollection_Array1::ChangeValue(const Standard_Integer Index) | |
143 | { | |
144 | Standard_OutOfRange_Raise_if((Index < myLowerBound || Index > myUpperBound),NULL); | |
145 | ||
146 | return ((Array1Item *)myStart)[Index]; | |
147 | } | |
148 | ||
149 | ||
150 |