1 // Copyright (c) 1993-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_DimensionMismatch.hxx>
20 #include <Standard_RangeError.hxx>
21 #include <Standard_OutOfMemory.hxx>
22 #include <Standard.hxx>
24 //=======================================================================
26 //purpose : Allocate memory for the array, set up indirection table
27 //=======================================================================
29 void TCollection_Array2::Allocate ()
31 Standard_Integer RowSize = myUpperColumn-myLowerColumn+1;
32 Standard_Integer ColumnSize = myUpperRow-myLowerRow+1;
35 // allocation of the data in the array
37 Standard_Integer Size = RowSize * ColumnSize;
39 // Modified by Sergey KHROMOV - Mon Feb 10 11:46:14 2003 Begin
40 // Standard_RangeError_Raise_if(( RowSize < 0 || ColumnSize < 0 ),
41 // "TCollection_Array2::Create");
42 Standard_RangeError_Raise_if(( RowSize <= 0 || ColumnSize <= 0 ),
43 "TCollection_Array2::Create");
44 // Modified by Sergey KHROMOV - Mon Feb 10 11:46:15 2003 End
45 myData = new Array2Item [Size];
47 if (!myData) Standard_OutOfMemory::Raise("Array2 : Allocation failed");
50 // allocation of the indirection table (pointers on rows)
51 Array2Item* p = (Array2Item*) myData;
52 Array2Item** q = (Array2Item**)Standard::Allocate(ColumnSize * sizeof(Array2Item*));
54 for (Standard_Integer i = 0; i < ColumnSize; i++) {
55 q[i] = p - myLowerColumn;
59 myData = (void*) (q - myLowerRow);
63 //=======================================================================
66 //=======================================================================
68 const TCollection_Array2& TCollection_Array2::Assign
69 (const TCollection_Array2& Right)
71 Standard_Integer MaxColumn = RowLength() ;
72 Standard_Integer MaxRow = ColLength() ;
73 Standard_Integer MaxSize = MaxColumn * MaxRow;
75 Standard_DimensionMismatch_Raise_if(MaxRow != Right.ColLength() ||
76 MaxColumn != Right.RowLength(),
79 Array2Item* p = &ChangeValue(myLowerRow,myLowerColumn);
80 const Array2Item* q = &Right.Value(Right.LowerRow(),Right.LowerCol());
81 for (Standard_Integer i=0; i<MaxSize; i++) {