1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _math_IntegerVector_HeaderFile
16 #define _math_IntegerVector_HeaderFile
18 #include <NCollection_Array1.hxx>
19 #include <NCollection_LocalArray.hxx>
21 // resolve name collisions with X11 headers
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.
31 //! math_IntegerVector V1(-3, 5); // an IntegerVector with range [-3..5]
34 //! IntegerVector is copied through assignement :
36 //! math_IntegerVector V2( 1, 9);
39 //! V1(1) = 2.0; // the IntegerVector V2 will not be modified.
42 //! The Exception RangeError is raised when trying to access outside
43 //! the range of an IntegerVector :
45 //! V1(11) = 0 // --> will raise RangeError;
48 //! The Exception DimensionError is raised when the dimensions of two
49 //! IntegerVectors are not compatible :
51 //! math_IntegerVector V3(1, 2);
52 //! V3 = V1; // --> will raise DimensionError;
53 //! V1.Add(V3) // --> will raise DimensionError;
55 class math_IntegerVector
61 //! contructs an IntegerVector in the range [Lower..Upper]
62 Standard_EXPORT math_IntegerVector(const Standard_Integer theFirst, const Standard_Integer theLast);
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);
68 //! Initialize an IntegerVector with all the elements
69 //! set to theInitialValue.
70 Standard_EXPORT void Init(const Standard_Integer theInitialValue);
72 //! constructs an IntegerVector in the range [Lower..Upper]
73 //! which share the "c array" theTab.
74 Standard_EXPORT math_IntegerVector(const Standard_Integer* theTab, const Standard_Integer theFirst, const Standard_Integer theLast);
76 //! constructs a copy for initialization.
77 //! An exception is raised if the lengths of the IntegerVectors
79 Standard_EXPORT math_IntegerVector(const math_IntegerVector& theOther);
81 //! returns the length of an IntegerVector
82 inline Standard_Integer Length() const
84 return Array.Length();
87 //! returns the value of the Lower index of an IntegerVector.
88 inline Standard_Integer Lower() const
93 //! returns the value of the Upper index of an IntegerVector.
94 inline Standard_Integer Upper() const
99 //! returns the value of the norm of an IntegerVector.
100 Standard_EXPORT Standard_Real Norm() const;
102 //! returns the value of the square of the norm of an IntegerVector.
103 Standard_EXPORT Standard_Real Norm2() const;
105 //! returns the value of the Index of the maximum element of an IntegerVector.
106 Standard_EXPORT Standard_Integer Max() const;
108 //! returns the value of the Index of the minimum element of an IntegerVector.
109 Standard_EXPORT Standard_Integer Min() const;
111 //! inverses an IntegerVector.
112 Standard_EXPORT void Invert();
114 //! returns the inverse IntegerVector of an IntegerVector.
115 Standard_EXPORT math_IntegerVector Inverse() const;
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);
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;
127 //! returns the product of an IntegerVector by an integer value.
128 Standard_EXPORT void Multiply(const Standard_Integer theRight);
130 void operator *=(const Standard_Integer theRight)
135 //! returns the product of an IntegerVector by an integer value.
136 Standard_NODISCARD Standard_EXPORT math_IntegerVector Multiplied(const Standard_Integer theRight) const;
138 Standard_NODISCARD math_IntegerVector operator*(const Standard_Integer theRight) const
140 return Multiplied(theRight);
143 //! returns the product of a vector and a real value.
144 Standard_NODISCARD Standard_EXPORT math_IntegerVector TMultiplied(const Standard_Integer theRight) const;
146 friend inline math_IntegerVector operator* (const Standard_Integer theLeft, const math_IntegerVector& theRight)
148 return theRight.Multiplied(theLeft);
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);
156 void operator +=(const math_IntegerVector& theRight)
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.
164 Standard_NODISCARD Standard_EXPORT math_IntegerVector Added(const math_IntegerVector& theRight) const;
166 Standard_NODISCARD math_IntegerVector operator+(const math_IntegerVector& theRight) const
168 return Added(theRight);
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);
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);
180 //! accesses the value of index theNum of an IntegerVector.
181 const Standard_Integer& Value (const Standard_Integer theNum) const
183 return Array(theNum);
186 //! accesses (in read or write mode) the value of index theNum of an IntegerVector.
187 inline Standard_Integer& Value (const Standard_Integer theNum)
189 return Array(theNum);
192 const Standard_Integer& operator()(const Standard_Integer theNum) const
194 return Value(theNum);
197 Standard_Integer& operator()(const Standard_Integer theNum)
199 return Value(theNum);
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);
206 math_IntegerVector& operator=(const math_IntegerVector& theOther)
208 return Initialized(theOther);
211 //! returns the inner product of 2 IntegerVectors.
212 //! An exception is raised if the lengths are not equal.
213 Standard_NODISCARD Standard_EXPORT Standard_Integer Multiplied(const math_IntegerVector& theRight) const;
215 Standard_NODISCARD Standard_Integer operator*(const math_IntegerVector& theRight) const
217 return Multiplied(theRight);
220 //! returns the opposite of an IntegerVector.
221 Standard_EXPORT math_IntegerVector Opposite();
223 math_IntegerVector operator-()
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);
232 void operator-=(const math_IntegerVector& theRight)
237 //! returns the subtraction of "theRight" from "me".
238 //! An exception is raised if the IntegerVectors have not the same length.
239 Standard_NODISCARD Standard_EXPORT math_IntegerVector Subtracted(const math_IntegerVector& theRight) const;
241 Standard_NODISCARD math_IntegerVector operator-(const math_IntegerVector& theRight) const
243 return Subtracted(theRight);
246 //! returns the multiplication of an integer by an IntegerVector.
247 Standard_EXPORT void Multiply(const Standard_Integer theLeft,const math_IntegerVector& theRight);
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;
253 friend inline Standard_OStream& operator<<(Standard_OStream& theO, const math_IntegerVector& theVec)
261 //! is used internally to set the Lower value of the IntegerVector.
262 void SetFirst(const Standard_Integer theFirst);
266 NCollection_LocalArray<Standard_Integer, 512> myLocArray;
267 NCollection_Array1<Standard_Integer> Array;