1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 // Lpa, le 7/02/92
16
17 #include <math_DoubleTab.hxx>
18 #include <Standard_Failure.hxx>
19 #include <Standard_Integer.hxx>
20 #include <Standard_OutOfRange.hxx>
21
22 // macro to get size of C array
23 #define CARRAY_LENGTH(arr) (int)(sizeof(arr)/sizeof(arr[0]))
24
Allocate()25 void math_DoubleTab::Allocate()
26 {
27 Standard_Integer RowNumber = UppR - LowR + 1;
28 Standard_Integer ColNumber = UppC - LowC + 1;
29
30 if(isAllocated)
31 Addr = (Standard_Real*) Standard::Allocate(RowNumber * ColNumber * sizeof(Standard_Real));
32 }
33
math_DoubleTab(const Standard_Integer LowerRow,const Standard_Integer UpperRow,const Standard_Integer LowerCol,const Standard_Integer UpperCol)34 math_DoubleTab::math_DoubleTab(const Standard_Integer LowerRow,
35 const Standard_Integer UpperRow,
36 const Standard_Integer LowerCol,
37 const Standard_Integer UpperCol) :
38 Addr(Buf),
39 isAllocated((UpperRow - LowerRow + 1) * (UpperCol - LowerCol + 1) > CARRAY_LENGTH(Buf)),
40 LowR(LowerRow),
41 UppR(UpperRow),
42 LowC(LowerCol),
43 UppC(UpperCol)
44 {
45 Allocate();
46 }
47
math_DoubleTab(const Standard_Address Tab,const Standard_Integer LowerRow,const Standard_Integer UpperRow,const Standard_Integer LowerCol,const Standard_Integer UpperCol)48 math_DoubleTab::math_DoubleTab(const Standard_Address Tab,
49 const Standard_Integer LowerRow,
50 const Standard_Integer UpperRow,
51 const Standard_Integer LowerCol,
52 const Standard_Integer UpperCol) :
53 Addr(Tab),
54 isAllocated(Standard_False),
55 LowR(LowerRow),
56 UppR(UpperRow),
57 LowC(LowerCol),
58 UppC(UpperCol)
59 {
60 Allocate();
61 }
62
Init(const Standard_Real InitValue)63 void math_DoubleTab::Init(const Standard_Real InitValue)
64 {
65 for (Standard_Integer anIndex = 0; anIndex < (UppR - LowR + 1) * (UppC - LowC + 1); anIndex++)
66 {
67 ((Standard_Real* )Addr)[anIndex] = InitValue;
68 }
69 }
70
math_DoubleTab(const math_DoubleTab & Other)71 math_DoubleTab::math_DoubleTab(const math_DoubleTab& Other) :
72 Addr(Buf),
73 isAllocated((Other.UppR - Other.LowR + 1) *
74 (Other.UppC - Other.LowC + 1) > CARRAY_LENGTH(Buf)),
75 LowR(Other.LowR),
76 UppR(Other.UppR),
77 LowC(Other.LowC),
78 UppC(Other.UppC)
79 {
80 Allocate();
81 memmove (Addr, Other.Addr, (int)((UppR - LowR + 1) * (UppC - LowC + 1) * sizeof(Standard_Real)));
82 }
83
Free()84 void math_DoubleTab::Free()
85 {
86 // free the data
87 if(isAllocated)
88 {
89 Standard::Free (Addr);
90 }
91
92 Addr = 0;
93 }
94
SetLowerRow(const Standard_Integer LowerRow)95 void math_DoubleTab::SetLowerRow(const Standard_Integer LowerRow)
96 {
97 UppR = UppR - LowR + LowerRow;
98 LowR = LowerRow;
99 }
100
SetLowerCol(const Standard_Integer LowerCol)101 void math_DoubleTab::SetLowerCol(const Standard_Integer LowerCol)
102 {
103 UppC = UppC - LowC + LowerCol;
104 LowC = LowerCol;
105 }
106
107