Back to home page

EIC code displayed by LXR

 
 

    


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 // Created on: 1992-02-07
0002 // Created by: Laurent PAINNOT
0003 // Copyright (c) 1992-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
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   //! Constructor for ranges [theLowerRow..theUpperRow, theLowerCol..theUpperCol]
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   //! Constructor from external data array
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   //! Initialize all elements with theInitValue
0072   void Init(const double theInitValue) { myArray.Init(theInitValue); }
0073 
0074   //! Copy constructor
0075   math_DoubleTab(const math_DoubleTab& theOther)
0076       : myArray(theOther.myArray)
0077   {
0078   }
0079 
0080   //! Move constructor
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   //! Copy data to theOther
0103   void Copy(math_DoubleTab& theOther) const { theOther.myArray.CopyValues(myArray); }
0104 
0105   //! Returns true if the internal array is deletable (heap-allocated)
0106   bool IsDeletable() const { return myArray.IsDeletable(); }
0107 
0108   //! Set lower row index
0109   void SetLowerRow(const int theLowerRow) { myArray.UpdateLowerRow(theLowerRow); }
0110 
0111   //! Set lower column index
0112   void SetLowerCol(const int theLowerCol) { myArray.UpdateLowerCol(theLowerCol); }
0113 
0114   //! Get lower row index
0115   int LowerRow() const noexcept { return myArray.LowerRow(); }
0116 
0117   //! Get upper row index
0118   int UpperRow() const noexcept { return myArray.UpperRow(); }
0119 
0120   //! Get lower column index
0121   int LowerCol() const noexcept { return myArray.LowerCol(); }
0122 
0123   //! Get upper column index
0124   int UpperCol() const noexcept { return myArray.UpperCol(); }
0125 
0126   //! Get number of rows
0127   int NbRows() const noexcept { return myArray.NbRows(); }
0128 
0129   //! Get number of columns
0130   int NbColumns() const noexcept { return myArray.NbColumns(); }
0131 
0132   //! Access element at (theRowIndex, theColIndex)
0133   const double& Value(const int theRowIndex, const int theColIndex) const
0134   {
0135     return myArray.Value(theRowIndex, theColIndex);
0136   }
0137 
0138   //! Change element at (theRowIndex, theColIndex)
0139   double& Value(const int theRowIndex, const int theColIndex)
0140   {
0141     return myArray.ChangeValue(theRowIndex, theColIndex);
0142   }
0143 
0144   //! Operator() - alias to Value
0145   const double& operator()(const int theRowIndex, const int theColIndex) const
0146   {
0147     return Value(theRowIndex, theColIndex);
0148   }
0149 
0150   //! Operator() - alias to ChangeValue
0151   double& operator()(const int theRowIndex, const int theColIndex)
0152   {
0153     return Value(theRowIndex, theColIndex);
0154   }
0155 
0156   //! Assignment operator
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   //! Move assignment operator
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   //! Destructor
0190   ~math_DoubleTab() = default;
0191 
0192 private:
0193   std::array<double, THE_BUFFER_SIZE> myBuffer;
0194   NCollection_Array2<double>          myArray;
0195 };
0196 
0197 #endif // _math_DoubleTab_HeaderFile