1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
19 #include <Standard.hxx>
20 #include <Standard_OutOfMemory.hxx>
21 #include <Standard_OutOfRange.hxx>
22 #include <Standard_RangeError.hxx>
24 #include Array1Item_hxx
27 //=======================================================================
28 //function : TCollection_Array1
30 //=======================================================================
32 inline TCollection_Array1::TCollection_Array1 (const Standard_Integer Low,
33 const Standard_Integer Up) :
36 isAllocated(Standard_True)
38 Standard_RangeError_Raise_if(Up < Low,"TCollection_Array1::Create");
40 Array1Item* p = new Array1Item[Up-Low+1];
42 if (!p) Standard_OutOfMemory::Raise("Array1 : Allocation failed");
43 myStart = (void*)(p - myLowerBound);
46 //=======================================================================
47 //function : TCollection_Array1
48 //purpose : C Array constructor
49 //=======================================================================
51 inline TCollection_Array1::TCollection_Array1(const Array1Item& AnItem,
52 const Standard_Integer Low,
53 const Standard_Integer Up) :
56 isAllocated(Standard_False)
58 Standard_RangeError_Raise_if(Up < Low,"Array1::CArray");
59 myStart = (void*)( &AnItem - Low );
62 //=======================================================================
65 //=======================================================================
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++) {
75 //=======================================================================
78 //=======================================================================
80 inline void TCollection_Array1::Destroy()
83 delete [] &ChangeValue(myLowerBound);
87 //=======================================================================
90 //=======================================================================
92 inline Standard_Integer TCollection_Array1::Length () const
94 return myUpperBound - myLowerBound + 1 ;
98 //=======================================================================
101 //=======================================================================
103 inline Standard_Integer TCollection_Array1::Lower () const
105 return myLowerBound ;
109 //=======================================================================
112 //=======================================================================
114 inline Standard_Integer TCollection_Array1::Upper () const
116 return myUpperBound ;
120 //=======================================================================
121 //function : IsAllocated
123 //=======================================================================
125 inline Standard_Boolean TCollection_Array1::IsAllocated () const
130 //=======================================================================
133 //=======================================================================
135 inline const Array1Item& TCollection_Array1::Value
136 (const Standard_Integer Index) const
138 Standard_OutOfRange_Raise_if((Index < myLowerBound || Index > myUpperBound),NULL);
139 return ((Array1Item *)myStart)[Index];
142 //=======================================================================
143 //function : SetValue
145 //=======================================================================
147 inline void TCollection_Array1::SetValue (const Standard_Integer Index,
148 const Array1Item& Value)
150 Standard_OutOfRange_Raise_if((Index < myLowerBound || Index > myUpperBound),NULL);
152 ((Array1Item *)myStart)[Index] = Value ;
156 //=======================================================================
157 //function : ChangeValue
159 //=======================================================================
161 inline Array1Item& TCollection_Array1::ChangeValue(const Standard_Integer Index)
163 Standard_OutOfRange_Raise_if((Index < myLowerBound || Index > myUpperBound),NULL);
165 return ((Array1Item *)myStart)[Index];