Integration of OCCT 6.5.0 from SVN
[occt.git] / src / math / math_DoubleTab.gxx
CommitLineData
7fd59977 1// File math_DoubleTab.gxx
2// Lpa, le 7/02/92
3
4
5#include <math_Memory.hxx>
6#include <Standard_OutOfRange.hxx>
7#include <Standard_Failure.hxx>
8#include <Standard_Integer.hxx>
9
10void math_DoubleTab::Allocate()
11{
12 Standard_Integer RowNumber = UppR - LowR + 1;
13 Standard_Integer ColNumber = UppC - LowC + 1;
14
15 Item** TheAddr = (Item**) Standard::Allocate(RowNumber * sizeof(Item*));
16 Item* Address;
17 if(isAllocated)
18 Address = (Item*) Standard::Allocate(RowNumber * ColNumber * sizeof(Item));
19 else
20 Address = (Item*) Addr;
21 Address -= LowC;
22
23 for (Standard_Integer Index = 0; Index < RowNumber; Index++) {
24 TheAddr[Index] = Address;
25 Address += ColNumber;
26 }
27
28 TheAddr -= LowR;
29 Addr = (Standard_Address) TheAddr;
30}
31
32math_DoubleTab::math_DoubleTab(const Standard_Integer LowerRow,
33 const Standard_Integer UpperRow,
34 const Standard_Integer LowerCol,
35 const Standard_Integer UpperCol) :
36 isAllocated(Standard_True),
37 LowR(LowerRow),
38 UppR(UpperRow),
39 LowC(LowerCol),
40 UppC(UpperCol)
41{
42 Allocate();
43}
44
45
46math_DoubleTab::math_DoubleTab(const Item& Tab,
47 const Standard_Integer LowerRow,
48 const Standard_Integer UpperRow,
49 const Standard_Integer LowerCol,
50 const Standard_Integer UpperCol) :
51 Addr((void *) &Tab),
52 isAllocated(Standard_False),
53 LowR(LowerRow),
54 UppR(UpperRow),
55 LowC(LowerCol),
56 UppC(UpperCol)
57{
58 Allocate();
59}
60
61void math_DoubleTab::Init(const Item& InitValue)
62{
63 for (Standard_Integer i = LowR; i <= UppR; i++) {
64 for (Standard_Integer j = LowC; j <= UppC; j++) {
65 ((Item**) Addr)[i][j] = InitValue;
66 }
67 }
68}
69
70
71
72math_DoubleTab::math_DoubleTab(const math_DoubleTab& Other) :
73 isAllocated(Standard_True),
74 LowR(Other.LowR),
75 UppR(Other.UppR),
76 LowC(Other.LowC),
77 UppC(Other.UppC)
78{
79 Allocate();
80
81 Standard_Address target = (Standard_Address) &Value(LowR,LowC);
82 Standard_Address source = (Standard_Address) &Other.Value(LowR,LowC);
83
84 memmove(target,source,
85 (int)((UppR - LowR + 1) * (UppC - LowC + 1) * sizeof(Item)));
86
87}
88
89
90void math_DoubleTab::Free()
91{
92 Standard_Integer RowNumber = UppR - LowR + 1;
93 Standard_Integer ColNumber = UppC - LowC + 1;
94
95 // free the data
96 if(isAllocated) {
97 Standard_Address it = (Standard_Address)&Value(LowR,LowC);
98 Standard::Free(it);
99 }
100 // free the pointers
101 Standard_Address it = (Standard_Address)(((Item**)Addr) + LowR);
102 Standard::Free (it);
103 Addr = 0;
104}
105
106
107
108void math_DoubleTab::SetLowerRow(const Standard_Integer LowerRow)
109{
110 Item** TheAddr = (Item**)Addr;
111 Addr = (Standard_Address) (TheAddr + LowR - LowerRow);
112 UppR = UppR - LowR + LowerRow;
113 LowR = LowerRow;
114}
115
116
117void math_DoubleTab::SetLowerCol(const Standard_Integer LowerCol)
118{
119 Item** TheAddr = (Item**) Addr;
120 for (Standard_Integer Index = LowR; Index <= UppR; Index++) {
121 TheAddr[Index] = TheAddr[Index] + LowC - LowerCol;
122 }
123
124 UppC = UppC - LowC + LowerCol;
125 LowC = LowerCol;
126}
127