1 // Copyright (c) 1993-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <Standard_DimensionMismatch.hxx>
16 #include <Standard_RangeError.hxx>
17 #include <Standard_OutOfMemory.hxx>
18 #include <Standard.hxx>
20 //=======================================================================
22 //purpose : Allocate memory for the array, set up indirection table
23 //=======================================================================
25 void TCollection_Array2::Allocate ()
27 Standard_Integer RowSize = myUpperColumn-myLowerColumn+1;
28 Standard_Integer ColumnSize = myUpperRow-myLowerRow+1;
31 // allocation of the data in the array
33 Standard_Integer Size = RowSize * ColumnSize;
35 // Modified by Sergey KHROMOV - Mon Feb 10 11:46:14 2003 Begin
36 // Standard_RangeError_Raise_if(( RowSize < 0 || ColumnSize < 0 ),
37 // "TCollection_Array2::Create");
38 Standard_RangeError_Raise_if(( RowSize <= 0 || ColumnSize <= 0 ),
39 "TCollection_Array2::Create");
40 // Modified by Sergey KHROMOV - Mon Feb 10 11:46:15 2003 End
41 myData = new Array2Item [Size];
43 if (!myData) Standard_OutOfMemory::Raise("Array2 : Allocation failed");
46 // allocation of the indirection table (pointers on rows)
47 Array2Item* p = (Array2Item*) myData;
48 Array2Item** q = (Array2Item**)Standard::Allocate(ColumnSize * sizeof(Array2Item*));
50 for (Standard_Integer i = 0; i < ColumnSize; i++) {
51 q[i] = p - myLowerColumn;
55 myData = (void*) (q - myLowerRow);
58 //=======================================================================
59 //function : TCollection_Array2
61 //=======================================================================
63 TCollection_Array2::TCollection_Array2 (const Standard_Integer R1,
64 const Standard_Integer R2,
65 const Standard_Integer C1,
66 const Standard_Integer C2) :
71 myDeletable(Standard_True)
76 //=======================================================================
77 //function : TCollection_Array2
78 //purpose : User allocated data
79 //=======================================================================
81 TCollection_Array2::TCollection_Array2 (const Array2Item& Item,
82 const Standard_Integer R1,
83 const Standard_Integer R2,
84 const Standard_Integer C1,
85 const Standard_Integer C2) :
90 myDeletable(Standard_False),
96 //=======================================================================
99 //=======================================================================
101 void TCollection_Array2::Init (const Array2Item& V)
103 Standard_Integer Size = RowLength() * ColLength();
104 Array2Item* p = &(ChangeValue(myLowerRow,myLowerColumn));
105 for (Standard_Integer I = 0; I < Size ; I++) p[I] = V;
108 //=======================================================================
111 //=======================================================================
113 void TCollection_Array2::Destroy ()
115 Array2Item** anItemPtr = ((Array2Item**)myData + myLowerRow);
120 delete [] &ChangeValue(myLowerRow,myLowerColumn);
122 // delete the indirection table
123 Standard::Free (anItemPtr);
126 //=======================================================================
129 //=======================================================================
131 const TCollection_Array2& TCollection_Array2::Assign
132 (const TCollection_Array2& Right)
134 Standard_Integer MaxColumn = RowLength() ;
135 Standard_Integer MaxRow = ColLength() ;
136 Standard_Integer MaxSize = MaxColumn * MaxRow;
138 Standard_DimensionMismatch_Raise_if(MaxRow != Right.ColLength() ||
139 MaxColumn != Right.RowLength(),
140 "Array2::Operator=");
142 Array2Item* p = &ChangeValue(myLowerRow,myLowerColumn);
143 const Array2Item* q = &Right.Value(Right.LowerRow(),Right.LowerCol());
144 for (Standard_Integer i=0; i<MaxSize; i++) {