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