0022627: Change OCCT memory management defaults
[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{
7fd59977 92 // free the data
93 if(isAllocated) {
94 Standard_Address it = (Standard_Address)&Value(LowR,LowC);
95 Standard::Free(it);
96 }
97 // free the pointers
98 Standard_Address it = (Standard_Address)(((Item**)Addr) + LowR);
99 Standard::Free (it);
100 Addr = 0;
101}
102
103
104
105void math_DoubleTab::SetLowerRow(const Standard_Integer LowerRow)
106{
107 Item** TheAddr = (Item**)Addr;
108 Addr = (Standard_Address) (TheAddr + LowR - LowerRow);
109 UppR = UppR - LowR + LowerRow;
110 LowR = LowerRow;
111}
112
113
114void math_DoubleTab::SetLowerCol(const Standard_Integer LowerCol)
115{
116 Item** TheAddr = (Item**) Addr;
117 for (Standard_Integer Index = LowR; Index <= UppR; Index++) {
118 TheAddr[Index] = TheAddr[Index] + LowC - LowerCol;
119 }
120
121 UppC = UppC - LowC + LowerCol;
122 LowC = LowerCol;
123}
124