0030686: Visualization, SelectMgr_ViewerSelector - sorting issues of transformation...
[occt.git] / src / math / math_IntegerVector.hxx
CommitLineData
3b010a74 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//
d5f74e42 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
3b010a74 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#ifndef _math_IntegerVector_HeaderFile
16#define _math_IntegerVector_HeaderFile
17
18434846 18#include <NCollection_Array1.hxx>
19#include <NCollection_LocalArray.hxx>
3b010a74 20
9fd2d2c3 21// resolve name collisions with X11 headers
22#ifdef Opposite
23 #undef Opposite
24#endif
3b010a74 25
26//! This class implements the real IntegerVector abstract data type.
27//! IntegerVectors can have an arbitrary range which must be define at
28//! the declaration and cannot be changed after this declaration.
29//! Example:
30//! @code
31//! math_IntegerVector V1(-3, 5); // an IntegerVector with range [-3..5]
32//! @endcode
33//!
34//! IntegerVector is copied through assignement :
35//! @code
36//! math_IntegerVector V2( 1, 9);
37//! ....
38//! V2 = V1;
39//! V1(1) = 2.0; // the IntegerVector V2 will not be modified.
40//! @endcode
41//!
42//! The Exception RangeError is raised when trying to access outside
43//! the range of an IntegerVector :
44//! @code
45//! V1(11) = 0 // --> will raise RangeError;
46//! @endcode
47//!
48//! The Exception DimensionError is raised when the dimensions of two
49//! IntegerVectors are not compatible :
50//! @code
51//! math_IntegerVector V3(1, 2);
52//! V3 = V1; // --> will raise DimensionError;
53//! V1.Add(V3) // --> will raise DimensionError;
54//! @endcode
55class math_IntegerVector
56{
57public:
58
59 DEFINE_STANDARD_ALLOC
60
61 //! contructs an IntegerVector in the range [Lower..Upper]
62 Standard_EXPORT math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast);
63
64 //! contructs an IntegerVector in the range [Lower..Upper]
65 //! with all the elements set to theInitialValue.
66 Standard_EXPORT math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast, const Standard_Integer theInitialValue);
67
68 //! Initialize an IntegerVector with all the elements
69 //! set to theInitialValue.
70 Standard_EXPORT void Init(const Standard_Integer theInitialValue);
71
72 //! constructs an IntegerVector in the range [Lower..Upper]
73 //! which share the "c array" theTab.
18434846 74 Standard_EXPORT math_IntegerVector(const Standard_Integer* theTab, const Standard_Integer theFirst, const Standard_Integer theLast);
3b010a74 75
76 //! constructs a copy for initialization.
77 //! An exception is raised if the lengths of the IntegerVectors
78 //! are different.
79 Standard_EXPORT math_IntegerVector(const math_IntegerVector& theOther);
80
81 //! returns the length of an IntegerVector
82 inline Standard_Integer Length() const
83 {
18434846 84 return Array.Length();
3b010a74 85 }
86
87 //! returns the value of the Lower index of an IntegerVector.
88 inline Standard_Integer Lower() const
89 {
18434846 90 return Array.Lower();
3b010a74 91 }
92
93 //! returns the value of the Upper index of an IntegerVector.
94 inline Standard_Integer Upper() const
95 {
18434846 96 return Array.Upper();
3b010a74 97 }
98
99 //! returns the value of the norm of an IntegerVector.
100 Standard_EXPORT Standard_Real Norm() const;
101
102 //! returns the value of the square of the norm of an IntegerVector.
103 Standard_EXPORT Standard_Real Norm2() const;
104
105 //! returns the value of the Index of the maximum element of an IntegerVector.
106 Standard_EXPORT Standard_Integer Max() const;
107
108 //! returns the value of the Index of the minimum element of an IntegerVector.
109 Standard_EXPORT Standard_Integer Min() const;
110
111 //! inverses an IntegerVector.
112 Standard_EXPORT void Invert();
113
114 //! returns the inverse IntegerVector of an IntegerVector.
115 Standard_EXPORT math_IntegerVector Inverse() const;
116
117 //! sets an IntegerVector from "theI1" to "theI2" to the IntegerVector "theV";
118 //! An exception is raised if "theI1" is less than "LowerIndex" or "theI2" is greater than "UpperIndex" or "theI1" is greater than "theI2".
119 //! An exception is raised if "theI2-theI1+1" is different from the Length of "theV".
120 Standard_EXPORT void Set(const Standard_Integer theI1, const Standard_Integer theI2, const math_IntegerVector& theV);
121
122 //! slices the values of the IntegerVector between "theI1" and "theI2":
123 //! Example: [2, 1, 2, 3, 4, 5] becomes [2, 4, 3, 2, 1, 5] between 2 and 5.
124 //! An exception is raised if "theI1" is less than "LowerIndex" or "theI2" is greater than "UpperIndex".
125 Standard_EXPORT math_IntegerVector Slice(const Standard_Integer theI1, const Standard_Integer theI2) const;
126
127 //! returns the product of an IntegerVector by an integer value.
128 Standard_EXPORT void Multiply(const Standard_Integer theRight);
129
130 void operator *=(const Standard_Integer theRight)
131 {
132 Multiply(theRight);
133 }
134
135 //! returns the product of an IntegerVector by an integer value.
0be7dbe1 136 Standard_EXPORT Standard_NODISCARD math_IntegerVector Multiplied(const Standard_Integer theRight) const;
3b010a74 137
0be7dbe1 138 Standard_NODISCARD math_IntegerVector operator*(const Standard_Integer theRight) const
3b010a74 139 {
140 return Multiplied(theRight);
141 }
142
143 //! returns the product of a vector and a real value.
0be7dbe1 144 Standard_EXPORT Standard_NODISCARD math_IntegerVector TMultiplied(const Standard_Integer theRight) const;
3b010a74 145
146 friend inline math_IntegerVector operator* (const Standard_Integer theLeft, const math_IntegerVector& theRight)
147 {
148 return theRight.Multiplied(theLeft);
149 }
150
151 //! adds the IntegerVector "theRight" to an IntegerVector.
152 //! An exception is raised if the IntegerVectors have not the same length.
153 //! An exception is raised if the lengths are not equal.
154 Standard_EXPORT void Add(const math_IntegerVector& theRight);
155
156 void operator +=(const math_IntegerVector& theRight)
157 {
158 Add(theRight);
159 }
160
161 //! adds the IntegerVector "theRight" to an IntegerVector.
162 //! An exception is raised if the IntegerVectors have not the same length.
163 //! An exception is raised if the lengths are not equal.
0be7dbe1 164 Standard_EXPORT Standard_NODISCARD math_IntegerVector Added(const math_IntegerVector& theRight) const;
3b010a74 165
0be7dbe1 166 Standard_NODISCARD math_IntegerVector operator+(const math_IntegerVector& theRight) const
3b010a74 167 {
168 return Added(theRight);
169 }
170
171 //! sets an IntegerVector to the sum of the IntegerVector
172 //! "theLeft" and the IntegerVector "theRight".
173 //! An exception is raised if the lengths are different.
174 Standard_EXPORT void Add(const math_IntegerVector& theLeft, const math_IntegerVector& theRight);
175
176 //! sets an IntegerVector to the substraction of "theRight" from "theLeft".
177 //! An exception is raised if the IntegerVectors have not the same length.
178 Standard_EXPORT void Subtract(const math_IntegerVector& theLeft, const math_IntegerVector& theRight);
179
18434846 180 //! accesses the value of index theNum of an IntegerVector.
181 const Standard_Integer& Value (const Standard_Integer theNum) const
182 {
183 return Array(theNum);
184 }
185
3b010a74 186 //! accesses (in read or write mode) the value of index theNum of an IntegerVector.
18434846 187 inline Standard_Integer& Value (const Standard_Integer theNum)
3b010a74 188 {
3b010a74 189 return Array(theNum);
190 }
191
18434846 192 const Standard_Integer& operator()(const Standard_Integer theNum) const
193 {
194 return Value(theNum);
195 }
196
197 Standard_Integer& operator()(const Standard_Integer theNum)
3b010a74 198 {
199 return Value(theNum);
200 }
201
202 //! Initialises an IntegerVector by copying "theOther".
203 //! An exception is raised if the Lengths are different.
204 Standard_EXPORT math_IntegerVector& Initialized(const math_IntegerVector& theOther);
205
206 math_IntegerVector& operator=(const math_IntegerVector& theOther)
207 {
208 return Initialized(theOther);
209 }
210
211 //! returns the inner product of 2 IntegerVectors.
212 //! An exception is raised if the lengths are not equal.
0be7dbe1 213 Standard_EXPORT Standard_NODISCARD Standard_Integer Multiplied(const math_IntegerVector& theRight) const;
3b010a74 214
0be7dbe1 215 Standard_NODISCARD Standard_Integer operator*(const math_IntegerVector& theRight) const
3b010a74 216 {
217 return Multiplied(theRight);
218 }
219
220 //! returns the opposite of an IntegerVector.
221 Standard_EXPORT math_IntegerVector Opposite();
222
223 math_IntegerVector operator-()
224 {
225 return Opposite();
226 }
227
228 //! returns the subtraction of "theRight" from "me".
229 //! An exception is raised if the IntegerVectors have not the same length.
230 Standard_EXPORT void Subtract(const math_IntegerVector& theRight);
231
232 void operator-=(const math_IntegerVector& theRight)
233 {
234 Subtract(theRight);
235 }
236
237 //! returns the subtraction of "theRight" from "me".
238 //! An exception is raised if the IntegerVectors have not the same length.
0be7dbe1 239 Standard_EXPORT Standard_NODISCARD math_IntegerVector Subtracted(const math_IntegerVector& theRight) const;
3b010a74 240
0be7dbe1 241 Standard_NODISCARD math_IntegerVector operator-(const math_IntegerVector& theRight) const
3b010a74 242 {
243 return Subtracted(theRight);
244 }
245
246 //! returns the multiplication of an integer by an IntegerVector.
247 Standard_EXPORT void Multiply(const Standard_Integer theLeft,const math_IntegerVector& theRight);
248
249 //! Prints on the stream theO information on the current state of the object.
250 //! Is used to redefine the operator <<.
251 Standard_EXPORT void Dump(Standard_OStream& theO) const;
252
253 friend inline Standard_OStream& operator<<(Standard_OStream& theO, const math_IntegerVector& theVec)
254 {
255 theVec.Dump(theO);
256 return theO;
257 }
258
259protected:
260
261 //! is used internally to set the Lower value of the IntegerVector.
262 void SetFirst(const Standard_Integer theFirst);
263
264private:
265
18434846 266 NCollection_LocalArray<Standard_Integer, 512> myLocArray;
267 NCollection_Array1<Standard_Integer> Array;
268
3b010a74 269};
270
271#endif
272