cacb5371035693ea58a00c672578af650ffef7de
[occt.git] / src / PCollection / PCollection_HArray2.gxx
1 // Copyright (c) 1998-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 // --------------------------------------------------------------------
16 // HArray2 Implementation :
17 // Last Revision : Feb,10 1992 J.P Tirault
18 //                 Implementation of ShallowCopy, ShallowDump
19 //                 methods.
20 // --------------------------------------------------------------------
21
22
23 // --------------------------------------------------------------------
24 //                            Exceptions raised
25 // --------------------------------------------------------------------
26 #include <Standard_OutOfRange.hxx>
27 #include <Standard_RangeError.hxx>
28 #include <Standard_NotImplemented.hxx>
29
30 // --------------------------------------------------------------------
31 //                            Constructor 
32 // --------------------------------------------------------------------
33 PCollection_HArray2::PCollection_HArray2 
34       (const Standard_Integer R1, 
35        const Standard_Integer R2, 
36        const Standard_Integer C1, 
37        const Standard_Integer C2) : Data( (C2-C1+1)*(R2-R1+1) )
38 {
39   Standard_RangeError_Raise_if((C2-C1+1 <= 0  || R2-R1+1 <= 0 ),
40                   "Attempt to create a Double Array with negative size");
41
42   myLowerRow = R1;
43   myLowerCol = C1;
44   myUpperRow = R2;
45   myUpperCol = C2;
46
47 }
48
49 // ----------------------------------------------------------------------
50 //                 datas
51 // ----------------------------------------------------------------------
52
53 Standard_Address PCollection_HArray2::Datas() const
54 {
55   return ((Standard_Address)Data.Lock());
56 }
57
58
59 // --------------------------------------------------------------------
60 //                            Constructor 
61 // --------------------------------------------------------------------
62 PCollection_HArray2::PCollection_HArray2 
63                          (const Standard_Integer R1, 
64                           const Standard_Integer R2,
65                           const Standard_Integer C1, 
66                           const Standard_Integer C2, 
67                           const Item& V) : Data ( (C2-C1+1)*(R2-R1+1) )
68 {
69   Standard_RangeError_Raise_if((C2-C1+1 <= 0  || R2-R1+1 <= 0 ),
70                   "Attempt to create a Double Array with negative size");
71
72   myLowerRow = R1;
73   myLowerCol = C1;
74   myUpperRow = R2;
75   myUpperCol = C2;
76   Standard_Integer Size = Data.Length();
77
78   for (Standard_Integer I = 0; I < Size ; I++) Data.SetValue(I,V); 
79 }
80
81
82 // --------------------------------------------------------------------
83 //                            Destructor : Not Implemented
84 // --------------------------------------------------------------------
85
86 /*
87 void PCollection_HArray2::~PCollection_HArray2 () 
88 {
89         delete Data ;
90 }
91 */
92
93 // --------------------------------------------------------------------
94 //                            ShallowCopy
95 // --------------------------------------------------------------------
96 Handle(Standard_Persistent) PCollection_HArray2::ShallowCopy() const
97 {
98   PCollection_HArray2* TheCopy = new PCollection_HArray2(*this);
99 //  PCollection_FieldOfHArray2 DataCopy (Data);
100 //  TheCopy->Data = DataCopy;
101   return TheCopy;
102 }
103
104 // --------------------------------------------------------------------
105 //                            ShallowDump
106 // --------------------------------------------------------------------
107 void PCollection_HArray2::ShallowDump(Standard_OStream& S) const
108 {
109   ::ShallowDump(Data,S);
110 }
111
112
113
114
115
116 /* Anciens INLINE */
117
118 // --------------------------------------------------------------------
119 //                            SetValue
120 // --------------------------------------------------------------------
121 void PCollection_HArray2::SetValue ( const Standard_Integer Row,
122                                          const Standard_Integer Col,
123                                          const Item& Value)
124 {
125   Standard_OutOfRange_Raise_if((Row <myLowerRow || Row > myUpperRow ||
126                                 Col <myLowerCol || Col > myUpperCol),
127                                "Index out of range in HArray2::SetValue");
128
129   Data.SetValue((Row-myLowerRow)*(myUpperCol-myLowerCol+1)+
130                 (Col-myLowerCol), Value) ;
131 }
132
133
134 // --------------------------------------------------------------------
135 //                            Value
136 // --------------------------------------------------------------------
137 Item PCollection_HArray2::Value (const Standard_Integer Row,
138                                      const Standard_Integer Col) const
139 {
140   Standard_OutOfRange_Raise_if((Row <myLowerRow || Row > myUpperRow ||
141                                 Col <myLowerCol || Col > myUpperCol),
142                                "Index out of range in HArray2::SetValue");
143
144   return Data((Row-myLowerRow) * (myUpperCol-myLowerCol+1) +
145               (Col-myLowerCol)) ;
146 }
147
148
149 // ------------------------------------------------------------------
150 //
151 // ------------------------------------------------------------------
152 PCollection_FieldOfHArray2 PCollection_HArray2::Field () const
153 {
154   return Data ;
155 }
156