Warning, file /include/opencascade/math_DoubleTab.hxx was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef _math_DoubleTab_HeaderFile
0018 #define _math_DoubleTab_HeaderFile
0019
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 #include <NCollection_Array2.hxx>
0024
0025 #include <Standard_Real.hxx>
0026 #include <Standard_Boolean.hxx>
0027
0028 #include <array>
0029 #include <utility>
0030
0031 class math_DoubleTab
0032 {
0033 static const int THE_BUFFER_SIZE = 64;
0034
0035 public:
0036 DEFINE_STANDARD_ALLOC;
0037 DEFINE_NCOLLECTION_ALLOC;
0038
0039 public:
0040
0041 math_DoubleTab(const int theLowerRow,
0042 const int theUpperRow,
0043 const int theLowerCol,
0044 const int theUpperCol)
0045 : myBuffer{},
0046 myArray((theUpperRow - theLowerRow + 1) * (theUpperCol - theLowerCol + 1) <= THE_BUFFER_SIZE
0047 ? NCollection_Array2<double>(*myBuffer.data(),
0048 theLowerRow,
0049 theUpperRow,
0050 theLowerCol,
0051 theUpperCol)
0052 : NCollection_Array2<double>(theLowerRow, theUpperRow, theLowerCol, theUpperCol))
0053 {
0054 }
0055
0056 public:
0057
0058 math_DoubleTab(void* const theTab,
0059 const int theLowerRow,
0060 const int theUpperRow,
0061 const int theLowerCol,
0062 const int theUpperCol)
0063 : myArray(*static_cast<const double*>(theTab),
0064 theLowerRow,
0065 theUpperRow,
0066 theLowerCol,
0067 theUpperCol)
0068 {
0069 }
0070
0071
0072 void Init(const double theInitValue) { myArray.Init(theInitValue); }
0073
0074
0075 math_DoubleTab(const math_DoubleTab& theOther)
0076 : myArray(theOther.myArray)
0077 {
0078 }
0079
0080
0081 math_DoubleTab(math_DoubleTab&& theOther) noexcept
0082 : myBuffer{},
0083 myArray(theOther.myArray.IsDeletable()
0084 ? std::move(theOther.myArray)
0085 : (theOther.NbRows() * theOther.NbColumns() <= THE_BUFFER_SIZE
0086 ? NCollection_Array2<double>(*myBuffer.data(),
0087 theOther.LowerRow(),
0088 theOther.UpperRow(),
0089 theOther.LowerCol(),
0090 theOther.UpperCol())
0091 : NCollection_Array2<double>(theOther.LowerRow(),
0092 theOther.UpperRow(),
0093 theOther.LowerCol(),
0094 theOther.UpperCol())))
0095 {
0096 if (!theOther.myArray.IsEmpty())
0097 {
0098 myArray.Assign(theOther.myArray);
0099 }
0100 }
0101
0102
0103 void Copy(math_DoubleTab& theOther) const { theOther.myArray.CopyValues(myArray); }
0104
0105
0106 bool IsDeletable() const { return myArray.IsDeletable(); }
0107
0108
0109 void SetLowerRow(const int theLowerRow) { myArray.UpdateLowerRow(theLowerRow); }
0110
0111
0112 void SetLowerCol(const int theLowerCol) { myArray.UpdateLowerCol(theLowerCol); }
0113
0114
0115 int LowerRow() const noexcept { return myArray.LowerRow(); }
0116
0117
0118 int UpperRow() const noexcept { return myArray.UpperRow(); }
0119
0120
0121 int LowerCol() const noexcept { return myArray.LowerCol(); }
0122
0123
0124 int UpperCol() const noexcept { return myArray.UpperCol(); }
0125
0126
0127 int NbRows() const noexcept { return myArray.NbRows(); }
0128
0129
0130 int NbColumns() const noexcept { return myArray.NbColumns(); }
0131
0132
0133 const double& Value(const int theRowIndex, const int theColIndex) const
0134 {
0135 return myArray.Value(theRowIndex, theColIndex);
0136 }
0137
0138
0139 double& Value(const int theRowIndex, const int theColIndex)
0140 {
0141 return myArray.ChangeValue(theRowIndex, theColIndex);
0142 }
0143
0144
0145 const double& operator()(const int theRowIndex, const int theColIndex) const
0146 {
0147 return Value(theRowIndex, theColIndex);
0148 }
0149
0150
0151 double& operator()(const int theRowIndex, const int theColIndex)
0152 {
0153 return Value(theRowIndex, theColIndex);
0154 }
0155
0156
0157 math_DoubleTab& operator=(const math_DoubleTab& theOther)
0158 {
0159 if (this != &theOther)
0160 {
0161 myArray = theOther.myArray;
0162 }
0163 return *this;
0164 }
0165
0166
0167 math_DoubleTab& operator=(math_DoubleTab&& theOther) noexcept
0168 {
0169 if (this == &theOther)
0170 {
0171 return *this;
0172 }
0173
0174 if (myArray.IsDeletable() && theOther.myArray.IsDeletable()
0175 && myArray.NbRows() == theOther.myArray.NbRows()
0176 && myArray.NbColumns() == theOther.myArray.NbColumns()
0177 && myArray.LowerRow() == theOther.myArray.LowerRow()
0178 && myArray.LowerCol() == theOther.myArray.LowerCol())
0179 {
0180 myArray.Move(theOther.myArray);
0181 }
0182 else
0183 {
0184 myArray = theOther.myArray;
0185 }
0186 return *this;
0187 }
0188
0189
0190 ~math_DoubleTab() = default;
0191
0192 private:
0193 std::array<double, THE_BUFFER_SIZE> myBuffer;
0194 NCollection_Array2<double> myArray;
0195 };
0196
0197 #endif