1 #include <Standard_DimensionMismatch.hxx>
2 #include <Standard_RangeError.hxx>
3 #include <Standard_OutOfMemory.hxx>
4 #include <Standard.hxx>
6 //=======================================================================
8 //purpose : Allocate memory for the array, set up indirection table
9 //=======================================================================
11 void TCollection_Array2::Allocate ()
13 Standard_Integer RowSize = myUpperColumn-myLowerColumn+1;
14 Standard_Integer ColumnSize = myUpperRow-myLowerRow+1;
17 // allocation of the data in the array
19 Standard_Integer Size = RowSize * ColumnSize;
21 // Modified by Sergey KHROMOV - Mon Feb 10 11:46:14 2003 Begin
22 // Standard_RangeError_Raise_if(( RowSize < 0 || ColumnSize < 0 ),
23 // "TCollection_Array2::Create");
24 Standard_RangeError_Raise_if(( RowSize <= 0 || ColumnSize <= 0 ),
25 "TCollection_Array2::Create");
26 // Modified by Sergey KHROMOV - Mon Feb 10 11:46:15 2003 End
28 myData = Standard::Allocate(Size*sizeof (Array2Item));
29 // myData = (Array2Item *) new char [Size * sizeof (Array2Item)];
31 myData = new Array2Item [Size];
34 if (!myData) Standard_OutOfMemory::Raise("Array2 : Allocation failed");
37 // allocation of the indirection table (pointers on rows)
38 Array2Item* p = (Array2Item*) myData;
39 Array2Item** q = (Array2Item**)Standard::Allocate(ColumnSize * sizeof(Array2Item*));
41 for (Standard_Integer i = 0; i < ColumnSize; i++) {
42 q[i] = p - myLowerColumn;
46 myData = (void*) (q - myLowerRow);
49 //=======================================================================
50 //function : TCollection_Array2
52 //=======================================================================
54 TCollection_Array2::TCollection_Array2 (const Standard_Integer R1,
55 const Standard_Integer R2,
56 const Standard_Integer C1,
57 const Standard_Integer C2) :
62 myDeletable(Standard_True)
67 //=======================================================================
68 //function : TCollection_Array2
69 //purpose : User allocated data
70 //=======================================================================
72 TCollection_Array2::TCollection_Array2 (const Array2Item& Item,
73 const Standard_Integer R1,
74 const Standard_Integer R2,
75 const Standard_Integer C1,
76 const Standard_Integer C2) :
81 myDeletable(Standard_False),
88 //=======================================================================
91 //=======================================================================
93 void TCollection_Array2::Init (const Array2Item& V)
95 Standard_Integer Size = RowLength() * ColLength();
96 Array2Item* p = &(ChangeValue(myLowerRow,myLowerColumn));
97 for (Standard_Integer I = 0; I < Size ; I++) p[I] = V;
100 //=======================================================================
103 //=======================================================================
105 void TCollection_Array2::Destroy ()
107 Array2Item** anItemPtr = ((Array2Item**)myData + myLowerRow);
114 Standard_Integer RowSize = myUpperColumn-myLowerColumn+1;
115 Standard_Integer ColumnSize = myUpperRow-myLowerRow+1;
116 Standard_Integer Size = RowSize * ColumnSize;
117 Standard_Address it = (Standard_Address)&((Array2Item **)myData)[myLowerRow][myLowerColumn];
121 delete [] &ChangeValue(myLowerRow,myLowerColumn);
124 // delete the indirection table
125 Standard::Free((void*&)anItemPtr);
128 //=======================================================================
131 //=======================================================================
133 const TCollection_Array2& TCollection_Array2::Assign
134 (const TCollection_Array2& Right)
136 Standard_Integer MaxColumn = RowLength() ;
137 Standard_Integer MaxRow = ColLength() ;
138 Standard_Integer MaxSize = MaxColumn * MaxRow;
140 Standard_DimensionMismatch_Raise_if(MaxRow != Right.ColLength() ||
141 MaxColumn != Right.RowLength(),
142 "Array2::Operator=");
144 Array2Item* p = &ChangeValue(myLowerRow,myLowerColumn);
145 const Array2Item* q = &Right.Value(Right.LowerRow(),Right.LowerCol());
146 for (Standard_Integer i=0; i<MaxSize; i++) {