From a575926c2da4baae53b20fb0ac77acb6f52404de Mon Sep 17 00:00:00 2001 From: Pasukhin Dmitry Date: Sat, 1 Nov 2025 21:38:48 +0000 Subject: [PATCH] Foundation Classes, NCollection - Modernize code, add noexcept/constexpr (#793) - Mark many methods and operators noexcept (iterators, containers, allocators, maps, lists, buffers, UTF/string utilities, etc.) - Add constexpr to suitable functions and factory methods (matrices, vectors, static sizes) to enable compile-time usage - Replace non-constexpr memcpy usages in NCollection_Mat3/NCollection_Mat4 with constexpr-friendly initialization and promote static arrays to constexpr - Make several small API improvements: stronger const-correctness, noexcept on allocation/deallocation operators, delete forbidden copy ctors/assign where appropriate - Remove obsolete NCollection_TypeDef.hxx and update FILES.cmake - Miscellaneous small refactors to support modern C++ patterns and better compile-time guarantees --- .../TKMath/Poly/Poly_CoherentLink.hxx | 2 +- .../TKMath/Poly/Poly_CoherentNode.hxx | 2 +- .../TKMath/Poly/Poly_CoherentTriangle.hxx | 2 +- .../Poly/Poly_CoherentTriangulation.cxx | 6 +- .../Poly/Poly_CoherentTriangulation.hxx | 6 +- .../TKernel/NCollection/FILES.cmake | 1 - .../NCollection/NCollection_AccAllocator.cxx | 2 +- .../NCollection/NCollection_AccAllocator.hxx | 51 +++-- .../NCollection_AlignedAllocator.cxx | 2 +- .../NCollection_AlignedAllocator.hxx | 6 +- .../NCollection/NCollection_Allocator.hxx | 17 +- .../NCollection/NCollection_Array1.hxx | 43 ++-- .../NCollection/NCollection_Array2.hxx | 49 +++-- .../NCollection/NCollection_BaseAllocator.hxx | 2 +- .../NCollection/NCollection_BaseList.cxx | 10 +- .../NCollection/NCollection_BaseList.hxx | 38 ++-- .../NCollection/NCollection_BaseMap.cxx | 4 +- .../NCollection/NCollection_BaseMap.hxx | 34 +-- .../NCollection_BasePointerVector.hxx | 14 +- .../NCollection/NCollection_BaseSequence.cxx | 4 +- .../NCollection/NCollection_BaseSequence.hxx | 30 +-- .../NCollection/NCollection_Buffer.hxx | 10 +- .../NCollection/NCollection_CellFilter.hxx | 6 +- .../NCollection/NCollection_DataMap.hxx | 21 +- .../NCollection/NCollection_DefineHArray1.hxx | 4 +- .../NCollection/NCollection_DefineHArray2.hxx | 4 +- .../NCollection_DefineHSequence.hxx | 4 +- .../NCollection/NCollection_DoubleMap.hxx | 17 +- .../NCollection/NCollection_DynamicArray.hxx | 65 +++--- .../NCollection/NCollection_EBTree.hxx | 4 +- .../NCollection/NCollection_Handle.hxx | 18 +- .../NCollection_IndexedDataMap.hxx | 28 ++- .../NCollection_IndexedIterator.hxx | 53 +++-- .../NCollection/NCollection_IndexedMap.hxx | 24 +- .../NCollection/NCollection_Iterator.hxx | 22 +- .../TKernel/NCollection/NCollection_List.hxx | 10 +- .../NCollection/NCollection_ListNode.hxx | 10 +- .../NCollection/NCollection_LocalArray.hxx | 6 +- .../TKernel/NCollection/NCollection_Map.hxx | 14 +- .../TKernel/NCollection/NCollection_Mat3.hxx | 181 +++++++++------ .../TKernel/NCollection/NCollection_Mat4.hxx | 206 +++++++++++------- .../NCollection/NCollection_OccAllocator.hxx | 21 +- .../NCollection/NCollection_Primes.cxx | 5 +- .../NCollection/NCollection_Primes.hxx | 3 +- .../NCollection/NCollection_Sequence.hxx | 32 +-- .../NCollection/NCollection_SparseArray.hxx | 8 +- .../NCollection_SparseArrayBase.hxx | 30 +-- .../NCollection/NCollection_StlIterator.hxx | 4 +- .../NCollection/NCollection_TListIterator.hxx | 14 +- .../NCollection/NCollection_TListNode.hxx | 4 +- .../NCollection/NCollection_TypeDef.hxx | 30 --- .../NCollection/NCollection_UBTree.hxx | 34 +-- .../NCollection/NCollection_UBTreeFiller.hxx | 5 +- .../NCollection/NCollection_UtfIterator.hxx | 69 ++++-- .../NCollection/NCollection_UtfIterator.lxx | 49 ----- .../NCollection/NCollection_UtfString.hxx | 23 +- .../NCollection/NCollection_UtfString.lxx | 8 +- .../TKernel/NCollection/NCollection_Vec2.hxx | 114 ++++++---- .../TKernel/NCollection/NCollection_Vec3.hxx | 160 ++++++++------ .../TKernel/NCollection/NCollection_Vec4.hxx | 144 ++++++------ .../TKernel/Standard/Standard_DefineAlloc.hxx | 8 +- .../TKOpenGl/OpenGl/OpenGl_View_Raytrace.cxx | 6 - .../SelectMgr/SelectMgr_ViewerSelector.cxx | 1 - 63 files changed, 973 insertions(+), 831 deletions(-) delete mode 100644 src/FoundationClasses/TKernel/NCollection/NCollection_TypeDef.hxx diff --git a/src/FoundationClasses/TKMath/Poly/Poly_CoherentLink.hxx b/src/FoundationClasses/TKMath/Poly/Poly_CoherentLink.hxx index 15b7eb5051..21e0665738 100644 --- a/src/FoundationClasses/TKMath/Poly/Poly_CoherentLink.hxx +++ b/src/FoundationClasses/TKMath/Poly/Poly_CoherentLink.hxx @@ -101,7 +101,7 @@ public: * Query the status of the link - if it is an invalid one. * An invalid link has Node members equal to -1. */ - inline Standard_Boolean IsEmpty() const { return myNode[0] < 0 || myNode[1] < 0; } + inline Standard_Boolean IsEmpty() const noexcept { return myNode[0] < 0 || myNode[1] < 0; } /** * Invalidate this Link. diff --git a/src/FoundationClasses/TKMath/Poly/Poly_CoherentNode.hxx b/src/FoundationClasses/TKMath/Poly/Poly_CoherentNode.hxx index 3db8e5fcab..e7170226b3 100644 --- a/src/FoundationClasses/TKMath/Poly/Poly_CoherentNode.hxx +++ b/src/FoundationClasses/TKMath/Poly/Poly_CoherentNode.hxx @@ -117,7 +117,7 @@ public: * Check if this is a free node, i.e., a node without a single * incident triangle. */ - inline Standard_Boolean IsFreeNode() const { return myTriangles == 0L; } + inline Standard_Boolean IsFreeNode() const noexcept { return myTriangles == 0L; } /** * Reset the Node to void. diff --git a/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangle.hxx b/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangle.hxx index ffad2f33a7..447afcf7b6 100644 --- a/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangle.hxx +++ b/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangle.hxx @@ -57,7 +57,7 @@ public: /** * Query if this is a valid triangle. */ - inline Standard_Boolean IsEmpty() const + inline Standard_Boolean IsEmpty() const noexcept { return myNodes[0] < 0 || myNodes[1] < 0 || myNodes[2] < 0; } diff --git a/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangulation.cxx b/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangulation.cxx index 52449c71e6..049ba194f1 100644 --- a/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangulation.cxx +++ b/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangulation.cxx @@ -277,7 +277,7 @@ Poly_CoherentTriangulation::IteratorOfTriangle::IteratorOfTriangle( //================================================================================================= -void Poly_CoherentTriangulation::IteratorOfTriangle::Next() +void Poly_CoherentTriangulation::IteratorOfTriangle::Next() noexcept { Poly_BaseIteratorOfCoherentTriangle::Next(); while (More()) @@ -308,7 +308,7 @@ Poly_CoherentTriangulation::IteratorOfNode::IteratorOfNode( //================================================================================================= -void Poly_CoherentTriangulation::IteratorOfNode::Next() +void Poly_CoherentTriangulation::IteratorOfNode::Next() noexcept { Poly_BaseIteratorOfCoherentNode::Next(); while (More()) @@ -338,7 +338,7 @@ Poly_CoherentTriangulation::IteratorOfLink::IteratorOfLink( //================================================================================================= -void Poly_CoherentTriangulation::IteratorOfLink::Next() +void Poly_CoherentTriangulation::IteratorOfLink::Next() noexcept { Poly_BaseIteratorOfCoherentLink::Next(); while (More()) diff --git a/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangulation.hxx b/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangulation.hxx index c8fcadb4e9..fbbe798e4c 100644 --- a/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangulation.hxx +++ b/src/FoundationClasses/TKMath/Poly/Poly_CoherentTriangulation.hxx @@ -115,7 +115,7 @@ public: //! Constructor Standard_EXPORT IteratorOfTriangle(const Handle(Poly_CoherentTriangulation)& theTri); //! Make step - Standard_EXPORT virtual void Next(); + Standard_EXPORT virtual void Next() noexcept; }; /** @@ -127,7 +127,7 @@ public: //! Constructor Standard_EXPORT IteratorOfNode(const Handle(Poly_CoherentTriangulation)& theTri); //! Make step - Standard_EXPORT virtual void Next(); + Standard_EXPORT virtual void Next() noexcept; }; /** @@ -139,7 +139,7 @@ public: //! Constructor Standard_EXPORT IteratorOfLink(const Handle(Poly_CoherentTriangulation)& theTri); //! Make step - Standard_EXPORT virtual void Next(); + Standard_EXPORT virtual void Next() noexcept; }; //! Couple of integer indices (used in RemoveDegenerated()). diff --git a/src/FoundationClasses/TKernel/NCollection/FILES.cmake b/src/FoundationClasses/TKernel/NCollection/FILES.cmake index 42f4f77310..485bda5d27 100644 --- a/src/FoundationClasses/TKernel/NCollection/FILES.cmake +++ b/src/FoundationClasses/TKernel/NCollection/FILES.cmake @@ -65,7 +65,6 @@ set(OCCT_NCollection_FILES NCollection_String.hxx NCollection_TListIterator.hxx NCollection_TListNode.hxx - NCollection_TypeDef.hxx NCollection_UBTree.hxx NCollection_UBTreeFiller.hxx NCollection_UtfIterator.hxx diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_AccAllocator.cxx b/src/FoundationClasses/TKernel/NCollection/NCollection_AccAllocator.cxx index 877b8aaa2e..774eb5053f 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_AccAllocator.cxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_AccAllocator.cxx @@ -159,7 +159,7 @@ void NCollection_AccAllocator::Free(void* theAddress) //======================================================================= NCollection_AccAllocator::Block* NCollection_AccAllocator::findBlock( const Standard_Address theAddress, - Key& theKey) + Key& theKey) noexcept { theKey = getKey(theAddress); diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_AccAllocator.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_AccAllocator.hxx index 8eb0a2282f..0a371beef7 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_AccAllocator.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_AccAllocator.hxx @@ -43,13 +43,13 @@ class NCollection_AccAllocator : public NCollection_BaseAllocator // --------- PUBLIC CONSTANTS --------- public: //! Alignment of all allocated objects: 4 bytes - static const Standard_Size Align = 4; + static constexpr Standard_Size Align = 4; //! Default block size - static const Standard_Size DefaultBlockSize = 24600; + static constexpr Standard_Size DefaultBlockSize = 24600; //! Number of last blocks to check for free space - static const Standard_Integer MaxLookupBlocks = 16; + static constexpr Standard_Integer MaxLookupBlocks = 16; // ---------- PUBLIC METHODS ---------- public: @@ -77,17 +77,17 @@ protected: Standard_Size myValue; public: - AlignedSize() + constexpr AlignedSize() noexcept : myValue(0) { } - AlignedSize(const Standard_Size theValue) + constexpr AlignedSize(const Standard_Size theValue) noexcept : myValue((theValue + Align - 1) & ~(Align - 1)) { } - operator Standard_Size() const { return myValue; } + constexpr operator Standard_Size() const noexcept { return myValue; } }; //! A pointer aligned to a 4 byte boundary @@ -96,27 +96,27 @@ protected: Standard_Byte* myValue; public: - AlignedPtr() + constexpr AlignedPtr() noexcept : myValue(0) { } - AlignedPtr(const Standard_Address theValue) + AlignedPtr(const Standard_Address theValue) noexcept : myValue((Standard_Byte*)((Standard_Size)theValue & ~(Align - 1))) { } - operator Standard_Address() const { return myValue; } + operator Standard_Address() const noexcept { return myValue; } - operator Standard_Byte*() const { return myValue; } + operator Standard_Byte*() const noexcept { return myValue; } - AlignedPtr operator-(const AlignedSize theValue) const { return myValue - theValue; } + AlignedPtr operator-(const AlignedSize theValue) const noexcept { return myValue - theValue; } - AlignedPtr operator+(const AlignedSize theValue) const { return myValue + theValue; } + AlignedPtr operator+(const AlignedSize theValue) const noexcept { return myValue + theValue; } - AlignedPtr operator-=(const AlignedSize theValue) { return myValue -= theValue; } + AlignedPtr operator-=(const AlignedSize theValue) noexcept { return myValue -= theValue; } - AlignedPtr operator+=(const AlignedSize theValue) { return myValue += theValue; } + AlignedPtr operator+=(const AlignedSize theValue) noexcept { return myValue += theValue; } }; //! A key for the map of blocks @@ -148,7 +148,9 @@ protected: Block* prevBlock; Standard_Integer allocCount; - Block(const Standard_Address theAddress, const Standard_Size theSize, Block* thePrevBlock = 0L) + Block(const Standard_Address theAddress, + const Standard_Size theSize, + Block* thePrevBlock = 0L) noexcept : address(theAddress), prevBlock(thePrevBlock), allocCount(0) @@ -156,14 +158,17 @@ protected: SetFreeSize(theSize); } - void SetFreeSize(const Standard_Size theSize) + void SetFreeSize(const Standard_Size theSize) noexcept { allocStart = (Standard_Byte*)address + theSize; } - Standard_Size FreeSize() const { return (Standard_Byte*)allocStart - (Standard_Byte*)address; } + Standard_Size FreeSize() const noexcept + { + return (Standard_Byte*)allocStart - (Standard_Byte*)address; + } - AlignedPtr Allocate(const AlignedSize theSize) + AlignedPtr Allocate(const AlignedSize theSize) noexcept { allocCount++; return allocStart -= theSize; @@ -171,28 +176,28 @@ protected: void Free() { allocCount--; } - Standard_Boolean IsEmpty() const { return allocCount == 0; } + Standard_Boolean IsEmpty() const noexcept { return allocCount == 0; } }; // --------- PROTECTED METHODS --------- protected: //! Calculate a key for the data map basing on the given address - inline Key getKey(const Standard_Address theAddress) const + inline Key getKey(const Standard_Address theAddress) const noexcept { Key aKey = {(Standard_Size)theAddress / myBlockSize}; return aKey; } //! Find a block that the given allocation unit belongs to - Standard_EXPORT Block* findBlock(const Standard_Address theAddress, Key& theKey); + Standard_EXPORT Block* findBlock(const Standard_Address theAddress, Key& theKey) noexcept; //! Allocate a new block and return a pointer to it Standard_EXPORT Block* allocateNewBlock(const Standard_Size theSize); // --------- PROHIBITED METHODS --------- private: - NCollection_AccAllocator(const NCollection_AccAllocator&); - NCollection_AccAllocator& operator=(const NCollection_AccAllocator&); + NCollection_AccAllocator(const NCollection_AccAllocator&) = delete; + NCollection_AccAllocator& operator=(const NCollection_AccAllocator&) = delete; // --------- PROTECTED DATA --------- protected: diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_AlignedAllocator.cxx b/src/FoundationClasses/TKernel/NCollection/NCollection_AlignedAllocator.cxx index 35795a5c31..a336c267d2 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_AlignedAllocator.cxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_AlignedAllocator.cxx @@ -20,7 +20,7 @@ IMPLEMENT_STANDARD_RTTIEXT(NCollection_AlignedAllocator, NCollection_BaseAllocat //================================================================================================= -NCollection_AlignedAllocator::NCollection_AlignedAllocator(const size_t theAlignment) +NCollection_AlignedAllocator::NCollection_AlignedAllocator(const size_t theAlignment) noexcept : myAlignment(theAlignment) { // diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_AlignedAllocator.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_AlignedAllocator.hxx index 6178e64372..f154698ce8 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_AlignedAllocator.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_AlignedAllocator.hxx @@ -26,7 +26,7 @@ public: //! Constructor. The alignment should be specified explicitly: //! 16 bytes for SSE instructions //! 32 bytes for AVX instructions - Standard_EXPORT NCollection_AlignedAllocator(const size_t theAlignment); + Standard_EXPORT NCollection_AlignedAllocator(const size_t theAlignment) noexcept; //! Allocate memory with given size. Returns NULL on failure. Standard_EXPORT virtual void* Allocate(const size_t theSize) Standard_OVERRIDE; @@ -38,8 +38,8 @@ public: Standard_EXPORT virtual void Free(void* thePtr) Standard_OVERRIDE; private: - NCollection_AlignedAllocator(const NCollection_AlignedAllocator&); - NCollection_AlignedAllocator& operator=(const NCollection_AlignedAllocator&); + NCollection_AlignedAllocator(const NCollection_AlignedAllocator&) = delete; + NCollection_AlignedAllocator& operator=(const NCollection_AlignedAllocator&) = delete; protected: size_t myAlignment; //!< alignment in bytes diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Allocator.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Allocator.hxx index 8b5e8949f5..cd92eda7db 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Allocator.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Allocator.hxx @@ -17,6 +17,7 @@ #include #include +#include #include //! Implements allocator requirements as defined in ISO C++ Standard 2003, section 20.1.5. @@ -74,10 +75,10 @@ public: } //! Returns an object address. - pointer address(reference theItem) const { return &theItem; } + pointer address(reference theItem) const noexcept { return &theItem; } //! Returns an object address. - const_pointer address(const_reference theItem) const { return &theItem; } + const_pointer address(const_reference theItem) const noexcept { return &theItem; } //! Allocates memory for theSize objects. pointer allocate(const size_type theSize, const void* /*hint*/ = 0) const @@ -107,31 +108,31 @@ public: //! Destroys the object. //! Uses the object destructor. - void destroy(pointer thePnt) + void destroy(pointer thePnt) noexcept(std::is_nothrow_destructible::value) { (void)thePnt; thePnt->~value_type(); } - bool operator==(const NCollection_Allocator&) const { return true; } + constexpr bool operator==(const NCollection_Allocator&) const noexcept { return true; } template - bool operator==(const NCollection_Allocator&) const noexcept + constexpr bool operator==(const NCollection_Allocator&) const noexcept { return true; } - bool operator!=(const NCollection_Allocator&) const noexcept { return false; } + constexpr bool operator!=(const NCollection_Allocator&) const noexcept { return false; } template - bool operator!=(const NCollection_Allocator&) const noexcept + constexpr bool operator!=(const NCollection_Allocator&) const noexcept { return false; } }; template -bool operator==(const NCollection_Allocator&, const NCollection_Allocator&) +constexpr bool operator==(const NCollection_Allocator&, const NCollection_Allocator&) noexcept { return true; } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Array1.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Array1.hxx index 374795b087..a5fd812aca 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Array1.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Array1.hxx @@ -81,21 +81,21 @@ public: using Iterator = NCollection_Iterator>; public: - const_iterator begin() const { return const_iterator(*this); } + const_iterator begin() const noexcept { return const_iterator(*this); } - iterator begin() { return iterator(*this); } + iterator begin() noexcept { return iterator(*this); } - const_iterator cbegin() const { return const_iterator(*this); } + const_iterator cbegin() const noexcept { return const_iterator(*this); } - iterator end() { return iterator(mySize, *this); } + iterator end() noexcept { return iterator(mySize, *this); } - const_iterator end() const { return const_iterator(mySize, *this); } + const_iterator end() const noexcept { return const_iterator(mySize, *this); } - const_iterator cend() const { return const_iterator(mySize, *this); } + const_iterator cend() const noexcept { return const_iterator(mySize, *this); } public: // Constructors - NCollection_Array1() + NCollection_Array1() noexcept : myLowerBound(1), mySize(0) { @@ -197,19 +197,19 @@ public: } //! Size query - Standard_Integer Size() const { return Length(); } + Standard_Integer Size() const noexcept { return Length(); } //! Length query (the same) - Standard_Integer Length() const { return static_cast(mySize); } + Standard_Integer Length() const noexcept { return static_cast(mySize); } //! Return TRUE if array has zero length. - Standard_Boolean IsEmpty() const { return mySize == 0; } + Standard_Boolean IsEmpty() const noexcept { return mySize == 0; } //! Lower bound - Standard_Integer Lower() const { return myLowerBound; } + Standard_Integer Lower() const noexcept { return myLowerBound; } //! Upper bound - Standard_Integer Upper() const { return myLowerBound + static_cast(mySize) - 1; } + Standard_Integer Upper() const noexcept { return myLowerBound + static_cast(mySize) - 1; } //! Copies data of theOther array to this. //! This array should be pre-allocated and have the same length as theOther; @@ -255,7 +255,10 @@ public: return *this; } - NCollection_Array1& Move(NCollection_Array1& theOther) { return Move(std::move(theOther)); } + NCollection_Array1& Move(NCollection_Array1& theOther) noexcept + { + return Move(std::move(theOther)); + } //! Assignment operator; @sa Assign() NCollection_Array1& operator=(const NCollection_Array1& theOther) { return Assign(theOther); } @@ -267,16 +270,16 @@ public: } //! @return first element - const_reference First() const { return myPointer[0]; } + const_reference First() const noexcept { return myPointer[0]; } //! @return first element - reference ChangeFirst() { return myPointer[0]; } + reference ChangeFirst() noexcept { return myPointer[0]; } //! @return last element - const_reference Last() const { return myPointer[mySize - 1]; } + const_reference Last() const noexcept { return myPointer[mySize - 1]; } //! @return last element - reference ChangeLast() { return myPointer[mySize - 1]; } + reference ChangeLast() noexcept { return myPointer[mySize - 1]; } //! Constant value access const_reference Value(const Standard_Integer theIndex) const @@ -323,10 +326,10 @@ public: } //! Changes the lowest bound. Do not move data - void UpdateLowerBound(const Standard_Integer theLower) { myLowerBound = theLower; } + void UpdateLowerBound(const Standard_Integer theLower) noexcept { myLowerBound = theLower; } //! Changes the upper bound. Do not move data - void UpdateUpperBound(const Standard_Integer theUpper) + void UpdateUpperBound(const Standard_Integer theUpper) noexcept { myLowerBound = myLowerBound - Upper() + theUpper; } @@ -382,7 +385,7 @@ public: myIsOwner = true; } - bool IsDeletable() const { return myIsOwner; } + bool IsDeletable() const noexcept { return myIsOwner; } friend iterator; friend const_iterator; diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Array2.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Array2.hxx index a008927594..b7519be731 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Array2.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Array2.hxx @@ -67,7 +67,7 @@ public: static int BeginPosition(Standard_Integer theRowLower, Standard_Integer /*theRowUpper*/, Standard_Integer theColLower, - Standard_Integer theColUpper) + Standard_Integer theColUpper) noexcept { // Calculate the offset for the beginning position return theColLower + (theRowLower * (theColUpper - theColLower + 1)); @@ -76,7 +76,7 @@ public: static int LastPosition(Standard_Integer theRowLower, Standard_Integer theRowUpper, Standard_Integer theColLower, - Standard_Integer theColUpper) + Standard_Integer theColUpper) noexcept { return ((theRowUpper - theRowLower + 1) * (theColUpper - theColLower + 1)) + theColLower + (theRowLower * (theColUpper - theColLower + 1)) - 1; @@ -87,7 +87,7 @@ public: //! Empty constructor; should be used with caution. //! @sa methods Resize() and Move(). - NCollection_Array2() + NCollection_Array2() noexcept : NCollection_Array1(), myLowerRow(1), mySizeRow(0), @@ -170,49 +170,55 @@ public: } //! Size (number of items) - Standard_Integer Size() const { return Length(); } + Standard_Integer Size() const noexcept { return Length(); } //! Length (number of items) - Standard_Integer Length() const { return NbRows() * NbColumns(); } + Standard_Integer Length() const noexcept { return NbRows() * NbColumns(); } //! Returns number of rows - Standard_Integer NbRows() const { return static_cast(mySizeRow); } + Standard_Integer NbRows() const noexcept { return static_cast(mySizeRow); } //! Returns number of columns - Standard_Integer NbColumns() const { return static_cast(mySizeCol); } + Standard_Integer NbColumns() const noexcept { return static_cast(mySizeCol); } //! Returns length of the row, i.e. number of columns - Standard_Integer RowLength() const { return NbColumns(); } + Standard_Integer RowLength() const noexcept { return NbColumns(); } //! Returns length of the column, i.e. number of rows - Standard_Integer ColLength() const { return NbRows(); } + Standard_Integer ColLength() const noexcept { return NbRows(); } //! LowerRow - Standard_Integer LowerRow() const { return myLowerRow; } + Standard_Integer LowerRow() const noexcept { return myLowerRow; } //! UpperRow - Standard_Integer UpperRow() const { return myLowerRow + static_cast(mySizeRow) - 1; } + Standard_Integer UpperRow() const noexcept + { + return myLowerRow + static_cast(mySizeRow) - 1; + } //! LowerCol - Standard_Integer LowerCol() const { return myLowerCol; } + Standard_Integer LowerCol() const noexcept { return myLowerCol; } //! UpperCol - Standard_Integer UpperCol() const { return myLowerCol + static_cast(mySizeCol) - 1; } + Standard_Integer UpperCol() const noexcept + { + return myLowerCol + static_cast(mySizeCol) - 1; + } //! Updates lower row - void UpdateLowerRow(const Standard_Integer theLowerRow) { myLowerRow = theLowerRow; } + void UpdateLowerRow(const Standard_Integer theLowerRow) noexcept { myLowerRow = theLowerRow; } //! Updates lower column - void UpdateLowerCol(const Standard_Integer theLowerCol) { myLowerCol = theLowerCol; } + void UpdateLowerCol(const Standard_Integer theLowerCol) noexcept { myLowerCol = theLowerCol; } //! Updates upper row - void UpdateUpperRow(const Standard_Integer theUpperRow) + void UpdateUpperRow(const Standard_Integer theUpperRow) noexcept { myLowerRow = myLowerRow - UpperRow() + theUpperRow; } //! Updates upper column - void UpdateUpperCol(const Standard_Integer theUpperCol) + void UpdateUpperCol(const Standard_Integer theUpperCol) noexcept { myLowerCol = myLowerCol - UpperCol() + theUpperCol; } @@ -232,7 +238,7 @@ public: //! Move assignment. //! This array will borrow all the data from theOther. //! The moved object will be left uninitialized and should not be used anymore. - NCollection_Array2& Move(NCollection_Array2&& theOther) + NCollection_Array2& Move(NCollection_Array2&& theOther) noexcept { if (&theOther == this) { @@ -253,13 +259,16 @@ public: //! Move assignment. //! This array will borrow all the data from theOther. //! The moved object will be left uninitialized and should not be used anymore. - NCollection_Array2& Move(NCollection_Array2& theOther) { return Move(std::move(theOther)); } + NCollection_Array2& Move(NCollection_Array2& theOther) noexcept + { + return Move(std::move(theOther)); + } //! Assignment operator NCollection_Array2& operator=(const NCollection_Array2& theOther) { return Assign(theOther); } //! Move assignment operator; @sa Move() - NCollection_Array2& operator=(NCollection_Array2&& theOther) + NCollection_Array2& operator=(NCollection_Array2&& theOther) noexcept { return Move(std::forward(theOther)); } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseAllocator.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseAllocator.hxx index cccc8a97d4..35a3d00015 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseAllocator.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseAllocator.hxx @@ -58,7 +58,7 @@ public: protected: //! Constructor - prohibited - NCollection_BaseAllocator() {} + NCollection_BaseAllocator() noexcept {} private: //! Copy constructor - prohibited diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseList.cxx b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseList.cxx index 202656b038..cd85811a83 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseList.cxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseList.cxx @@ -41,7 +41,7 @@ void NCollection_BaseList::PClear(NCollection_DelListNode fDel) // purpose : Appends one item at the end //======================================================================= -void NCollection_BaseList::PAppend(NCollection_ListNode* theNode) +void NCollection_BaseList::PAppend(NCollection_ListNode* theNode) noexcept { if (myLength) myLast->Next() = theNode; @@ -57,7 +57,7 @@ void NCollection_BaseList::PAppend(NCollection_ListNode* theNode) // purpose : Appends another list at the end //======================================================================= -void NCollection_BaseList::PAppend(NCollection_BaseList& theOther) +void NCollection_BaseList::PAppend(NCollection_BaseList& theOther) noexcept { if (this == &theOther || theOther.IsEmpty()) return; @@ -78,7 +78,7 @@ void NCollection_BaseList::PAppend(NCollection_BaseList& theOther) // purpose : Prepends one item at the beginning //======================================================================= -void NCollection_BaseList::PPrepend(NCollection_ListNode* theNode) +void NCollection_BaseList::PPrepend(NCollection_ListNode* theNode) noexcept { theNode->Next() = myFirst; myFirst = theNode; @@ -89,7 +89,7 @@ void NCollection_BaseList::PPrepend(NCollection_ListNode* theNode) //================================================================================================= -void NCollection_BaseList::PPrepend(NCollection_BaseList& theOther) +void NCollection_BaseList::PPrepend(NCollection_BaseList& theOther) noexcept { if (this == &theOther || theOther.IsEmpty()) return; @@ -218,7 +218,7 @@ void NCollection_BaseList::PInsertAfter(NCollection_BaseList& theOther, Iterator //================================================================================================= -void NCollection_BaseList::PReverse() +void NCollection_BaseList::PReverse() noexcept { if (myLength > 1) { diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseList.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseList.hxx index 1f60a12c03..77517c151c 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseList.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseList.hxx @@ -45,43 +45,43 @@ public: { public: // ******** Empty constructor - Iterator(void) + Iterator(void) noexcept : myCurrent(NULL), myPrevious(NULL) { } // ******** Constructor with initialisation - Iterator(const NCollection_BaseList& theList) + Iterator(const NCollection_BaseList& theList) noexcept : myCurrent(theList.myFirst), myPrevious(NULL) { } // ******** Initialisation - void Init(const NCollection_BaseList& theList) + void Init(const NCollection_BaseList& theList) noexcept { myCurrent = theList.myFirst; myPrevious = NULL; } // ******** Initialisation - void Initialize(const NCollection_BaseList& theList) { Init(theList); } + void Initialize(const NCollection_BaseList& theList) noexcept { Init(theList); } // ******** More - Standard_Boolean More(void) const { return (myCurrent != NULL); } + Standard_Boolean More(void) const noexcept { return (myCurrent != NULL); } // ******** Comparison operator - Standard_Boolean operator==(const Iterator& theIt) const + Standard_Boolean operator==(const Iterator& theIt) const noexcept { return myCurrent == theIt.myCurrent; } //! Performs comparison of two iterators - Standard_Boolean IsEqual(const Iterator& theOther) const { return *this == theOther; } + Standard_Boolean IsEqual(const Iterator& theOther) const noexcept { return *this == theOther; } protected: - void Init(const NCollection_BaseList& theList, NCollection_ListNode* const thePrev) + void Init(const NCollection_BaseList& theList, NCollection_ListNode* const thePrev) noexcept { myCurrent = thePrev ? thePrev->Next() : (NCollection_ListNode*)theList.PLast(); myPrevious = thePrev; @@ -97,15 +97,15 @@ public: // ---------- PUBLIC METHODS ------------ // ******** Extent // Purpose: Returns the number of nodes in the list - Standard_Integer Extent(void) const { return myLength; } + Standard_Integer Extent(void) const noexcept { return myLength; } // ******** IsEmpty // Purpose: Query if the list is empty - Standard_Boolean IsEmpty(void) const { return (myFirst == NULL); } + Standard_Boolean IsEmpty(void) const noexcept { return (myFirst == NULL); } // ******** Allocator //! Returns attached allocator - const Handle(NCollection_BaseAllocator)& Allocator() const { return myAllocator; } + const Handle(NCollection_BaseAllocator)& Allocator() const noexcept { return myAllocator; } // ******** Destructor // Purpose: defines virtual interface @@ -131,19 +131,19 @@ protected: // ******** PFirst // Purpose: Returns pointer to the first node - const NCollection_ListNode* PFirst(void) const { return myFirst; } + const NCollection_ListNode* PFirst(void) const noexcept { return myFirst; } // ******** PLast // Purpose: Returns pointer to the last node - const NCollection_ListNode* PLast(void) const { return myLast; } + const NCollection_ListNode* PLast(void) const noexcept { return myLast; } // ******** PAppend // Purpose: Appends theNode at the end - Standard_EXPORT void PAppend(NCollection_ListNode* theNode); + Standard_EXPORT void PAppend(NCollection_ListNode* theNode) noexcept; // ******** PAppend // Purpose: Appends theNode at the end, returns iterator to the previous - void PAppend(NCollection_ListNode* theNode, Iterator& theIt) + void PAppend(NCollection_ListNode* theNode, Iterator& theIt) noexcept { NCollection_ListNode* aPrev = myLast; PAppend(theNode); @@ -152,15 +152,15 @@ protected: // ******** PAppend // Purpose: Appends theOther list at the end (clearing it) - Standard_EXPORT void PAppend(NCollection_BaseList& theOther); + Standard_EXPORT void PAppend(NCollection_BaseList& theOther) noexcept; // ******** PPrepend // Purpose: Prepends theNode at the beginning - Standard_EXPORT void PPrepend(NCollection_ListNode* theNode); + Standard_EXPORT void PPrepend(NCollection_ListNode* theNode) noexcept; // ******** PPrepend // Purpose: Prepends theOther list at the beginning (clearing it) - Standard_EXPORT void PPrepend(NCollection_BaseList& theOther); + Standard_EXPORT void PPrepend(NCollection_BaseList& theOther) noexcept; // ******** PRemoveFirst // Purpose: Removes first node @@ -188,7 +188,7 @@ protected: // ******** PReverse // Purpose: Reverse the list - Standard_EXPORT void PReverse(); + Standard_EXPORT void PReverse() noexcept; protected: // ------------ PROTECTED FIELDS ------------ diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.cxx b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.cxx index 949d03f791..972d73dff4 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.cxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.cxx @@ -49,7 +49,7 @@ Standard_Boolean NCollection_BaseMap::BeginResize(const Standard_Integer NbBuck void NCollection_BaseMap::EndResize(const Standard_Integer theNbBuckets, const Standard_Integer N, NCollection_ListNode** data1, - NCollection_ListNode** data2) + NCollection_ListNode** data2) noexcept { (void)theNbBuckets; // obsolete parameter if (myData1) @@ -152,7 +152,7 @@ void NCollection_BaseMap::Statistics(Standard_OStream& S) const //================================================================================================= -Standard_Integer NCollection_BaseMap::NextPrimeForMap(const Standard_Integer N) const +Standard_Integer NCollection_BaseMap::NextPrimeForMap(const Standard_Integer N) const noexcept { return NCollection_Primes::NextPrimeForMap(N); } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.hxx index 7d21645ce2..df4af033e0 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseMap.hxx @@ -47,7 +47,7 @@ public: { protected: //! Empty constructor - Iterator(void) + Iterator(void) noexcept : myNbBuckets(0), myBuckets(nullptr), myBucket(0), @@ -56,7 +56,7 @@ public: } //! Constructor - Iterator(const NCollection_BaseMap& theMap) + Iterator(const NCollection_BaseMap& theMap) noexcept : myNbBuckets(theMap.myNbBuckets), myBuckets(theMap.myData1), myBucket(-1), @@ -76,7 +76,7 @@ public: public: //! Initialize - void Initialize(const NCollection_BaseMap& theMap) + void Initialize(const NCollection_BaseMap& theMap) noexcept { myNbBuckets = theMap.myNbBuckets; myBuckets = theMap.myData1; @@ -88,7 +88,7 @@ public: } //! Reset - void Reset(void) + void Reset(void) noexcept { myBucket = -1; myNode = nullptr; @@ -96,17 +96,17 @@ public: } //! Performs comparison of two iterators. - Standard_Boolean IsEqual(const Iterator& theOther) const + Standard_Boolean IsEqual(const Iterator& theOther) const noexcept { return myBucket == theOther.myBucket && myNode == theOther.myNode; } protected: //! PMore - Standard_Boolean PMore(void) const { return (myNode != nullptr); } + Standard_Boolean PMore(void) const noexcept { return (myNode != nullptr); } //! PNext - void PNext(void) + void PNext(void) noexcept { if (!myBuckets) return; @@ -137,19 +137,19 @@ public: // ---------- PUBLIC METHODS ------------ //! NbBuckets - Standard_Integer NbBuckets() const { return myNbBuckets; } + Standard_Integer NbBuckets() const noexcept { return myNbBuckets; } //! Extent - Standard_Integer Extent() const { return mySize; } + Standard_Integer Extent() const noexcept { return mySize; } //! IsEmpty - Standard_Boolean IsEmpty() const { return mySize == 0; } + Standard_Boolean IsEmpty() const noexcept { return mySize == 0; } //! Statistics Standard_EXPORT void Statistics(Standard_OStream& S) const; //! Returns attached allocator - const Handle(NCollection_BaseAllocator)& Allocator() const { return myAllocator; } + const Handle(NCollection_BaseAllocator)& Allocator() const noexcept { return myAllocator; } protected: // -------- PROTECTED METHODS ----------- @@ -196,26 +196,26 @@ protected: Standard_EXPORT void EndResize(const Standard_Integer NbBuckets, const Standard_Integer NewBuckets, NCollection_ListNode** data1, - NCollection_ListNode** data2); + NCollection_ListNode** data2) noexcept; //! Resizable - Standard_Boolean Resizable() const { return IsEmpty() || (mySize > myNbBuckets); } + Standard_Boolean Resizable() const noexcept { return IsEmpty() || (mySize > myNbBuckets); } //! Increment - Standard_Integer Increment() { return ++mySize; } + Standard_Integer Increment() noexcept { return ++mySize; } //! Decrement - Standard_Integer Decrement() { return --mySize; } + Standard_Integer Decrement() noexcept { return --mySize; } //! Destroy Standard_EXPORT void Destroy(NCollection_DelMapNode fDel, Standard_Boolean doReleaseMemory = Standard_True); //! NextPrimeForMap - Standard_EXPORT Standard_Integer NextPrimeForMap(const Standard_Integer N) const; + Standard_EXPORT Standard_Integer NextPrimeForMap(const Standard_Integer N) const noexcept; //! Exchange content of two maps without data copying - void exchangeMapsData(NCollection_BaseMap& theOther) + void exchangeMapsData(NCollection_BaseMap& theOther) noexcept { std::swap(myAllocator, theOther.myAllocator); std::swap(myData1, theOther.myData1); diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_BasePointerVector.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_BasePointerVector.hxx index 9e10173788..f7bf993861 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_BasePointerVector.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_BasePointerVector.hxx @@ -35,7 +35,7 @@ public: public: //! Default constructor - NCollection_BasePointerVector() {} + NCollection_BasePointerVector() noexcept {} //! Copy data from another vector Standard_EXPORT NCollection_BasePointerVector(const NCollection_BasePointerVector& theOther); @@ -47,16 +47,16 @@ public: ~NCollection_BasePointerVector() { clear(); } //! Checks for an empty status - bool IsEmpty() const { return mySize == 0; } + bool IsEmpty() const noexcept { return mySize == 0; } //! Gets used size - size_t Size() const { return mySize; } + size_t Size() const noexcept { return mySize; } //! Gets available capacity - size_t Capacity() const { return myCapacity; } + size_t Capacity() const noexcept { return myCapacity; } //! Erases last element, decrements size. - void RemoveLast() { mySize--; } + void RemoveLast() noexcept { mySize--; } //! Resets the size void Clear(const bool theReleaseMemory = false) @@ -68,10 +68,10 @@ public: public: //! Gets array, can be null - void** GetArray() const { return myArray; } + void** GetArray() const noexcept { return myArray; } //! Gets value by index, no access validation - void* Value(const size_t theInd) const { return myArray[theInd]; } + void* Value(const size_t theInd) const noexcept { return myArray[theInd]; } public: //! Inserts new element at the end, increase size, diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseSequence.cxx b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseSequence.cxx index e7d0413247..3224a781eb 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseSequence.cxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseSequence.cxx @@ -147,7 +147,7 @@ void NCollection_BaseSequence::PPrepend(NCollection_BaseSequence& Other) // purpose : reverse the order of a given sequence //======================================================================= -void NCollection_BaseSequence::PReverse() +void NCollection_BaseSequence::PReverse() noexcept { NCollection_SeqNode* p = myFirstItem; while (p) @@ -444,7 +444,7 @@ void NCollection_BaseSequence::RemoveSeq(const Standard_Integer From, //================================================================================================= -NCollection_SeqNode* NCollection_BaseSequence::Find(const Standard_Integer theIndex) const +NCollection_SeqNode* NCollection_BaseSequence::Find(const Standard_Integer theIndex) const noexcept { Standard_Integer i; NCollection_SeqNode* p; diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseSequence.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseSequence.hxx index e6cb3bc6ce..818c3a36d5 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_BaseSequence.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_BaseSequence.hxx @@ -28,19 +28,19 @@ public: // define new operator for use with NCollection allocators DEFINE_NCOLLECTION_ALLOC public: - NCollection_SeqNode() + NCollection_SeqNode() noexcept : myNext(NULL), myPrevious(NULL) { } - NCollection_SeqNode* Next() const { return myNext; } + NCollection_SeqNode* Next() const noexcept { return myNext; } - NCollection_SeqNode* Previous() const { return myPrevious; } + NCollection_SeqNode* Previous() const noexcept { return myPrevious; } - void SetNext(NCollection_SeqNode* theNext) { myNext = theNext; } + void SetNext(NCollection_SeqNode* theNext) noexcept { myNext = theNext; } - void SetPrevious(NCollection_SeqNode* thePrev) { myPrevious = thePrev; } + void SetPrevious(NCollection_SeqNode* thePrev) noexcept { myPrevious = thePrev; } private: NCollection_SeqNode* myNext; @@ -66,28 +66,28 @@ public: { public: //! Empty constructor - Iterator(void) + Iterator(void) noexcept : myCurrent(NULL), myPrevious(NULL) { } //! Constructor with initialisation - Iterator(const NCollection_BaseSequence& theSeq, const Standard_Boolean isStart) + Iterator(const NCollection_BaseSequence& theSeq, const Standard_Boolean isStart) noexcept { Init(theSeq, isStart); } //! Initialisation void Init(const NCollection_BaseSequence& theSeq, - const Standard_Boolean isStart = Standard_True) + const Standard_Boolean isStart = Standard_True) noexcept { myCurrent = (isStart ? theSeq.myFirstItem : NULL); myPrevious = (isStart ? NULL : theSeq.myLastItem); } //! Switch to previous element; note that it will reset - void Previous() + void Previous() noexcept { myCurrent = myPrevious; if (myCurrent) @@ -103,12 +103,12 @@ public: public: // Methods PUBLIC // - Standard_Boolean IsEmpty() const { return (mySize == 0); } + Standard_Boolean IsEmpty() const noexcept { return (mySize == 0); } - Standard_Integer Length() const { return mySize; } + Standard_Integer Length() const noexcept { return mySize; } //! Returns attached allocator - const Handle(NCollection_BaseAllocator)& Allocator() const { return myAllocator; } + const Handle(NCollection_BaseAllocator)& Allocator() const noexcept { return myAllocator; } protected: // Methods PROTECTED @@ -141,9 +141,9 @@ protected: Standard_EXPORT void RemoveSeq(const Standard_Integer From, const Standard_Integer To, NCollection_DelSeqNode fDel); - Standard_EXPORT void PReverse(); + Standard_EXPORT void PReverse() noexcept; Standard_EXPORT void PExchange(const Standard_Integer I, const Standard_Integer J); - Standard_EXPORT NCollection_SeqNode* Find(const Standard_Integer) const; + Standard_EXPORT NCollection_SeqNode* Find(const Standard_Integer) const noexcept; protected: // Fields PROTECTED @@ -160,7 +160,7 @@ private: // Standard_EXPORT NCollection_BaseSequence(const NCollection_BaseSequence& Other); - void Nullify() + void Nullify() noexcept { myFirstItem = myLastItem = myCurrentItem = NULL; myCurrentIndex = mySize = 0; diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Buffer.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Buffer.hxx index 24c85064f4..d42d56f280 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Buffer.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Buffer.hxx @@ -51,19 +51,19 @@ public: ~NCollection_Buffer() { Free(); } //! @return buffer data - const Standard_Byte* Data() const { return myData; } + const Standard_Byte* Data() const noexcept { return myData; } //! @return buffer data - Standard_Byte* ChangeData() { return myData; } + Standard_Byte* ChangeData() noexcept { return myData; } //! @return true if buffer is not allocated - bool IsEmpty() const { return myData == NULL; } + bool IsEmpty() const noexcept { return myData == NULL; } //! Return buffer length in bytes. - Standard_Size Size() const { return mySize; } + Standard_Size Size() const noexcept { return mySize; } //! @return buffer allocator - const Handle(NCollection_BaseAllocator)& Allocator() const { return myAllocator; } + const Handle(NCollection_BaseAllocator)& Allocator() const noexcept { return myAllocator; } //! Assign new buffer allocator with de-allocation of buffer. void SetAllocator(const Handle(NCollection_BaseAllocator)& theAlloc) diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_CellFilter.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_CellFilter.hxx index a8061e2d9e..c2379d0d4f 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_CellFilter.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_CellFilter.hxx @@ -283,7 +283,7 @@ protected: } //! Assignment operator: ensure that list is not deleted twice - void operator=(const Cell& theOther) + void operator=(const Cell& theOther) noexcept { Standard_Integer aDim = Standard_Integer(theOther.index.Size()); for (Standard_Integer anIdx = 0; anIdx < aDim; anIdx++) @@ -303,7 +303,7 @@ protected: } //! Compare cell with other one - Standard_Boolean IsEqual(const Cell& theOther) const + Standard_Boolean IsEqual(const Cell& theOther) const noexcept { Standard_Integer aDim = Standard_Integer(theOther.index.Size()); for (int i = 0; i < aDim; i++) @@ -312,7 +312,7 @@ protected: return Standard_True; } - bool operator==(const Cell& theOther) const { return IsEqual(theOther); } + bool operator==(const Cell& theOther) const noexcept { return IsEqual(theOther); } public: NCollection_LocalArray index; diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_DataMap.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_DataMap.hxx index ee3b2c6ce8..b6484f0f47 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_DataMap.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_DataMap.hxx @@ -88,10 +88,11 @@ public: } //! Key - const TheKeyType& Key(void) const { return myKey; } + const TheKeyType& Key(void) const noexcept { return myKey; } //! Static deleter to be passed to BaseMap - static void delNode(NCollection_ListNode* theNode, Handle(NCollection_BaseAllocator)& theAl) + static void delNode(NCollection_ListNode* theNode, + Handle(NCollection_BaseAllocator)& theAl) noexcept { ((DataMapNode*)theNode)->~DataMapNode(); theAl->Free(theNode); @@ -119,10 +120,10 @@ public: } //! Query if the end of collection is reached by iterator - Standard_Boolean More(void) const { return PMore(); } + Standard_Boolean More(void) const noexcept { return PMore(); } //! Make a step along the collection - void Next(void) { PNext(); } + void Next(void) noexcept { PNext(); } //! Value inquiry const TheItemType& Value(void) const @@ -154,16 +155,16 @@ public: const_iterator; //! Returns an iterator pointing to the first element in the map. - iterator begin() const { return Iterator(*this); } + iterator begin() const noexcept { return Iterator(*this); } //! Returns an iterator referring to the past-the-end element in the map. - iterator end() const { return Iterator(); } + iterator end() const noexcept { return Iterator(); } //! Returns a const iterator pointing to the first element in the map. - const_iterator cbegin() const { return Iterator(*this); } + const_iterator cbegin() const noexcept { return Iterator(*this); } //! Returns a const iterator referring to the past-the-end element in the map. - const_iterator cend() const { return Iterator(); } + const_iterator cend() const noexcept { return Iterator(); } public: // ---------- PUBLIC METHODS ------------ @@ -201,7 +202,7 @@ public: //! Exchange the content of two maps without re-allocations. //! Notice that allocators will be swapped as well! - void Exchange(NCollection_DataMap& theOther) { this->exchangeMapsData(theOther); } + void Exchange(NCollection_DataMap& theOther) noexcept { this->exchangeMapsData(theOther); } //! Assignment. //! This method does not change the internal allocator. @@ -552,7 +553,7 @@ public: virtual ~NCollection_DataMap(void) { Clear(true); } //! Size - Standard_Integer Size(void) const { return Extent(); } + Standard_Integer Size(void) const noexcept { return Extent(); } protected: //! Lookup for particular key in map. diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHArray1.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHArray1.hxx index b406d04f14..ef187c5bb5 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHArray1.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHArray1.hxx @@ -55,11 +55,11 @@ : _Array1Type_(theOther) \ { \ } \ - const _Array1Type_& Array1() const \ + const _Array1Type_& Array1() const noexcept \ { \ return *this; \ } \ - _Array1Type_& ChangeArray1() \ + _Array1Type_& ChangeArray1() noexcept \ { \ return *this; \ } \ diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHArray2.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHArray2.hxx index 85b7d9a34a..4e7fd3ab21 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHArray2.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHArray2.hxx @@ -49,11 +49,11 @@ : _Array2Type_(theOther) \ { \ } \ - const _Array2Type_& Array2() const \ + const _Array2Type_& Array2() const noexcept \ { \ return *this; \ } \ - _Array2Type_& ChangeArray2() \ + _Array2Type_& ChangeArray2() noexcept \ { \ return *this; \ } \ diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHSequence.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHSequence.hxx index a2534bfbc6..d3aeea824e 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHSequence.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_DefineHSequence.hxx @@ -34,7 +34,7 @@ : _SequenceType_(theOther) \ { \ } \ - const _SequenceType_& Sequence() const \ + const _SequenceType_& Sequence() const noexcept \ { \ return *this; \ } \ @@ -46,7 +46,7 @@ { \ _SequenceType_::Append(theSequence); \ } \ - _SequenceType_& ChangeSequence() \ + _SequenceType_& ChangeSequence() noexcept \ { \ return *this; \ } \ diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_DoubleMap.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_DoubleMap.hxx index 1d5e0e0dd0..18df51e320 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_DoubleMap.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_DoubleMap.hxx @@ -60,16 +60,17 @@ public: } //! Key1 - const TheKey1Type& Key1(void) { return myKey1; } + const TheKey1Type& Key1(void) noexcept { return myKey1; } //! Key2 - const TheKey2Type& Key2(void) { return this->myValue; } + const TheKey2Type& Key2(void) noexcept { return this->myValue; } //! Next2 - DoubleMapNode*& Next2(void) { return myNext2; } + DoubleMapNode*& Next2(void) noexcept { return myNext2; } //! Static deleter to be passed to BaseList - static void delNode(NCollection_ListNode* theNode, Handle(NCollection_BaseAllocator)& theAl) + static void delNode(NCollection_ListNode* theNode, + Handle(NCollection_BaseAllocator)& theAl) noexcept { ((DoubleMapNode*)theNode)->~DoubleMapNode(); theAl->Free(theNode); @@ -95,10 +96,10 @@ public: } //! Query if the end of collection is reached by iterator - Standard_Boolean More(void) const { return PMore(); } + Standard_Boolean More(void) const noexcept { return PMore(); } //! Make a step along the collection - void Next(void) { PNext(); } + void Next(void) noexcept { PNext(); } //! Key1 inquiry const TheKey1Type& Key1(void) const @@ -147,7 +148,7 @@ public: //! Exchange the content of two maps without re-allocations. //! Notice that allocators will be swapped as well! - void Exchange(NCollection_DoubleMap& theOther) { this->exchangeMapsData(theOther); } + void Exchange(NCollection_DoubleMap& theOther) noexcept { this->exchangeMapsData(theOther); } //! Assignment. //! This method does not change the internal allocator. @@ -507,7 +508,7 @@ public: ~NCollection_DoubleMap(void) { Clear(true); } //! Size - Standard_Integer Size(void) const { return Extent(); } + Standard_Integer Size(void) const noexcept { return Extent(); } protected: bool IsEqual1(const TheKey1Type& theKey1, const TheKey1Type& theKey2) const diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_DynamicArray.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_DynamicArray.hxx index cc82331ad4..23e0a2f761 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_DynamicArray.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_DynamicArray.hxx @@ -84,17 +84,17 @@ public: using Iterator = NCollection_Iterator>; public: - const_iterator begin() const { return const_iterator(*this); } + const_iterator begin() const noexcept { return const_iterator(*this); } - iterator begin() { return iterator(*this); } + iterator begin() noexcept { return iterator(*this); } - const_iterator cbegin() const { return const_iterator(*this); } + const_iterator cbegin() const noexcept { return const_iterator(*this); } - iterator end() { return iterator(myUsedSize, *this); } + iterator end() noexcept { return iterator(myUsedSize, *this); } - const_iterator end() const { return const_iterator(myUsedSize, *this); } + const_iterator end() const noexcept { return const_iterator(myUsedSize, *this); } - const_iterator cend() const { return const_iterator(myUsedSize, *this); } + const_iterator cend() const noexcept { return const_iterator(myUsedSize, *this); } public: //! @name public methods NCollection_DynamicArray(const Standard_Integer theIncrement = 256) @@ -147,21 +147,21 @@ public: //! @name public methods ~NCollection_DynamicArray() { Clear(true); } //! Total number of items - Standard_Integer Length() const { return static_cast(myUsedSize); } + Standard_Integer Length() const noexcept { return static_cast(myUsedSize); } //! Total number of items in the vector - Standard_Integer Size() const { return Length(); } + Standard_Integer Size() const noexcept { return Length(); } //! Method for consistency with other collections. //! @return Lower bound (inclusive) for iteration. - Standard_Integer Lower() const { return 0; } + Standard_Integer Lower() const noexcept { return 0; } //! Method for consistency with other collections. //! @return Upper bound (inclusive) for iteration. - Standard_Integer Upper() const { return Length() - 1; } + Standard_Integer Upper() const noexcept { return Length() - 1; } //! Empty query - Standard_Boolean IsEmpty() const { return myUsedSize == 0; } + Standard_Boolean IsEmpty() const noexcept { return myUsedSize == 0; } //! Assignment to the collection of the same type NCollection_DynamicArray& Assign(const NCollection_DynamicArray& theOther, @@ -262,41 +262,50 @@ public: //! @name public methods } //! Operator() - query the const value - const_reference operator()(const Standard_Integer theIndex) const { return Value(theIndex); } + const_reference operator()(const Standard_Integer theIndex) const noexcept + { + return Value(theIndex); + } //! Operator[] - query the const value - const_reference operator[](const Standard_Integer theIndex) const { return Value(theIndex); } + const_reference operator[](const Standard_Integer theIndex) const noexcept + { + return Value(theIndex); + } //! Operator[] - query the const value - const_reference operator[](const size_t theIndex) const { return at(theIndex); } + const_reference operator[](const size_t theIndex) const noexcept { return at(theIndex); } - const_reference Value(const Standard_Integer theIndex) const + const_reference Value(const Standard_Integer theIndex) const noexcept { return at(static_cast(theIndex)); } //! @return first element - const_reference First() const { return getArray()[0][0]; } + const_reference First() const noexcept { return getArray()[0][0]; } //! @return first element - reference ChangeFirst() { return getArray()[0][0]; } + reference ChangeFirst() noexcept { return getArray()[0][0]; } //! @return last element - const_reference Last() const { return at(myUsedSize - 1); } + const_reference Last() const noexcept { return at(myUsedSize - 1); } //! @return last element - reference ChangeLast() { return at(myUsedSize - 1); } + reference ChangeLast() noexcept { return at(myUsedSize - 1); } //! Operator() - query the value - reference operator()(const Standard_Integer theIndex) { return ChangeValue(theIndex); } + reference operator()(const Standard_Integer theIndex) noexcept { return ChangeValue(theIndex); } //! Operator[] - query the value - reference operator[](const Standard_Integer theIndex) { return ChangeValue(theIndex); } + reference operator[](const Standard_Integer theIndex) noexcept { return ChangeValue(theIndex); } //! Operator[] - query the value - reference operator[](const size_t theIndex) { return at(theIndex); } + reference operator[](const size_t theIndex) noexcept { return at(theIndex); } - reference ChangeValue(const Standard_Integer theIndex) { return at(static_cast(theIndex)); } + reference ChangeValue(const Standard_Integer theIndex) noexcept + { + return at(static_cast(theIndex)); + } //! SetValue () - set or append a value reference SetValue(const Standard_Integer theIndex, const TheItemType& theValue) @@ -363,7 +372,7 @@ public: //! @name public methods myUsedSize = 0; } - void SetIncrement(const Standard_Integer theIncrement) + void SetIncrement(const Standard_Integer theIncrement) noexcept { if (myUsedSize != 0) { @@ -376,7 +385,7 @@ public: //! @name public methods friend const_iterator; protected: - size_t availableSize() const { return myContainer.Size() * myInternalSize; } + size_t availableSize() const noexcept { return myContainer.Size() * myInternalSize; } TheItemType* expandArray() { @@ -385,12 +394,12 @@ protected: return aNewBlock; } - reference at(const size_t theInd) + reference at(const size_t theInd) noexcept { return getArray()[theInd / myInternalSize][theInd % myInternalSize]; } - const_reference at(const size_t theInd) const + const_reference at(const size_t theInd) const noexcept { return getArray()[theInd / myInternalSize][theInd % myInternalSize]; } @@ -413,7 +422,7 @@ protected: } //! Wrapper to extract array - TheItemType** getArray() const { return (TheItemType**)myContainer.GetArray(); } + TheItemType** getArray() const noexcept { return (TheItemType**)myContainer.GetArray(); } protected: vector myContainer; diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_EBTree.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_EBTree.hxx index b934061b99..d9de48c389 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_EBTree.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_EBTree.hxx @@ -212,11 +212,11 @@ Standard_Boolean NCollection_EBTree::Remove(const TheObj \ /* Access to the extended tree algorithm */ \ \ - const EBTree& ETree() const \ + const EBTree& ETree() const noexcept \ { \ return (const EBTree&)Tree(); \ } \ - EBTree& ChangeETree() \ + EBTree& ChangeETree() noexcept \ { \ return (EBTree&)ChangeTree(); \ } \ diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Handle.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Handle.hxx index b326806efd..3934616a2c 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Handle.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Handle.hxx @@ -83,26 +83,30 @@ public: } //! Cast handle to contained type - T* get() { return ((Ptr*)opencascade::handle::get())->myPtr; } + T* get() noexcept { return ((Ptr*)opencascade::handle::get())->myPtr; } //! Cast handle to contained type - const T* get() const { return ((Ptr*)opencascade::handle::get())->myPtr; } + const T* get() const noexcept + { + return ((Ptr*)opencascade::handle::get())->myPtr; + } //! Cast handle to contained type - T* operator->() { return get(); } + T* operator->() noexcept { return get(); } //! Cast handle to contained type - const T* operator->() const { return get(); } + const T* operator->() const noexcept { return get(); } //! Cast handle to contained type - T& operator*() { return *get(); } + T& operator*() noexcept { return *get(); } //! Cast handle to contained type - const T& operator*() const { return *get(); } + const T& operator*() const noexcept { return *get(); } //! Downcast arbitrary Handle to the argument type if contained //! object is Handle for this type; returns null otherwise - static NCollection_Handle DownCast(const opencascade::handle& theOther) + static NCollection_Handle DownCast( + const opencascade::handle& theOther) noexcept { return NCollection_Handle(dynamic_cast(theOther.get()), 0); } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedDataMap.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedDataMap.hxx index 9b426a7ca9..e74c5f6516 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedDataMap.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedDataMap.hxx @@ -105,13 +105,14 @@ private: } //! Key1 - TheKeyType& Key1() { return myKey1; } + TheKeyType& Key1() noexcept { return myKey1; } //! Index - Standard_Integer& Index() { return myIndex; } + Standard_Integer& Index() noexcept { return myIndex; } //! Static deleter to be passed to BaseList - static void delNode(NCollection_ListNode* theNode, Handle(NCollection_BaseAllocator)& theAl) + static void delNode(NCollection_ListNode* theNode, + Handle(NCollection_BaseAllocator)& theAl) noexcept { ((IndexedDataMapNode*)theNode)->~IndexedDataMapNode(); theAl->Free(theNode); @@ -142,10 +143,13 @@ public: } //! Query if the end of collection is reached by iterator - Standard_Boolean More(void) const { return (myMap != NULL) && (myIndex <= myMap->Extent()); } + Standard_Boolean More(void) const noexcept + { + return (myMap != NULL) && (myIndex <= myMap->Extent()); + } //! Make a step along the collection - void Next(void) { ++myIndex; } + void Next(void) noexcept { ++myIndex; } //! Value access const TheItemType& Value(void) const @@ -169,7 +173,7 @@ public: } //! Performs comparison of two iterators. - Standard_Boolean IsEqual(const Iterator& theOther) const + Standard_Boolean IsEqual(const Iterator& theOther) const noexcept { return myMap == theOther.myMap && myIndex == theOther.myIndex; } @@ -187,16 +191,16 @@ public: const_iterator; //! Returns an iterator pointing to the first element in the map. - iterator begin() const { return Iterator(*this); } + iterator begin() const noexcept { return Iterator(*this); } //! Returns an iterator referring to the past-the-end element in the map. - iterator end() const { return Iterator(); } + iterator end() const noexcept { return Iterator(); } //! Returns a const iterator pointing to the first element in the map. - const_iterator cbegin() const { return Iterator(*this); } + const_iterator cbegin() const noexcept { return Iterator(*this); } //! Returns a const iterator referring to the past-the-end element in the map. - const_iterator cend() const { return Iterator(); } + const_iterator cend() const noexcept { return Iterator(); } public: // ---------- PUBLIC METHODS ------------ @@ -229,7 +233,7 @@ public: //! Exchange the content of two maps without re-allocations. //! Notice that allocators will be swapped as well! - void Exchange(NCollection_IndexedDataMap& theOther) { this->exchangeMapsData(theOther); } + void Exchange(NCollection_IndexedDataMap& theOther) noexcept { this->exchangeMapsData(theOther); } //! Assignment. //! This method does not change the internal allocator. @@ -653,7 +657,7 @@ public: virtual ~NCollection_IndexedDataMap(void) { Clear(true); } //! Size - Standard_Integer Size(void) const { return Extent(); } + Standard_Integer Size(void) const noexcept { return Extent(); } protected: //! Lookup for particular key in map. diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedIterator.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedIterator.hxx index 85561d10ad..eedb7d07e3 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedIterator.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedIterator.hxx @@ -35,21 +35,21 @@ public: using reference = typename std::conditional::type; //! Default constructor - NCollection_IndexedIterator() + NCollection_IndexedIterator() noexcept : myIndex(0), myIndexedMap(nullptr) { } //! Constructor from NCollection_Indexed*Map - NCollection_IndexedIterator(const BaseIndexedMap& theMap) + NCollection_IndexedIterator(const BaseIndexedMap& theMap) noexcept : myIndex(0), myIndexedMap((&const_cast(theMap))) { } //! Constructor from NCollection_Indexed*Map - NCollection_IndexedIterator(const size_t theIndex, const BaseIndexedMap& theMap) + NCollection_IndexedIterator(const size_t theIndex, const BaseIndexedMap& theMap) noexcept : myIndex(theIndex), myIndexedMap(&const_cast(theMap)) { @@ -57,7 +57,7 @@ public: //! Cast from non-const variant to const one NCollection_IndexedIterator( - const NCollection_IndexedIterator& theOther) + const NCollection_IndexedIterator& theOther) noexcept : myIndex(theOther.myIndex), myIndexedMap(theOther.myIndexedMap) { @@ -65,7 +65,7 @@ public: //! Assignment of non-const iterator to const one NCollection_IndexedIterator& operator=( - const NCollection_IndexedIterator& theOther) + const NCollection_IndexedIterator& theOther) noexcept { myIndex = theOther.myIndex; myIndexedMap = theOther.myIndexedMap; @@ -90,7 +90,7 @@ protected: //! @name methods related to forward STL iterator public: //! @name methods related to forward STL iterator //! Test for equality - bool operator==(const NCollection_IndexedIterator& theOther) const + bool operator==(const NCollection_IndexedIterator& theOther) const noexcept { return myIndexedMap == theOther.myIndexedMap && myIndex == theOther.myIndex; } @@ -98,7 +98,7 @@ public: //! @name methods related to forward STL iterator template bool operator==( const NCollection_IndexedIterator& - theOther) const + theOther) const noexcept { return myIndexedMap == theOther.myIndexedMap && myIndex == theOther.myIndex; } @@ -106,13 +106,13 @@ public: //! @name methods related to forward STL iterator template bool operator!=( const NCollection_IndexedIterator& - theOther) const + theOther) const noexcept { return myIndexedMap != theOther.myIndexedMap || myIndex != theOther.myIndex; } //! Test for inequality - bool operator!=(const NCollection_IndexedIterator& theOther) const + bool operator!=(const NCollection_IndexedIterator& theOther) const noexcept { return !(*this == theOther); } @@ -130,14 +130,14 @@ public: //! @name methods related to forward STL iterator } //! Prefix increment - NCollection_IndexedIterator& operator++() + NCollection_IndexedIterator& operator++() noexcept { myIndex++; return *this; } //! Postfix increment - NCollection_IndexedIterator operator++(int) + NCollection_IndexedIterator operator++(int) noexcept { const NCollection_IndexedIterator theOld(*this); ++(*this); @@ -146,7 +146,7 @@ public: //! @name methods related to forward STL iterator public: //! @name methods related to bidirectional STL iterator //! Prefix decrement - NCollection_IndexedIterator& operator--() + NCollection_IndexedIterator& operator--() noexcept { Standard_STATIC_ASSERT( (opencascade::std::is_same::value @@ -156,7 +156,7 @@ public: //! @name methods related to bidirectional STL iterator } //! Postfix decrement - NCollection_IndexedIterator operator--(int) + NCollection_IndexedIterator operator--(int) noexcept { NCollection_IndexedIterator theOld(*this); --(*this); @@ -166,7 +166,7 @@ public: //! @name methods related to bidirectional STL iterator public: //! @name methods related to random access STL iterator //! Move forward NCollection_IndexedIterator& operator+=( - typename NCollection_IndexedIterator::difference_type theOffset) + typename NCollection_IndexedIterator::difference_type theOffset) noexcept { Standard_STATIC_ASSERT( (opencascade::std::is_same::value)); @@ -176,7 +176,7 @@ public: //! @name methods related to random access STL iterator //! Addition NCollection_IndexedIterator operator+( - typename NCollection_IndexedIterator::difference_type theOffset) const + typename NCollection_IndexedIterator::difference_type theOffset) const noexcept { NCollection_IndexedIterator aTemp(*this); return aTemp += theOffset; @@ -184,14 +184,14 @@ public: //! @name methods related to random access STL iterator //! Move backward NCollection_IndexedIterator& operator-=( - typename NCollection_IndexedIterator::difference_type theOffset) + typename NCollection_IndexedIterator::difference_type theOffset) noexcept { return *this += -theOffset; } //! Decrease NCollection_IndexedIterator operator-( - typename NCollection_IndexedIterator::difference_type theOffset) const + typename NCollection_IndexedIterator::difference_type theOffset) const noexcept { NCollection_IndexedIterator aTemp(*this); return aTemp += -theOffset; @@ -199,7 +199,7 @@ public: //! @name methods related to random access STL iterator //! Difference typename NCollection_IndexedIterator::difference_type operator-( - const NCollection_IndexedIterator& theOther) const + const NCollection_IndexedIterator& theOther) const noexcept { Standard_STATIC_ASSERT( (opencascade::std::is_same::value)); @@ -214,19 +214,28 @@ public: //! @name methods related to random access STL iterator } //! Comparison - bool operator<(const NCollection_IndexedIterator& theOther) const + bool operator<(const NCollection_IndexedIterator& theOther) const noexcept { return (*this - theOther) < 0; } //! Comparison - bool operator>(const NCollection_IndexedIterator& theOther) const { return theOther < *this; } + bool operator>(const NCollection_IndexedIterator& theOther) const noexcept + { + return theOther < *this; + } //! Comparison - bool operator<=(const NCollection_IndexedIterator& theOther) const { return !(theOther < *this); } + bool operator<=(const NCollection_IndexedIterator& theOther) const noexcept + { + return !(theOther < *this); + } //! Comparison - bool operator>=(const NCollection_IndexedIterator& theOther) const { return !(*this < theOther); } + bool operator>=(const NCollection_IndexedIterator& theOther) const noexcept + { + return !(*this < theOther); + } friend class NCollection_IndexedIterator; diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedMap.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedMap.hxx index cd2fb190fa..a26186e6c1 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedMap.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_IndexedMap.hxx @@ -67,13 +67,14 @@ protected: } //! Key1 - TheKeyType& Key1() { return this->ChangeValue(); } + TheKeyType& Key1() noexcept { return this->ChangeValue(); } //! Index - Standard_Integer& Index() { return myIndex; } + Standard_Integer& Index() noexcept { return myIndex; } //! Static deleter to be passed to BaseList - static void delNode(NCollection_ListNode* theNode, Handle(NCollection_BaseAllocator)& theAl) + static void delNode(NCollection_ListNode* theNode, + Handle(NCollection_BaseAllocator)& theAl) noexcept { ((IndexedMapNode*)theNode)->~IndexedMapNode(); theAl->Free(theNode); @@ -103,10 +104,13 @@ public: } //! Query if the end of collection is reached by iterator - Standard_Boolean More(void) const { return (myMap != NULL) && (myIndex <= myMap->Extent()); } + Standard_Boolean More(void) const noexcept + { + return (myMap != NULL) && (myIndex <= myMap->Extent()); + } //! Make a step along the collection - void Next(void) { myIndex++; } + void Next(void) noexcept { myIndex++; } //! Value access const TheKeyType& Value(void) const @@ -116,7 +120,7 @@ public: } //! Performs comparison of two iterators. - Standard_Boolean IsEqual(const Iterator& theOther) const + Standard_Boolean IsEqual(const Iterator& theOther) const noexcept { return myMap == theOther.myMap && myIndex == theOther.myIndex; } @@ -131,10 +135,10 @@ public: const_iterator; //! Returns a const iterator pointing to the first element in the map. - const_iterator cbegin() const { return Iterator(*this); } + const_iterator cbegin() const noexcept { return Iterator(*this); } //! Returns a const iterator referring to the past-the-end element in the map. - const_iterator cend() const { return Iterator(); } + const_iterator cend() const noexcept { return Iterator(); } public: // ---------- PUBLIC METHODS ------------ @@ -167,7 +171,7 @@ public: //! Exchange the content of two maps without re-allocations. //! Notice that allocators will be swapped as well! - void Exchange(NCollection_IndexedMap& theOther) { this->exchangeMapsData(theOther); } + void Exchange(NCollection_IndexedMap& theOther) noexcept { this->exchangeMapsData(theOther); } //! Assign. //! This method does not change the internal allocator. @@ -448,7 +452,7 @@ public: virtual ~NCollection_IndexedMap(void) { Clear(true); } //! Size - Standard_Integer Size(void) const { return Extent(); } + Standard_Integer Size(void) const noexcept { return Extent(); } protected: //! Lookup for particular key in map. diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Iterator.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Iterator.hxx index 55369b57d6..810f6b150f 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Iterator.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Iterator.hxx @@ -57,7 +57,7 @@ public: { } - ~NCollection_Iterator() {} + ~NCollection_Iterator() noexcept {} void Init(Container& theList) { @@ -67,37 +67,37 @@ public: void Init(const Container& theList) { Init(const_cast(theList)); } - virtual bool More() const { return myCur != myLast; } + virtual bool More() const noexcept { return myCur != myLast; } void Initialize(Container& theList) { Init(theList); } void Initialize(const Container& theList) { Init(theList); } - const typename Container::iterator& ValueIter() const { return myCur; } + const typename Container::iterator& ValueIter() const noexcept { return myCur; } - typename Container::iterator& ChangeValueIter() { return myCur; } + typename Container::iterator& ChangeValueIter() noexcept { return myCur; } - const typename Container::iterator& EndIter() const { return myLast; } + const typename Container::iterator& EndIter() const noexcept { return myLast; } - typename Container::iterator& ChangeEndIter() { return myLast; } + typename Container::iterator& ChangeEndIter() noexcept { return myLast; } - virtual void Next() { ++(myCur); } + virtual void Next() noexcept { ++(myCur); } const typename Container::const_reference Value() const { return *myCur; } const typename Container::reference ChangeValue() { return *myCur; } - bool operator==(const NCollection_Iterator& theOther) + bool operator==(const NCollection_Iterator& theOther) noexcept { return myLast == theOther.myLast && myCur == theOther.myCur; } - bool operator!=(const NCollection_Iterator& theOther) + bool operator!=(const NCollection_Iterator& theOther) noexcept { return myLast != theOther.myLast || myCur != theOther.myCur; } - NCollection_Iterator& operator=(const NCollection_Iterator& theOther) + NCollection_Iterator& operator=(const NCollection_Iterator& theOther) noexcept { if (this != &theOther) { @@ -107,7 +107,7 @@ public: return *this; } - NCollection_Iterator& operator=(NCollection_Iterator&& theOther) + NCollection_Iterator& operator=(NCollection_Iterator&& theOther) noexcept { if (this != &theOther) { diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_List.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_List.hxx index da854fb2c6..3ee27ba5a8 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_List.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_List.hxx @@ -45,16 +45,16 @@ public: const_iterator; //! Returns an iterator pointing to the first element in the list. - iterator begin() const { return Iterator(*this); } + iterator begin() const noexcept { return Iterator(*this); } //! Returns an iterator referring to the past-the-end element in the list. - iterator end() const { return Iterator(); } + iterator end() const noexcept { return Iterator(); } //! Returns a const iterator pointing to the first element in the list. - const_iterator cbegin() const { return Iterator(*this); } + const_iterator cbegin() const noexcept { return Iterator(*this); } //! Returns a const iterator referring to the past-the-end element in the list. - const_iterator cend() const { return Iterator(); } + const_iterator cend() const noexcept { return Iterator(); } public: // ---------- PUBLIC METHODS ------------ @@ -86,7 +86,7 @@ public: } //! Size - Number of items - Standard_Integer Size(void) const { return Extent(); } + Standard_Integer Size(void) const noexcept { return Extent(); } //! Replace this list by the items of another list (theOther parameter). //! This method does not change the internal allocator. diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_ListNode.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_ListNode.hxx index b1d7c28f48..ea258b89c5 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_ListNode.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_ListNode.hxx @@ -30,23 +30,23 @@ public: DEFINE_NCOLLECTION_ALLOC public: //! The only constructor - NCollection_ListNode(NCollection_ListNode* theNext) + NCollection_ListNode(NCollection_ListNode* theNext) noexcept : myNext(theNext) { } //! Next pointer access - NCollection_ListNode*& Next(void) { return myNext; } + NCollection_ListNode*& Next(void) noexcept { return myNext; } //! Next pointer const access - NCollection_ListNode* Next(void) const { return myNext; } + NCollection_ListNode* Next(void) const noexcept { return myNext; } private: //! operator= - forbidden - NCollection_ListNode& operator=(const NCollection_ListNode&); + NCollection_ListNode& operator=(const NCollection_ListNode&) = delete; //! copy constructor - forbidden - NCollection_ListNode(const NCollection_ListNode&); + NCollection_ListNode(const NCollection_ListNode&) = delete; private: NCollection_ListNode* myNext; //!< Pointer to the next node diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_LocalArray.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_LocalArray.hxx index 90a612b988..07890f8f24 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_LocalArray.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_LocalArray.hxx @@ -30,7 +30,7 @@ public: Allocate(theSize); } - NCollection_LocalArray() + NCollection_LocalArray() noexcept : myPtr(myBuffer), mySize(0) { @@ -49,9 +49,9 @@ public: mySize = theSize; } - size_t Size() const { return mySize; } + size_t Size() const noexcept { return mySize; } - operator theItem*() const { return myPtr; } + operator theItem*() const noexcept { return myPtr; } private: NCollection_LocalArray(const NCollection_LocalArray&); diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Map.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Map.hxx index 89dcb80a18..0d042d47ef 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Map.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Map.hxx @@ -79,7 +79,7 @@ public: } //! Key - const TheKeyType& Key(void) { return this->Value(); } + const TheKeyType& Key(void) noexcept { return this->Value(); } }; public: @@ -100,10 +100,10 @@ public: } //! Query if the end of collection is reached by iterator - Standard_Boolean More(void) const { return PMore(); } + Standard_Boolean More(void) const noexcept { return PMore(); } //! Make a step along the collection - void Next(void) { PNext(); } + void Next(void) noexcept { PNext(); } //! Value inquiry const TheKeyType& Value(void) const @@ -125,10 +125,10 @@ public: const_iterator; //! Returns a const iterator pointing to the first element in the map. - const_iterator cbegin() const { return Iterator(*this); } + const_iterator cbegin() const noexcept { return Iterator(*this); } //! Returns a const iterator referring to the past-the-end element in the map. - const_iterator cend() const { return Iterator(); } + const_iterator cend() const noexcept { return Iterator(); } public: // ---------- PUBLIC METHODS ------------ @@ -166,7 +166,7 @@ public: //! Exchange the content of two maps without re-allocations. //! Notice that allocators will be swapped as well! - void Exchange(NCollection_Map& theOther) { this->exchangeMapsData(theOther); } + void Exchange(NCollection_Map& theOther) noexcept { this->exchangeMapsData(theOther); } //! Assign. //! This method does not change the internal allocator. @@ -355,7 +355,7 @@ public: virtual ~NCollection_Map(void) { Clear(true); } //! Size - Standard_Integer Size(void) const { return Extent(); } + Standard_Integer Size(void) const noexcept { return Extent(); } public: //! Checks if two maps contain exactly the same keys. diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Mat3.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Mat3.hxx index 55a0e8ecde..f9335342a4 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Mat3.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Mat3.hxx @@ -24,10 +24,10 @@ class NCollection_Mat3 { public: //! Return identity matrix. - static NCollection_Mat3 Identity() { return NCollection_Mat3(); } + static constexpr NCollection_Mat3 Identity() { return NCollection_Mat3(); } //! Return zero matrix. - static NCollection_Mat3 Zero() + static constexpr NCollection_Mat3 Zero() { NCollection_Mat3 aMat; aMat.InitZero(); @@ -36,7 +36,7 @@ public: public: //! Empty constructor for identity matrix. - NCollection_Mat3() { InitIdentity(); } + constexpr NCollection_Mat3() { InitIdentity(); } //! Conversion constructor (explicitly converts some 3x3 matrix with other element type //! to a new 3x3 matrix with the element type Element_t, @@ -44,7 +44,7 @@ public: //! @tparam OtherElement_t the element type of the other 3x3 matrix theOtherVec3 //! @param theOtherMat3 the 3x3 matrix that needs to be converted template - explicit NCollection_Mat3(const NCollection_Mat3& theOtherMat3) + explicit constexpr NCollection_Mat3(const NCollection_Mat3& theOtherMat3) noexcept { ConvertFrom(theOtherMat3); } @@ -53,7 +53,7 @@ public: //! @param[in] theRow the row.to address. //! @param[in] theCol the column to address. //! @return the value of the addressed element. - Element_t GetValue(const size_t theRow, const size_t theCol) const + constexpr Element_t GetValue(const size_t theRow, const size_t theCol) const noexcept { return myMat[theCol * 3 + theRow]; } @@ -62,7 +62,7 @@ public: //! @param[in] theRow the row.to access. //! @param[in] theCol the column to access. //! @return reference on the matrix element. - Element_t& ChangeValue(const size_t theRow, const size_t theCol) + constexpr Element_t& ChangeValue(const size_t theRow, const size_t theCol) noexcept { return myMat[theCol * 3 + theRow]; } @@ -71,25 +71,27 @@ public: //! @param[in] theRow the row to change. //! @param[in] theCol the column to change. //! @param[in] theValue the value to set.s - void SetValue(const size_t theRow, const size_t theCol, const Element_t theValue) + constexpr void SetValue(const size_t theRow, + const size_t theCol, + const Element_t theValue) noexcept { myMat[theCol * 3 + theRow] = theValue; } //! Return value. - Element_t& operator()(const size_t theRow, const size_t theCol) + constexpr Element_t& operator()(const size_t theRow, const size_t theCol) noexcept { return ChangeValue(theRow, theCol); } //! Return value. - Element_t operator()(const size_t theRow, const size_t theCol) const + constexpr Element_t operator()(const size_t theRow, const size_t theCol) const noexcept { return GetValue(theRow, theCol); } //! Return the row. - NCollection_Vec3 GetRow(const size_t theRow) const + constexpr NCollection_Vec3 GetRow(const size_t theRow) const noexcept { return NCollection_Vec3(GetValue(theRow, 0), GetValue(theRow, 1), @@ -99,7 +101,7 @@ public: //! Change first 3 row values by the passed vector. //! @param[in] theRow the row to change. //! @param[in] theVec the vector of values. - void SetRow(const size_t theRow, const NCollection_Vec3& theVec) + constexpr void SetRow(const size_t theRow, const NCollection_Vec3& theVec) noexcept { SetValue(theRow, 0, theVec.x()); SetValue(theRow, 1, theVec.y()); @@ -107,7 +109,7 @@ public: } //! Return the column. - NCollection_Vec3 GetColumn(const size_t theCol) const + constexpr NCollection_Vec3 GetColumn(const size_t theCol) const noexcept { return NCollection_Vec3(GetValue(0, theCol), GetValue(1, theCol), @@ -117,7 +119,7 @@ public: //! Change first 3 column values by the passed vector. //! @param[in] theCol the column to change. //! @param[in] theVec the vector of values. - void SetColumn(const size_t theCol, const NCollection_Vec3& theVec) + constexpr void SetColumn(const size_t theCol, const NCollection_Vec3& theVec) noexcept { SetValue(0, theCol, theVec.x()); SetValue(1, theCol, theVec.y()); @@ -126,14 +128,14 @@ public: //! Get vector of diagonal elements. //! @return vector of diagonal elements. - NCollection_Vec3 GetDiagonal() const + constexpr NCollection_Vec3 GetDiagonal() const noexcept { return NCollection_Vec3(GetValue(0, 0), GetValue(1, 1), GetValue(2, 2)); } //! Change first 3 elements of the diagonal matrix. //! @param theVec the vector of values. - void SetDiagonal(const NCollection_Vec3& theVec) + constexpr void SetDiagonal(const NCollection_Vec3& theVec) noexcept { SetValue(0, 0, theVec.x()); SetValue(1, 1, theVec.y()); @@ -141,41 +143,84 @@ public: } //! Initialize the zero matrix. - void InitZero() { std::memcpy(this, MyZeroArray, sizeof(NCollection_Mat3)); } + constexpr void InitZero() noexcept + { + for (int i = 0; i < 9; ++i) + { + myMat[i] = MyZeroArray[i]; + } + } //! Checks the matrix for zero (without tolerance). - bool IsZero() const { return std::memcmp(this, MyZeroArray, sizeof(NCollection_Mat3)) == 0; } + constexpr bool IsZero() const noexcept + { + for (int i = 0; i < 9; ++i) + { + if (myMat[i] != MyZeroArray[i]) + { + return false; + } + } + return true; + } //! Initialize the identity matrix. - void InitIdentity() { std::memcpy(this, MyIdentityArray, sizeof(NCollection_Mat3)); } + constexpr void InitIdentity() noexcept + { + for (int i = 0; i < 9; ++i) + { + myMat[i] = MyIdentityArray[i]; + } + } //! Checks the matrix for identity (without tolerance). - bool IsIdentity() const + constexpr bool IsIdentity() const noexcept { - return std::memcmp(this, MyIdentityArray, sizeof(NCollection_Mat3)) == 0; + for (int i = 0; i < 9; ++i) + { + if (myMat[i] != MyIdentityArray[i]) + { + return false; + } + } + return true; } //! Check this matrix for equality with another matrix (without tolerance!). - bool IsEqual(const NCollection_Mat3& theOther) const + constexpr bool IsEqual(const NCollection_Mat3& theOther) const noexcept { - return std::memcmp(this, &theOther, sizeof(NCollection_Mat3)) == 0; + for (int i = 0; i < 9; ++i) + { + if (myMat[i] != theOther.myMat[i]) + { + return false; + } + } + return true; } //! Comparison operator. - bool operator==(const NCollection_Mat3& theMat) const { return IsEqual(theMat); } + constexpr bool operator==(const NCollection_Mat3& theMat) const noexcept + { + return IsEqual(theMat); + } //! Check this vector with another vector for non-equality (without tolerance!). - bool operator!=(const NCollection_Mat3& theOther) const { return !IsEqual(theOther); } + constexpr bool operator!=(const NCollection_Mat3& theOther) const noexcept + { + return !IsEqual(theOther); + } //! Raw access to the data (for OpenGL exchange). //! the data is returned in column-major order. - const Element_t* GetData() const { return myMat; } + constexpr const Element_t* GetData() const noexcept { return myMat; } - Element_t* ChangeData() { return myMat; } + constexpr Element_t* ChangeData() noexcept { return myMat; } //! Multiply by the vector (M * V). //! @param[in] theVec the vector to multiply. - NCollection_Vec3 operator*(const NCollection_Vec3& theVec) const + constexpr NCollection_Vec3 operator*( + const NCollection_Vec3& theVec) const noexcept { return NCollection_Vec3( GetValue(0, 0) * theVec.x() + GetValue(0, 1) * theVec.y() + GetValue(0, 2) * theVec.z(), @@ -186,15 +231,15 @@ public: //! Compute matrix multiplication product: A * B. //! @param[in] theMatA the matrix "A". //! @param[in] theMatB the matrix "B". - static NCollection_Mat3 Multiply(const NCollection_Mat3& theMatA, const NCollection_Mat3& theMatB) + static constexpr NCollection_Mat3 Multiply(const NCollection_Mat3& theMatA, + const NCollection_Mat3& theMatB) noexcept { NCollection_Mat3 aMatRes; - size_t aInputElem; for (size_t aResElem = 0; aResElem < 9; ++aResElem) { aMatRes.myMat[aResElem] = (Element_t)0; - for (aInputElem = 0; aInputElem < 3; ++aInputElem) + for (size_t aInputElem = 0; aInputElem < 3; ++aInputElem) { aMatRes.myMat[aResElem] += theMatA.GetValue(aResElem % 3, aInputElem) * theMatB.GetValue(aInputElem, aResElem / 3); @@ -206,11 +251,14 @@ public: //! Compute matrix multiplication. //! @param[in] theMat the matrix to multiply. - void Multiply(const NCollection_Mat3& theMat) { *this = Multiply(*this, theMat); } + constexpr void Multiply(const NCollection_Mat3& theMat) noexcept + { + *this = Multiply(*this, theMat); + } //! Multiply by the another matrix. //! @param[in] theMat the other matrix. - NCollection_Mat3& operator*=(const NCollection_Mat3& theMat) + constexpr NCollection_Mat3& operator*=(const NCollection_Mat3& theMat) noexcept { Multiply(theMat); return *this; @@ -219,7 +267,8 @@ public: //! Compute matrix multiplication product. //! @param[in] theMat the other matrix. //! @return result of multiplication. - Standard_NODISCARD NCollection_Mat3 operator*(const NCollection_Mat3& theMat) const + Standard_NODISCARD constexpr NCollection_Mat3 operator*( + const NCollection_Mat3& theMat) const noexcept { return Multiplied(theMat); } @@ -227,7 +276,8 @@ public: //! Compute matrix multiplication product. //! @param[in] theMat the other matrix. //! @return result of multiplication. - Standard_NODISCARD NCollection_Mat3 Multiplied(const NCollection_Mat3& theMat) const + Standard_NODISCARD constexpr NCollection_Mat3 Multiplied( + const NCollection_Mat3& theMat) const noexcept { NCollection_Mat3 aTempMat(*this); aTempMat *= theMat; @@ -236,7 +286,7 @@ public: //! Compute per-component multiplication. //! @param[in] theFactor the scale factor. - void Multiply(const Element_t theFactor) + constexpr void Multiply(const Element_t theFactor) noexcept { for (size_t i = 0; i < 9; ++i) { @@ -246,7 +296,7 @@ public: //! Compute per-element multiplication. //! @param[in] theFactor the scale factor. - NCollection_Mat3& operator*=(const Element_t theFactor) + constexpr NCollection_Mat3& operator*=(const Element_t theFactor) noexcept { Multiply(theFactor); return *this; @@ -255,7 +305,7 @@ public: //! Compute per-element multiplication. //! @param[in] theFactor the scale factor. //! @return the result of multiplication. - Standard_NODISCARD NCollection_Mat3 operator*(const Element_t theFactor) const + Standard_NODISCARD constexpr NCollection_Mat3 operator*(const Element_t theFactor) const noexcept { return Multiplied(theFactor); } @@ -263,7 +313,7 @@ public: //! Compute per-element multiplication. //! @param[in] theFactor the scale factor. //! @return the result of multiplication. - Standard_NODISCARD NCollection_Mat3 Multiplied(const Element_t theFactor) const + Standard_NODISCARD constexpr NCollection_Mat3 Multiplied(const Element_t theFactor) const noexcept { NCollection_Mat3 aTempMat(*this); aTempMat *= theFactor; @@ -272,7 +322,7 @@ public: //! Compute per-component division. //! @param[in] theFactor the scale factor. - void Divide(const Element_t theFactor) + constexpr void Divide(const Element_t theFactor) { for (size_t i = 0; i < 9; ++i) { @@ -282,14 +332,14 @@ public: //! Per-component division. //! @param[in] theScalar the scale factor. - NCollection_Mat3& operator/=(const Element_t theScalar) + constexpr NCollection_Mat3& operator/=(const Element_t theScalar) { Divide(theScalar); return *this; } //! Divides all the coefficients of the matrix by scalar. - Standard_NODISCARD NCollection_Mat3 Divided(const Element_t theScalar) const + Standard_NODISCARD constexpr NCollection_Mat3 Divided(const Element_t theScalar) const { NCollection_Mat3 aTempMat(*this); aTempMat /= theScalar; @@ -297,13 +347,13 @@ public: } //! Divides all the coefficients of the matrix by scalar. - Standard_NODISCARD NCollection_Mat3 operator/(const Element_t theScalar) const + Standard_NODISCARD constexpr NCollection_Mat3 operator/(const Element_t theScalar) const { return Divided(theScalar); } //! Per-component addition of another matrix. - void Add(const NCollection_Mat3& theMat) + constexpr void Add(const NCollection_Mat3& theMat) noexcept { for (size_t i = 0; i < 9; ++i) { @@ -312,14 +362,14 @@ public: } //! Per-component addition of another matrix. - NCollection_Mat3& operator+=(const NCollection_Mat3& theMat) + constexpr NCollection_Mat3& operator+=(const NCollection_Mat3& theMat) noexcept { Add(theMat); return *this; } //! Per-component subtraction of another matrix. - void Subtract(const NCollection_Mat3& theMat) + constexpr void Subtract(const NCollection_Mat3& theMat) noexcept { for (size_t i = 0; i < 9; ++i) { @@ -328,14 +378,14 @@ public: } //! Per-component subtraction of another matrix. - NCollection_Mat3& operator-=(const NCollection_Mat3& theMat) + constexpr NCollection_Mat3& operator-=(const NCollection_Mat3& theMat) noexcept { Subtract(theMat); return *this; } //! Per-component addition of another matrix. - Standard_NODISCARD NCollection_Mat3 Added(const NCollection_Mat3& theMat) const + Standard_NODISCARD constexpr NCollection_Mat3 Added(const NCollection_Mat3& theMat) const noexcept { NCollection_Mat3 aMat(*this); aMat += theMat; @@ -343,13 +393,15 @@ public: } //! Per-component addition of another matrix. - Standard_NODISCARD NCollection_Mat3 operator+(const NCollection_Mat3& theMat) const + Standard_NODISCARD constexpr NCollection_Mat3 operator+( + const NCollection_Mat3& theMat) const noexcept { return Added(theMat); } //! Per-component subtraction of another matrix. - Standard_NODISCARD NCollection_Mat3 Subtracted(const NCollection_Mat3& theMat) const + Standard_NODISCARD constexpr NCollection_Mat3 Subtracted( + const NCollection_Mat3& theMat) const noexcept { NCollection_Mat3 aMat(*this); aMat -= theMat; @@ -357,13 +409,14 @@ public: } //! Per-component subtraction of another matrix. - Standard_NODISCARD NCollection_Mat3 operator-(const NCollection_Mat3& theMat) const + Standard_NODISCARD constexpr NCollection_Mat3 operator-( + const NCollection_Mat3& theMat) const noexcept { return Subtracted(theMat); } //! Returns matrix with all components negated. - Standard_NODISCARD NCollection_Mat3 Negated() const + Standard_NODISCARD constexpr NCollection_Mat3 Negated() const noexcept { NCollection_Mat3 aMat; for (size_t i = 0; i < 9; ++i) @@ -374,11 +427,11 @@ public: } //! Returns matrix with all components negated. - Standard_NODISCARD NCollection_Mat3 operator-() const { return Negated(); } + Standard_NODISCARD constexpr NCollection_Mat3 operator-() const noexcept { return Negated(); } //! Transpose the matrix. //! @return transposed copy of the matrix. - Standard_NODISCARD NCollection_Mat3 Transposed() const + Standard_NODISCARD constexpr NCollection_Mat3 Transposed() const noexcept { NCollection_Mat3 aTempMat; aTempMat.SetRow(0, GetColumn(0)); @@ -388,10 +441,10 @@ public: } //! Transpose the matrix. - void Transpose() { *this = Transposed(); } + constexpr void Transpose() noexcept { *this = Transposed(); } //! Return determinant of the matrix. - Element_t Determinant() const + constexpr Element_t Determinant() const noexcept { return (GetValue(0, 0) * GetValue(1, 1) * GetValue(2, 2) + GetValue(0, 1) * GetValue(1, 2) * GetValue(2, 0) @@ -402,7 +455,7 @@ public: } //! Return adjoint (adjugate matrix, e.g. conjugate transpose). - Standard_NODISCARD NCollection_Mat3 Adjoint() const + Standard_NODISCARD constexpr NCollection_Mat3 Adjoint() const noexcept { NCollection_Mat3 aMat; aMat.SetRow(0, NCollection_Vec3::Cross(GetRow(1), GetRow(2))); @@ -451,7 +504,7 @@ public: //! Take values from NCollection_Mat3 with a different element type with type conversion. template - void ConvertFrom(const NCollection_Mat3& theFrom) + constexpr void ConvertFrom(const NCollection_Mat3& theFrom) noexcept { for (int anIdx = 0; anIdx < 9; ++anIdx) { @@ -460,13 +513,13 @@ public: } //! Maps plain C array to matrix type. - static NCollection_Mat3& Map(Element_t* theData) + static NCollection_Mat3& Map(Element_t* theData) noexcept { return *reinterpret_cast*>(theData); } //! Maps plain C array to matrix type. - static const NCollection_Mat3& Map(const Element_t* theData) + static const NCollection_Mat3& Map(const Element_t* theData) noexcept { return *reinterpret_cast*>(theData); } @@ -492,20 +545,14 @@ private: Element_t myMat[9]; private: - static const Element_t MyZeroArray[9]; - static const Element_t MyIdentityArray[9]; + static constexpr Element_t MyZeroArray[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; + static constexpr Element_t MyIdentityArray[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; // All instantiations are friend to each other template friend class NCollection_Mat3; }; -template -const Element_t NCollection_Mat3::MyZeroArray[] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; - -template -const Element_t NCollection_Mat3::MyIdentityArray[] = {1, 0, 0, 0, 1, 0, 0, 0, 1}; - #if defined(_MSC_VER) && (_MSC_VER >= 1900) #include diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Mat4.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Mat4.hxx index f49a76d67e..55030b5cf1 100755 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Mat4.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Mat4.hxx @@ -29,17 +29,17 @@ class NCollection_Mat4 public: //! Get number of rows. //! @return number of rows. - static size_t Rows() { return 4; } + static constexpr size_t Rows() noexcept { return 4; } //! Get number of columns. //! @return number of columns. - static size_t Cols() { return 4; } + static constexpr size_t Cols() noexcept { return 4; } //! Return identity matrix. - static NCollection_Mat4 Identity() { return NCollection_Mat4(); } + static constexpr NCollection_Mat4 Identity() { return NCollection_Mat4(); } //! Return zero matrix. - static NCollection_Mat4 Zero() + static constexpr NCollection_Mat4 Zero() { NCollection_Mat4 aMat; aMat.InitZero(); @@ -49,7 +49,7 @@ public: public: //! Empty constructor. //! Construct the identity matrix. - NCollection_Mat4() { InitIdentity(); } + constexpr NCollection_Mat4() { InitIdentity(); } //! Conversion constructor (explicitly converts some 4 x 4 matrix with other element type //! to a new 4 x 4 matrix with the element type Element_t, @@ -57,7 +57,7 @@ public: //! @tparam OtherElement_t the element type of the other 4 x 4 matrix theOtherVec4 //! @param theOtherMat4 the 4 x 4 matrix that needs to be converted template - explicit NCollection_Mat4(const NCollection_Mat4& theOtherMat4) + explicit constexpr NCollection_Mat4(const NCollection_Mat4& theOtherMat4) noexcept { ConvertFrom(theOtherMat4); } @@ -66,7 +66,7 @@ public: //! @param[in] theRow the row to address. //! @param[in] theCol the column to address. //! @return the value of the addressed element. - Element_t GetValue(const size_t theRow, const size_t theCol) const + constexpr Element_t GetValue(const size_t theRow, const size_t theCol) const noexcept { return myMat[theCol * 4 + theRow]; } @@ -75,7 +75,7 @@ public: //! @param[in] theRow the row to access. //! @param[in] theCol the column to access. //! @return reference on the matrix element. - Element_t& ChangeValue(const size_t theRow, const size_t theCol) + constexpr Element_t& ChangeValue(const size_t theRow, const size_t theCol) noexcept { return myMat[theCol * 4 + theRow]; } @@ -84,19 +84,21 @@ public: //! @param[in] theRow the row to change. //! @param[in] theCol the column to change. //! @param[in] theValue the value to set. - void SetValue(const size_t theRow, const size_t theCol, const Element_t theValue) + constexpr void SetValue(const size_t theRow, + const size_t theCol, + const Element_t theValue) noexcept { myMat[theCol * 4 + theRow] = theValue; } //! Return value. - Element_t& operator()(const size_t theRow, const size_t theCol) + constexpr Element_t& operator()(const size_t theRow, const size_t theCol) noexcept { return ChangeValue(theRow, theCol); } //! Return value. - Element_t operator()(const size_t theRow, const size_t theCol) const + constexpr Element_t operator()(const size_t theRow, const size_t theCol) const noexcept { return GetValue(theRow, theCol); } @@ -104,7 +106,7 @@ public: //! Get vector of elements for the specified row. //! @param[in] theRow the row to access. //! @return vector of elements. - NCollection_Vec4 GetRow(const size_t theRow) const + constexpr NCollection_Vec4 GetRow(const size_t theRow) const noexcept { return NCollection_Vec4(GetValue(theRow, 0), GetValue(theRow, 1), @@ -115,7 +117,7 @@ public: //! Change first 3 row values by the passed vector. //! @param[in] theRow the row to change. //! @param[in] theVec the vector of values. - void SetRow(const size_t theRow, const NCollection_Vec3& theVec) + constexpr void SetRow(const size_t theRow, const NCollection_Vec3& theVec) noexcept { SetValue(theRow, 0, theVec.x()); SetValue(theRow, 1, theVec.y()); @@ -125,7 +127,7 @@ public: //! Set row values by the passed 4 element vector. //! @param[in] theRow the row to change. //! @param[in] theVec the vector of values. - void SetRow(const size_t theRow, const NCollection_Vec4& theVec) + constexpr void SetRow(const size_t theRow, const NCollection_Vec4& theVec) noexcept { SetValue(theRow, 0, theVec.x()); SetValue(theRow, 1, theVec.y()); @@ -136,7 +138,7 @@ public: //! Get vector of elements for the specified column. //! @param[in] theCol the column to access. //! @return vector of elements. - NCollection_Vec4 GetColumn(const size_t theCol) const + constexpr NCollection_Vec4 GetColumn(const size_t theCol) const noexcept { return NCollection_Vec4(GetValue(0, theCol), GetValue(1, theCol), @@ -147,7 +149,7 @@ public: //! Change first 3 column values by the passed vector. //! @param[in] theCol the column to change. //! @param[in] theVec the vector of values. - void SetColumn(const size_t theCol, const NCollection_Vec3& theVec) + constexpr void SetColumn(const size_t theCol, const NCollection_Vec3& theVec) noexcept { SetValue(0, theCol, theVec.x()); SetValue(1, theCol, theVec.y()); @@ -157,7 +159,7 @@ public: //! Set column values by the passed 4 element vector. //! @param[in] theCol the column to change. //! @param[in] theVec the vector of values. - void SetColumn(const size_t theCol, const NCollection_Vec4& theVec) + constexpr void SetColumn(const size_t theCol, const NCollection_Vec4& theVec) noexcept { SetValue(0, theCol, theVec.x()); SetValue(1, theCol, theVec.y()); @@ -167,7 +169,7 @@ public: //! Get vector of diagonal elements. //! @return vector of diagonal elements. - NCollection_Vec4 GetDiagonal() const + constexpr NCollection_Vec4 GetDiagonal() const noexcept { return NCollection_Vec4(GetValue(0, 0), GetValue(1, 1), @@ -177,7 +179,7 @@ public: //! Change first 3 elements of the diagonal matrix. //! @param theVec the vector of values. - void SetDiagonal(const NCollection_Vec3& theVec) + constexpr void SetDiagonal(const NCollection_Vec3& theVec) noexcept { SetValue(0, 0, theVec.x()); SetValue(1, 1, theVec.y()); @@ -186,7 +188,7 @@ public: //! Set diagonal elements of the matrix by the passed vector. //! @param[in] theVec the vector of values. - void SetDiagonal(const NCollection_Vec4& theVec) + constexpr void SetDiagonal(const NCollection_Vec4& theVec) noexcept { SetValue(0, 0, theVec.x()); SetValue(1, 1, theVec.y()); @@ -195,7 +197,7 @@ public: } //! Return 3x3 sub-matrix. - NCollection_Mat3 GetMat3() const + constexpr NCollection_Mat3 GetMat3() const noexcept { NCollection_Mat3 aMat; aMat.SetColumn(0, GetColumn(0).xyz()); @@ -205,41 +207,84 @@ public: } //! Initialize the zero matrix. - void InitZero() { std::memcpy(this, MyZeroArray, sizeof(NCollection_Mat4)); } + constexpr void InitZero() noexcept + { + for (int i = 0; i < 16; ++i) + { + myMat[i] = MyZeroArray[i]; + } + } //! Checks the matrix for zero (without tolerance). - bool IsZero() const { return std::memcmp(this, MyZeroArray, sizeof(NCollection_Mat4)) == 0; } + constexpr bool IsZero() const noexcept + { + for (int i = 0; i < 16; ++i) + { + if (myMat[i] != MyZeroArray[i]) + { + return false; + } + } + return true; + } //! Initialize the identity matrix. - void InitIdentity() { std::memcpy(this, MyIdentityArray, sizeof(NCollection_Mat4)); } + constexpr void InitIdentity() noexcept + { + for (int i = 0; i < 16; ++i) + { + myMat[i] = MyIdentityArray[i]; + } + } //! Checks the matrix for identity (without tolerance). - bool IsIdentity() const + constexpr bool IsIdentity() const noexcept { - return std::memcmp(this, MyIdentityArray, sizeof(NCollection_Mat4)) == 0; + for (int i = 0; i < 16; ++i) + { + if (myMat[i] != MyIdentityArray[i]) + { + return false; + } + } + return true; } //! Check this matrix for equality with another matrix (without tolerance!). - bool IsEqual(const NCollection_Mat4& theOther) const + constexpr bool IsEqual(const NCollection_Mat4& theOther) const noexcept { - return std::memcmp(this, &theOther, sizeof(NCollection_Mat4)) == 0; + for (int i = 0; i < 16; ++i) + { + if (myMat[i] != theOther.myMat[i]) + { + return false; + } + } + return true; } //! Check this matrix for equality with another matrix (without tolerance!). - bool operator==(const NCollection_Mat4& theOther) const { return IsEqual(theOther); } + constexpr bool operator==(const NCollection_Mat4& theOther) const noexcept + { + return IsEqual(theOther); + } //! Check this matrix for non-equality with another matrix (without tolerance!). - bool operator!=(const NCollection_Mat4& theOther) const { return !IsEqual(theOther); } + constexpr bool operator!=(const NCollection_Mat4& theOther) const noexcept + { + return !IsEqual(theOther); + } //! Raw access to the data (for OpenGL exchange); //! the data is returned in column-major order. - const Element_t* GetData() const { return myMat; } + constexpr const Element_t* GetData() const noexcept { return myMat; } - Element_t* ChangeData() { return myMat; } + constexpr Element_t* ChangeData() noexcept { return myMat; } //! Multiply by the vector (M * V). //! @param[in] theVec the vector to multiply. - NCollection_Vec4 operator*(const NCollection_Vec4& theVec) const + constexpr NCollection_Vec4 operator*( + const NCollection_Vec4& theVec) const noexcept { return NCollection_Vec4( GetValue(0, 0) * theVec.x() + GetValue(0, 1) * theVec.y() + GetValue(0, 2) * theVec.z() @@ -255,15 +300,15 @@ public: //! Compute matrix multiplication product: A * B. //! @param[in] theMatA the matrix "A". //! @param[in] theMatB the matrix "B". - static NCollection_Mat4 Multiply(const NCollection_Mat4& theMatA, const NCollection_Mat4& theMatB) + static constexpr NCollection_Mat4 Multiply(const NCollection_Mat4& theMatA, + const NCollection_Mat4& theMatB) noexcept { NCollection_Mat4 aMatRes; - size_t aInputElem; for (size_t aResElem = 0; aResElem < 16; ++aResElem) { aMatRes.myMat[aResElem] = (Element_t)0; - for (aInputElem = 0; aInputElem < 4; ++aInputElem) + for (size_t aInputElem = 0; aInputElem < 4; ++aInputElem) { aMatRes.myMat[aResElem] += theMatA.GetValue(aResElem % 4, aInputElem) * theMatB.GetValue(aInputElem, aResElem / 4); @@ -275,11 +320,14 @@ public: //! Compute matrix multiplication. //! @param[in] theMat the matrix to multiply. - void Multiply(const NCollection_Mat4& theMat) { *this = Multiply(*this, theMat); } + constexpr void Multiply(const NCollection_Mat4& theMat) noexcept + { + *this = Multiply(*this, theMat); + } //! Multiply by the another matrix. //! @param[in] theMat the other matrix. - NCollection_Mat4& operator*=(const NCollection_Mat4& theMat) + constexpr NCollection_Mat4& operator*=(const NCollection_Mat4& theMat) noexcept { Multiply(theMat); return *this; @@ -288,7 +336,8 @@ public: //! Compute matrix multiplication product. //! @param[in] theMat the other matrix. //! @return result of multiplication. - Standard_NODISCARD NCollection_Mat4 operator*(const NCollection_Mat4& theMat) const + Standard_NODISCARD constexpr NCollection_Mat4 operator*( + const NCollection_Mat4& theMat) const noexcept { return Multiplied(theMat); } @@ -296,7 +345,8 @@ public: //! Compute matrix multiplication product. //! @param[in] theMat the other matrix. //! @return result of multiplication. - Standard_NODISCARD NCollection_Mat4 Multiplied(const NCollection_Mat4& theMat) const + Standard_NODISCARD constexpr NCollection_Mat4 Multiplied( + const NCollection_Mat4& theMat) const noexcept { NCollection_Mat4 aTempMat(*this); aTempMat *= theMat; @@ -305,7 +355,7 @@ public: //! Compute per-component multiplication. //! @param[in] theFactor the scale factor. - void Multiply(const Element_t theFactor) + constexpr void Multiply(const Element_t theFactor) noexcept { for (size_t i = 0; i < 16; ++i) { @@ -315,7 +365,7 @@ public: //! Compute per-element multiplication. //! @param[in] theFactor the scale factor. - NCollection_Mat4& operator*=(const Element_t theFactor) + constexpr NCollection_Mat4& operator*=(const Element_t theFactor) noexcept { Multiply(theFactor); return *this; @@ -324,7 +374,7 @@ public: //! Compute per-element multiplication. //! @param[in] theFactor the scale factor. //! @return the result of multiplication. - Standard_NODISCARD NCollection_Mat4 operator*(const Element_t theFactor) const + Standard_NODISCARD constexpr NCollection_Mat4 operator*(const Element_t theFactor) const noexcept { return Multiplied(theFactor); } @@ -332,7 +382,7 @@ public: //! Compute per-element multiplication. //! @param[in] theFactor the scale factor. //! @return the result of multiplication. - Standard_NODISCARD NCollection_Mat4 Multiplied(const Element_t theFactor) const + Standard_NODISCARD constexpr NCollection_Mat4 Multiplied(const Element_t theFactor) const noexcept { NCollection_Mat4 aTempMat(*this); aTempMat *= theFactor; @@ -341,7 +391,7 @@ public: //! Compute per-component division. //! @param[in] theFactor the scale factor. - void Divide(const Element_t theFactor) + constexpr void Divide(const Element_t theFactor) { for (size_t i = 0; i < 16; ++i) { @@ -351,14 +401,14 @@ public: //! Per-component division. //! @param[in] theScalar the scale factor. - NCollection_Mat4& operator/=(const Element_t theScalar) + constexpr NCollection_Mat4& operator/=(const Element_t theScalar) { Divide(theScalar); return *this; } //! Divides all the coefficients of the matrix by scalar. - Standard_NODISCARD NCollection_Mat4 Divided(const Element_t theScalar) const + Standard_NODISCARD constexpr NCollection_Mat4 Divided(const Element_t theScalar) const { NCollection_Mat4 aTempMat(*this); aTempMat /= theScalar; @@ -366,13 +416,13 @@ public: } //! Divides all the coefficients of the matrix by scalar. - Standard_NODISCARD NCollection_Mat4 operator/(const Element_t theScalar) const + Standard_NODISCARD constexpr NCollection_Mat4 operator/(const Element_t theScalar) const { return Divided(theScalar); } //! Per-component addition of another matrix. - void Add(const NCollection_Mat4& theMat) + constexpr void Add(const NCollection_Mat4& theMat) noexcept { for (size_t i = 0; i < 16; ++i) { @@ -381,14 +431,14 @@ public: } //! Per-component addition of another matrix. - NCollection_Mat4& operator+=(const NCollection_Mat4& theMat) + constexpr NCollection_Mat4& operator+=(const NCollection_Mat4& theMat) noexcept { Add(theMat); return *this; } //! Per-component subtraction of another matrix. - void Subtract(const NCollection_Mat4& theMat) + constexpr void Subtract(const NCollection_Mat4& theMat) noexcept { for (size_t i = 0; i < 16; ++i) { @@ -397,14 +447,14 @@ public: } //! Per-component subtraction of another matrix. - NCollection_Mat4& operator-=(const NCollection_Mat4& theMat) + constexpr NCollection_Mat4& operator-=(const NCollection_Mat4& theMat) noexcept { Subtract(theMat); return *this; } //! Per-component addition of another matrix. - Standard_NODISCARD NCollection_Mat4 Added(const NCollection_Mat4& theMat) const + Standard_NODISCARD constexpr NCollection_Mat4 Added(const NCollection_Mat4& theMat) const noexcept { NCollection_Mat4 aMat(*this); aMat += theMat; @@ -412,13 +462,15 @@ public: } //! Per-component addition of another matrix. - Standard_NODISCARD NCollection_Mat4 operator+(const NCollection_Mat4& theMat) const + Standard_NODISCARD constexpr NCollection_Mat4 operator+( + const NCollection_Mat4& theMat) const noexcept { return Added(theMat); } //! Per-component subtraction of another matrix. - Standard_NODISCARD NCollection_Mat4 Subtracted(const NCollection_Mat4& theMat) const + Standard_NODISCARD constexpr NCollection_Mat4 Subtracted( + const NCollection_Mat4& theMat) const noexcept { NCollection_Mat4 aMat(*this); aMat -= theMat; @@ -426,13 +478,14 @@ public: } //! Per-component subtraction of another matrix. - Standard_NODISCARD NCollection_Mat4 operator-(const NCollection_Mat4& theMat) const + Standard_NODISCARD constexpr NCollection_Mat4 operator-( + const NCollection_Mat4& theMat) const noexcept { return Subtracted(theMat); } //! Returns matrix with all components negated. - Standard_NODISCARD NCollection_Mat4 Negated() const + Standard_NODISCARD constexpr NCollection_Mat4 Negated() const noexcept { NCollection_Mat4 aMat; for (size_t i = 0; i < 16; ++i) @@ -443,11 +496,11 @@ public: } //! Returns matrix with all components negated. - Standard_NODISCARD NCollection_Mat4 operator-() const { return Negated(); } + Standard_NODISCARD constexpr NCollection_Mat4 operator-() const noexcept { return Negated(); } //! Translate the matrix on the passed vector. //! @param[in] theVec the translation vector. - void Translate(const NCollection_Vec3& theVec) + constexpr void Translate(const NCollection_Vec3& theVec) noexcept { NCollection_Mat4 aTempMat; aTempMat.SetColumn(3, theVec); @@ -456,7 +509,7 @@ public: //! Transpose the matrix. //! @return transposed copy of the matrix. - Standard_NODISCARD NCollection_Mat4 Transposed() const + Standard_NODISCARD constexpr NCollection_Mat4 Transposed() const noexcept { NCollection_Mat4 aTempMat; aTempMat.SetRow(0, GetColumn(0)); @@ -467,7 +520,7 @@ public: } //! Transpose the matrix. - void Transpose() { *this = Transposed(); } + constexpr void Transpose() noexcept { *this = Transposed(); } //! Compute inverted matrix. //! @param[out] theOutMx the inverted matrix @@ -564,7 +617,7 @@ public: } //! Return determinant of the 3x3 sub-matrix. - Element_t DeterminantMat3() const + constexpr Element_t DeterminantMat3() const noexcept { return (GetValue(0, 0) * GetValue(1, 1) * GetValue(2, 2) + GetValue(0, 1) * GetValue(1, 2) * GetValue(2, 0) @@ -575,7 +628,7 @@ public: } //! Return adjoint (adjugate matrix, e.g. conjugate transpose). - Standard_NODISCARD NCollection_Mat4 Adjoint() const + Standard_NODISCARD constexpr NCollection_Mat4 Adjoint() const noexcept { NCollection_Mat4 aMat; aMat.SetRow(0, crossVec4(GetRow(1), GetRow(2), GetRow(3))); @@ -587,7 +640,7 @@ public: //! Take values from NCollection_Mat4 with a different element type with type conversion. template - void ConvertFrom(const NCollection_Mat4& theFrom) + constexpr void ConvertFrom(const NCollection_Mat4& theFrom) noexcept { for (int anIdx = 0; anIdx < 16; ++anIdx) { @@ -597,19 +650,19 @@ public: //! Take values from NCollection_Mat4 with a different element type with type conversion. template - void Convert(const NCollection_Mat4& theFrom) + constexpr void Convert(const NCollection_Mat4& theFrom) noexcept { ConvertFrom(theFrom); } //! Maps plain C array to matrix type. - static NCollection_Mat4& Map(Element_t* theData) + static NCollection_Mat4& Map(Element_t* theData) noexcept { return *reinterpret_cast*>(theData); } //! Maps plain C array to matrix type. - static const NCollection_Mat4& Map(const Element_t* theData) + static const NCollection_Mat4& Map(const Element_t* theData) noexcept { return *reinterpret_cast*>(theData); } @@ -640,9 +693,10 @@ public: private: //! Cross-product has no direct meaning in 4D space - provided for local usage. - static NCollection_Vec4 crossVec4(const NCollection_Vec4& theA, - const NCollection_Vec4& theB, - const NCollection_Vec4& theC) + static constexpr NCollection_Vec4 crossVec4( + const NCollection_Vec4& theA, + const NCollection_Vec4& theB, + const NCollection_Vec4& theC) noexcept { const Element_t aD1 = (theB.z() * theC.w()) - (theB.w() * theC.z()); const Element_t aD2 = (theB.y() * theC.w()) - (theB.w() * theC.y()); @@ -663,22 +717,14 @@ private: Element_t myMat[16]; private: - static const Element_t MyZeroArray[16]; - static const Element_t MyIdentityArray[16]; + static constexpr Element_t MyZeroArray[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + static constexpr Element_t MyIdentityArray[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; // All instantiations are friend to each other template friend class NCollection_Mat4; }; -template -const Element_t NCollection_Mat4::MyZeroArray[] = - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -template -const Element_t NCollection_Mat4::MyIdentityArray[] = - {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; - #if defined(_MSC_VER) && (_MSC_VER >= 1900) #include diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_OccAllocator.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_OccAllocator.hxx index fb26c02b7e..fa91e507c4 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_OccAllocator.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_OccAllocator.hxx @@ -18,6 +18,7 @@ #include #include +#include //! Implements allocator requirements as defined in ISO C++ Standard 2003, section 20.1.5. /*! The allocator uses a standard OCCT mechanism for memory @@ -54,7 +55,7 @@ public: //! Constructor. //! Creates an object using the default Open CASCADE allocation mechanism, i.e., which uses //! Standard::Allocate() and Standard::Free() underneath. - NCollection_OccAllocator() + NCollection_OccAllocator() noexcept : myAllocator(nullptr) { } @@ -116,7 +117,7 @@ public: void SetAllocator(const Handle(NCollection_BaseAllocator)& theAlloc) { myAllocator = theAlloc; } - const Handle(NCollection_BaseAllocator)& Allocator() const { return myAllocator; } + const Handle(NCollection_BaseAllocator)& Allocator() const noexcept { return myAllocator; } //! Allocates memory for theSize objects. pointer allocate(size_type theSize, const void* = 0) @@ -149,15 +150,15 @@ public: } //! Returns an object address. - pointer address(reference theItem) const { return &theItem; } + pointer address(reference theItem) const noexcept { return &theItem; } //! Returns an object address. - const_pointer address(const_reference theItem) const { return &theItem; } + const_pointer address(const_reference theItem) const noexcept { return &theItem; } //! Destroys the object. //! Uses the object destructor. template - void destroy(_Uty* _Ptr) + void destroy(_Uty* _Ptr) noexcept(std::is_nothrow_destructible<_Uty>::value) { (void)_Ptr; _Ptr->~_Uty(); @@ -166,24 +167,24 @@ public: //! Estimate maximum array size size_t max_size() const noexcept { return ((size_t)(-1) / sizeof(ItemType)); } - bool operator==(const NCollection_OccAllocator& theOther) const + bool operator==(const NCollection_OccAllocator& theOther) const noexcept { return theOther.Allocator() == myAllocator; } template - bool operator==(const NCollection_OccAllocator& theOther) const + bool operator==(const NCollection_OccAllocator& theOther) const noexcept { return theOther.Allocator() == myAllocator; } - bool operator!=(const NCollection_OccAllocator& theOther) const + bool operator!=(const NCollection_OccAllocator& theOther) const noexcept { return theOther.Allocator() != myAllocator; } template - bool operator!=(const NCollection_OccAllocator& theOther) const + bool operator!=(const NCollection_OccAllocator& theOther) const noexcept { return theOther.Allocator() != myAllocator; } @@ -194,7 +195,7 @@ private: template bool operator==(const NCollection_OccAllocator& theFirst, - const NCollection_OccAllocator& theSecond) + const NCollection_OccAllocator& theSecond) noexcept { return theFirst.Allocator() == theSecond.Allocator(); } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Primes.cxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Primes.cxx index 850b06778d..b13d4bf125 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Primes.cxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Primes.cxx @@ -36,12 +36,13 @@ constexpr std::array THE_PRIME_VECTOR = { 17915905, 35831809, 71663617, 150994945, 301989889, 573308929, 1019215873, 2038431745}; } // namespace -int NCollection_Primes::NextPrimeForMap(const int theN) +int NCollection_Primes::NextPrimeForMap(const int theN) noexcept { auto aResult = std::lower_bound(THE_PRIME_VECTOR.begin(), THE_PRIME_VECTOR.end(), theN + 1); if (aResult == THE_PRIME_VECTOR.end()) { - throw Standard_OutOfRange("NCollection_Primes::NextPrimeForMap() - requested too big size"); + // Return theN + 1 if requested size exceeds the largest available prime + return theN + 1; } return *aResult; } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Primes.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Primes.hxx index fdc8360deb..95b0569bd9 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Primes.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Primes.hxx @@ -31,7 +31,8 @@ namespace NCollection_Primes { //! Returns the next prime number greater than or equal to theN. -Standard_EXPORT int NextPrimeForMap(const int theN); +//! If theN exceeds the largest available prime, returns theN + 1. +Standard_EXPORT int NextPrimeForMap(const int theN) noexcept; }; // namespace NCollection_Primes #endif // _NCollection_Primes_HeaderFile \ No newline at end of file diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Sequence.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Sequence.hxx index 47ea1499ff..b2658f8eb9 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Sequence.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Sequence.hxx @@ -54,10 +54,10 @@ public: } //! Constant value access - const TheItemType& Value() const { return myValue; } + const TheItemType& Value() const noexcept { return myValue; } //! Variable value access - TheItemType& ChangeValue() { return myValue; } + TheItemType& ChangeValue() noexcept { return myValue; } private: TheItemType myValue; @@ -78,10 +78,10 @@ public: } //! Check end - Standard_Boolean More(void) const { return (myCurrent != NULL); } + Standard_Boolean More(void) const noexcept { return (myCurrent != NULL); } //! Make step - void Next(void) + void Next(void) noexcept { if (myCurrent) { @@ -91,13 +91,13 @@ public: } //! Constant value access - const TheItemType& Value(void) const { return ((const Node*)myCurrent)->Value(); } + const TheItemType& Value(void) const noexcept { return ((const Node*)myCurrent)->Value(); } //! Variable value access - TheItemType& ChangeValue(void) const { return ((Node*)myCurrent)->ChangeValue(); } + TheItemType& ChangeValue(void) const noexcept { return ((Node*)myCurrent)->ChangeValue(); } //! Performs comparison of two iterators. - Standard_Boolean IsEqual(const Iterator& theOther) const + Standard_Boolean IsEqual(const Iterator& theOther) const noexcept { return myCurrent == theOther.myCurrent; } @@ -112,10 +112,10 @@ public: const_iterator; //! Returns an iterator pointing to the first element in the sequence. - iterator begin() const { return Iterator(*this, true); } + iterator begin() const noexcept { return Iterator(*this, true); } //! Returns an iterator referring to the past-the-end element in the sequence. - iterator end() const + iterator end() const noexcept { Iterator anIter(*this, false); anIter.Next(); @@ -123,10 +123,10 @@ public: } //! Returns a const iterator pointing to the first element in the sequence. - const_iterator cbegin() const { return Iterator(*this, true); } + const_iterator cbegin() const noexcept { return Iterator(*this, true); } //! Returns a const iterator referring to the past-the-end element in the sequence. - const_iterator cend() const + const_iterator cend() const noexcept { Iterator anIter(*this, false); anIter.Next(); @@ -163,21 +163,21 @@ public: } //! Number of items - Standard_Integer Size(void) const { return mySize; } + Standard_Integer Size(void) const noexcept { return mySize; } //! Number of items - Standard_Integer Length(void) const { return mySize; } + Standard_Integer Length(void) const noexcept { return mySize; } //! Method for consistency with other collections. //! @return Lower bound (inclusive) for iteration. - Standard_Integer Lower() const { return 1; } + static constexpr Standard_Integer Lower() noexcept { return 1; } //! Method for consistency with other collections. //! @return Upper bound (inclusive) for iteration. - Standard_Integer Upper() const { return mySize; } + Standard_Integer Upper() const noexcept { return mySize; } //! Empty query - Standard_Boolean IsEmpty(void) const { return (mySize == 0); } + Standard_Boolean IsEmpty(void) const noexcept { return (mySize == 0); } //! Reverse sequence void Reverse(void) { PReverse(); } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_SparseArray.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_SparseArray.hxx index d946ab65f4..d38da03383 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_SparseArray.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_SparseArray.hxx @@ -48,7 +48,7 @@ class NCollection_SparseArray : public NCollection_SparseArrayBase { public: //! Constructor; accepts size of blocks - explicit NCollection_SparseArray(Standard_Size theIncrement) + explicit NCollection_SparseArray(Standard_Size theIncrement) noexcept : NCollection_SparseArrayBase(sizeof(TheItemType), theIncrement) { } @@ -103,10 +103,10 @@ public: //!@{ //! Returns number of items in the array - Standard_Size Extent() const { return Size(); } + Standard_Size Extent() const noexcept { return Size(); } //! Returns True if array is empty - Standard_Boolean IsEmpty() const { return Size() == 0; } + Standard_Boolean IsEmpty() const noexcept { return Size() == 0; } //! Direct const access to the item const TheItemType& Find(const Standard_Size theIndex) const { return Value(theIndex); } @@ -156,7 +156,7 @@ public: const TheItemType& operator()(void) const { return *(const TheItemType*)this->value(); } //! Access current index with 'a-la map' interface - Standard_Size Key(void) const { return Index(); } + Standard_Size Key(void) const noexcept { return Index(); } }; /** diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_SparseArrayBase.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_SparseArrayBase.hxx index 02eca2a6c1..1c3f479ec7 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_SparseArrayBase.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_SparseArrayBase.hxx @@ -17,10 +17,9 @@ #define NCollection_SparseArrayBase_HeaderFile #include +#include #include -typedef size_t Standard_Size; - /** * Base class for NCollection_SparseArray; * provides non-template implementation of general mechanics @@ -37,7 +36,7 @@ public: Standard_EXPORT void Clear(); //! Returns number of currently contained items - Standard_Size Size() const { return mySize; } + Standard_Size Size() const noexcept { return mySize; } //! Check whether the value at given index is set Standard_EXPORT Standard_Boolean HasValue(const Standard_Size theIndex) const; @@ -72,7 +71,7 @@ private: typedef unsigned char Cell; //!< type of items used to hold bits //! Number of bits in each cell - static Standard_Size BitsPerCell() { return sizeof(Cell) * 8; } + static constexpr Standard_Size BitsPerCell() noexcept { return sizeof(Cell) * 8; } public: //! Initializes the block by pointer to block data @@ -86,7 +85,8 @@ private: } //! Compute required size for block data, in bytes - static Standard_Size Size(const Standard_Size theNbItems, const Standard_Size theItemSize) + static constexpr Standard_Size Size(const Standard_Size theNbItems, + const Standard_Size theItemSize) noexcept { return sizeof(Standard_Size) + sizeof(Cell) * ((theNbItems + BitsPerCell() - 1) / BitsPerCell()) @@ -96,7 +96,7 @@ private: //! Returns address of array from address of block static char* ToArray(const Standard_Address theAddress, const Standard_Size /*theNbItems*/, - const Standard_Size /*theItemSize*/) + const Standard_Size /*theItemSize*/) noexcept { return (char*)theAddress + sizeof(Standard_Size); } @@ -104,7 +104,7 @@ private: public: //! Set bit for i-th item; returns non-null if that bit has //! not been set previously - Cell Set(Standard_Size i) + Cell Set(Standard_Size i) noexcept { Cell* abyte = Bits + i / BitsPerCell(); Cell amask = (Cell)('\1' << (i % BitsPerCell())); @@ -114,7 +114,7 @@ private: } //! Check bit for i-th item; returns non-null if that bit is set - Cell IsSet(Standard_Size i) + Cell IsSet(Standard_Size i) noexcept { Cell* abyte = Bits + i / BitsPerCell(); Cell amask = (Cell)('\1' << (i % BitsPerCell())); @@ -123,7 +123,7 @@ private: //! Unset bit for i-th item; returns non-null if that bit //! has been set previously - Cell Unset(Standard_Size i) + Cell Unset(Standard_Size i) noexcept { Cell* abyte = Bits + i / BitsPerCell(); Cell amask = (Cell)('\1' << (i % BitsPerCell())); @@ -152,13 +152,13 @@ public: void Restart() { init(myArr); } //! Returns True if current item is available - Standard_Boolean More() const { return myHasMore; } + Standard_Boolean More() const noexcept { return myHasMore; } //! Advances to the next item Standard_EXPORT void Next(); //! Returns current index - Standard_Size Index() const { return myIBlock * myArr->myBlockSize + myInd; } + Standard_Size Index() const noexcept { return myIBlock * myArr->myBlockSize + myInd; } protected: // Methods for descendant @@ -170,7 +170,7 @@ public: Standard_EXPORT void init(const NCollection_SparseArrayBase* theArray); //! Returns address of the current item - Standard_Address value() const { return myArr->getItem(myBlock, myInd); } + Standard_Address value() const noexcept { return myArr->getItem(myBlock, myInd); } private: const NCollection_SparseArrayBase* myArr; @@ -190,7 +190,7 @@ protected: // Object life //! Constructor; initialized by size of item and of block (in items) - NCollection_SparseArrayBase(Standard_Size theItemSize, Standard_Size theBlockSize) + NCollection_SparseArrayBase(Standard_Size theItemSize, Standard_Size theBlockSize) noexcept : myItemSize(theItemSize), myBlockSize(theBlockSize), myNbBlocks(0), @@ -206,13 +206,13 @@ protected: // Data access interface for descendants //! Creates Block structure for block pointed by theAddr - Block getBlock(const Standard_Address theAddr) const + Block getBlock(const Standard_Address theAddr) const noexcept { return Block(theAddr, myBlockSize, myItemSize); } //! Find address of the item in the block by index (in the block) - Standard_Address getItem(const Block& theBlock, Standard_Size theInd) const + Standard_Address getItem(const Block& theBlock, Standard_Size theInd) const noexcept { return ((char*)theBlock.Array) + myItemSize * theInd; } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_StlIterator.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_StlIterator.hxx index 59283bb208..a7803e2696 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_StlIterator.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_StlIterator.hxx @@ -61,10 +61,10 @@ public: } //! Access to NCollection iterator instance - const BaseIterator& Iterator() const { return myIterator; } + const BaseIterator& Iterator() const noexcept { return myIterator; } //! Access to NCollection iterator instance - BaseIterator& ChangeIterator() { return myIterator; } + BaseIterator& ChangeIterator() noexcept { return myIterator; } protected: //! @name methods related to forward STL iterator // Note: Here we use SFINAE (Substitution failure is not an error) to choose diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_TListIterator.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_TListIterator.hxx index 3757c4b608..15c5644800 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_TListIterator.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_TListIterator.hxx @@ -29,41 +29,41 @@ class NCollection_TListIterator : public NCollection_BaseList::Iterator { public: //! Empty constructor - for later Init - NCollection_TListIterator(void) + NCollection_TListIterator(void) noexcept : NCollection_BaseList::Iterator() { } //! Constructor with initialisation - NCollection_TListIterator(const NCollection_BaseList& theList) + NCollection_TListIterator(const NCollection_BaseList& theList) noexcept : NCollection_BaseList::Iterator(theList) { } //! Check end - Standard_Boolean More(void) const { return (myCurrent != NULL); } + Standard_Boolean More(void) const noexcept { return (myCurrent != NULL); } //! Make step - void Next(void) + void Next(void) noexcept { myPrevious = myCurrent; myCurrent = myCurrent->Next(); } //! Constant Value access - const TheItemType& Value(void) const + const TheItemType& Value(void) const noexcept { return ((const NCollection_TListNode*)myCurrent)->Value(); } //! Non-const Value access - TheItemType& Value(void) + TheItemType& Value(void) noexcept { return ((NCollection_TListNode*)myCurrent)->ChangeValue(); } //! Non-const Value access - TheItemType& ChangeValue(void) const + TheItemType& ChangeValue(void) const noexcept { return ((NCollection_TListNode*)myCurrent)->ChangeValue(); } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_TListNode.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_TListNode.hxx index cbddb3ff57..691568ce97 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_TListNode.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_TListNode.hxx @@ -41,10 +41,10 @@ public: } //! Constant value access - const TheItemType& Value() const { return myValue; } + const TheItemType& Value() const noexcept { return myValue; } //! Variable value access - TheItemType& ChangeValue() { return myValue; } + TheItemType& ChangeValue() noexcept { return myValue; } //! Static deleter to be passed to BaseList static void delNode(NCollection_ListNode* theNode, Handle(NCollection_BaseAllocator)& theAl) diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_TypeDef.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_TypeDef.hxx deleted file mode 100644 index 6c22caf9b8..0000000000 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_TypeDef.hxx +++ /dev/null @@ -1,30 +0,0 @@ -// Created on: 2005-08-24 -// Created by: ABV -// Copyright (c) 2005-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// Purpose: Defines some portability macros - -#ifndef NCollection_TypeDef_HeaderFile -#define NCollection_TypeDef_HeaderFile - -// Macro TYPENAME - either C++ keyword typename, or empty on -// platforms that do not support it -#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530) - // work-around against obsolete SUN WorkShop 5.3 compiler - #define TYPENAME -#else - #define TYPENAME typename -#endif - -#endif diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_UBTree.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_UBTree.hxx index bf98c4a809..b1f48c26de 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_UBTree.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_UBTree.hxx @@ -106,7 +106,7 @@ public: * @return * True signals that the selection process is stopped */ - Standard_Boolean Stop() const { return myStop; } + Standard_Boolean Stop() const noexcept { return myStop; } /** * Destructor @@ -143,23 +143,23 @@ public: { } - Standard_Boolean IsLeaf() const { return !myChildren; } + Standard_Boolean IsLeaf() const noexcept { return !myChildren; } - Standard_Boolean IsRoot() const { return !myParent; } + Standard_Boolean IsRoot() const noexcept { return !myParent; } - const TheBndType& Bnd() const { return myBnd; } + const TheBndType& Bnd() const noexcept { return myBnd; } - TheBndType& ChangeBnd() { return myBnd; } + TheBndType& ChangeBnd() noexcept { return myBnd; } - const TheObjType& Object() const { return myObject; } + const TheObjType& Object() const noexcept { return myObject; } - const TreeNode& Child(const Standard_Integer i) const { return myChildren[i]; } + const TreeNode& Child(const Standard_Integer i) const noexcept { return myChildren[i]; } - TreeNode& ChangeChild(const Standard_Integer i) { return myChildren[i]; } + TreeNode& ChangeChild(const Standard_Integer i) noexcept { return myChildren[i]; } - const TreeNode& Parent() const { return *myParent; } + const TreeNode& Parent() const noexcept { return *myParent; } - TreeNode& ChangeParent() { return *myParent; } + TreeNode& ChangeParent() noexcept { return *myParent; } /** * Forces *this node being gemmated such a way that it becomes @@ -322,13 +322,13 @@ public: myAlloc = aNewAlloc; } - Standard_Boolean IsEmpty() const { return !myRoot; } + Standard_Boolean IsEmpty() const noexcept { return !myRoot; } /** * @return * the root node of the tree */ - const TreeNode& Root() const { return *myRoot; } + const TreeNode& Root() const noexcept { return *myRoot; } /** * Destructor. @@ -340,7 +340,7 @@ public: * @return * Allocator object used in this instance of UBTree. */ - const Handle(NCollection_BaseAllocator)& Allocator() const { return myAlloc; } + const Handle(NCollection_BaseAllocator)& Allocator() const noexcept { return myAlloc; } protected: // ---------- PROTECTED METHODS ---------- @@ -349,7 +349,7 @@ protected: * @return * the last added node */ - TreeNode& ChangeLastNode() { return *myLastNode; } + TreeNode& ChangeLastNode() noexcept { return *myLastNode; } /** * Searches in the branch all objects conforming to the given selector. @@ -514,7 +514,7 @@ Standard_Integer NCollection_UBTree::Select(const TreeNo ChangeTree().Clear(); \ } \ \ - Standard_Boolean IsEmpty() const \ + Standard_Boolean IsEmpty() const noexcept \ { \ return Tree().IsEmpty(); \ } \ @@ -526,11 +526,11 @@ Standard_Integer NCollection_UBTree::Select(const TreeNo \ /* Access to the tree algorithm */ \ \ - const UBTree& Tree() const \ + const UBTree& Tree() const noexcept \ { \ return *myTree; \ } \ - UBTree& ChangeTree() \ + UBTree& ChangeTree() noexcept \ { \ return *myTree; \ } \ diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_UBTreeFiller.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_UBTreeFiller.hxx index 0092b979db..187692a3b2 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_UBTreeFiller.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_UBTreeFiller.hxx @@ -127,9 +127,8 @@ public: } private: - // Assignment operator is made empty and private in order to - // avoid warning on MSVC (C4512) - void operator=(const NCollection_UBTreeFiller&) {} + // Explicitly delete assignment operator + NCollection_UBTreeFiller& operator=(const NCollection_UBTreeFiller&) = delete; static Standard_Real checkNode(const UBTreeNode& theNode, const Standard_Integer theLength, diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_UtfIterator.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_UtfIterator.hxx index d2f7b3c879..4dba4d5d91 100755 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_UtfIterator.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_UtfIterator.hxx @@ -79,30 +79,30 @@ public: } //! Equality operator. - bool operator==(const NCollection_UtfIterator& theRight) const + constexpr bool operator==(const NCollection_UtfIterator& theRight) const noexcept { return myPosition == theRight.myPosition; } //! Return true if Unicode symbol is within valid range. - bool IsValid() const { return myCharUtf32 <= UTF32_MAX_LEGAL; } + constexpr bool IsValid() const noexcept { return myCharUtf32 <= UTF32_MAX_LEGAL; } //! Dereference operator. //! @return the UTF-32 codepoint of the symbol currently pointed by iterator. - Standard_Utf32Char operator*() const { return myCharUtf32; } + constexpr Standard_Utf32Char operator*() const noexcept { return myCharUtf32; } //! Buffer-fetching getter. - const Type* BufferHere() const { return myPosition; } + constexpr const Type* BufferHere() const noexcept { return myPosition; } //! Buffer-fetching getter. Dangerous! Iterator should be reinitialized on buffer change. - Type* ChangeBufferHere() { return (Type*)myPosition; } + Type* ChangeBufferHere() noexcept { return (Type*)myPosition; } //! Buffer-fetching getter. - const Type* BufferNext() const { return myPosNext; } + constexpr const Type* BufferNext() const noexcept { return myPosNext; } //! @return the index displacement from iterator initialization //! (first symbol has index 0) - Standard_Integer Index() const { return myCharIndex; } + constexpr Standard_Integer Index() const noexcept { return myCharIndex; } //! @return the advance in bytes to store current symbol in UTF-8. //! 0 means an invalid symbol; @@ -123,7 +123,7 @@ public: //! @return the advance in bytes to store current symbol in UTF-32. //! Always 4 bytes (method for consistency). - Standard_Integer AdvanceBytesUtf32() const + constexpr Standard_Integer AdvanceBytesUtf32() const noexcept { return Standard_Integer(sizeof(Standard_Utf32Char)); } @@ -198,14 +198,17 @@ private: void readNext(const Standard_Utf16Char*) { readUTF16(); } - void readNext(const Standard_Utf32Char*) { myCharUtf32 = *myPosNext++; } + void readNext(const Standard_Utf32Char*) noexcept { myCharUtf32 = *myPosNext++; } //! Helper overload methods to dispatch advance function depending on code unit size Standard_Integer advanceBytes(const Standard_Utf8Char*) const { return AdvanceBytesUtf8(); } Standard_Integer advanceBytes(const Standard_Utf16Char*) const { return AdvanceBytesUtf16(); } - Standard_Integer advanceBytes(const Standard_Utf32Char*) const { return AdvanceBytesUtf32(); } + constexpr Standard_Integer advanceBytes(const Standard_Utf32Char*) const noexcept + { + return AdvanceBytesUtf32(); + } //! Helper overload methods to dispatch getter function depending on code unit size Standard_Utf8Char* getUtf(Standard_Utf8Char* theBuffer) const { return GetUtf8(theBuffer); } @@ -215,20 +218,38 @@ private: Standard_Utf32Char* getUtf(Standard_Utf32Char* theBuffer) const { return GetUtf32(theBuffer); } private: //! @name unicode magic numbers - static const unsigned char UTF8_BYTES_MINUS_ONE[256]; - static const Standard_Utf32Char offsetsFromUTF8[6]; - static const unsigned char UTF8_FIRST_BYTE_MARK[7]; - static const Standard_Utf32Char UTF8_BYTE_MASK; - static const Standard_Utf32Char UTF8_BYTE_MARK; - static const Standard_Utf32Char UTF16_SURROGATE_HIGH_START; - static const Standard_Utf32Char UTF16_SURROGATE_HIGH_END; - static const Standard_Utf32Char UTF16_SURROGATE_LOW_START; - static const Standard_Utf32Char UTF16_SURROGATE_LOW_END; - static const Standard_Utf32Char UTF16_SURROGATE_HIGH_SHIFT; - static const Standard_Utf32Char UTF16_SURROGATE_LOW_BASE; - static const Standard_Utf32Char UTF16_SURROGATE_LOW_MASK; - static const Standard_Utf32Char UTF32_MAX_BMP; - static const Standard_Utf32Char UTF32_MAX_LEGAL; + //! The first character in a UTF-8 sequence indicates how many bytes to read (among other things). + static constexpr unsigned char UTF8_BYTES_MINUS_ONE[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5}; + + //! Magic values subtracted from a buffer value during UTF-8 conversion. + //! This table contains as many values as there might be trailing bytes in a UTF-8 sequence. + static constexpr Standard_Utf32Char offsetsFromUTF8[6] = + {0x00000000UL, 0x00003080UL, 0x000E2080UL, 0x03C82080UL, 0xFA082080UL, 0x82082080UL}; + + //! The first character in a UTF-8 sequence indicates how many bytes to read. + static constexpr unsigned char UTF8_FIRST_BYTE_MARK[7] = + {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC}; + + // Magic numbers for UTF encoding/decoding + static constexpr Standard_Utf32Char UTF8_BYTE_MASK = 0xBF; + static constexpr Standard_Utf32Char UTF8_BYTE_MARK = 0x80; + static constexpr Standard_Utf32Char UTF16_SURROGATE_HIGH_START = 0xD800; + static constexpr Standard_Utf32Char UTF16_SURROGATE_HIGH_END = 0xDBFF; + static constexpr Standard_Utf32Char UTF16_SURROGATE_LOW_START = 0xDC00; + static constexpr Standard_Utf32Char UTF16_SURROGATE_LOW_END = 0xDFFF; + static constexpr Standard_Utf32Char UTF16_SURROGATE_HIGH_SHIFT = 10; + static constexpr Standard_Utf32Char UTF16_SURROGATE_LOW_BASE = 0x0010000UL; + static constexpr Standard_Utf32Char UTF16_SURROGATE_LOW_MASK = 0x3FFUL; + static constexpr Standard_Utf32Char UTF32_MAX_BMP = 0x0000FFFFUL; + static constexpr Standard_Utf32Char UTF32_MAX_LEGAL = 0x0010FFFFUL; private: //! @name private fields const Type* myPosition; //!< buffer position of the first element in the current symbol diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_UtfIterator.lxx b/src/FoundationClasses/TKernel/NCollection/NCollection_UtfIterator.lxx index 6c134be1ab..de4a877c12 100755 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_UtfIterator.lxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_UtfIterator.lxx @@ -35,31 +35,6 @@ // for internal or external distribution as long as this notice // remains attached. -//! The first character in a UTF-8 sequence indicates how many bytes -//! to read (among other things). -template -const unsigned char NCollection_UtfIterator::UTF8_BYTES_MINUS_ONE[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5}; - -//! Magic values subtracted from a buffer value during UTF-8 conversion. -//! This table contains as many values as there might be trailing bytes -//! in a UTF-8 sequence. -template -const Standard_Utf32Char NCollection_UtfIterator::offsetsFromUTF8[6] = - {0x00000000UL, 0x00003080UL, 0x000E2080UL, 0x03C82080UL, 0xFA082080UL, 0x82082080UL}; - -//! The first character in a UTF-8 sequence indicates how many bytes to read. -template -const unsigned char NCollection_UtfIterator::UTF8_FIRST_BYTE_MARK[7] = - {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC}; - // ======================================================================= // function : readUTF8 // purpose : Get a UTF-8 character; leave the tracking pointer at the start of the next character. @@ -101,30 +76,6 @@ inline void NCollection_UtfIterator::readUTF8() myPosNext = (Type*)aPos; } -// magic numbers -template -const Standard_Utf32Char NCollection_UtfIterator::UTF8_BYTE_MASK = 0xBF; -template -const Standard_Utf32Char NCollection_UtfIterator::UTF8_BYTE_MARK = 0x80; -template -const Standard_Utf32Char NCollection_UtfIterator::UTF16_SURROGATE_HIGH_START = 0xD800; -template -const Standard_Utf32Char NCollection_UtfIterator::UTF16_SURROGATE_HIGH_END = 0xDBFF; -template -const Standard_Utf32Char NCollection_UtfIterator::UTF16_SURROGATE_LOW_START = 0xDC00; -template -const Standard_Utf32Char NCollection_UtfIterator::UTF16_SURROGATE_LOW_END = 0xDFFF; -template -const Standard_Utf32Char NCollection_UtfIterator::UTF16_SURROGATE_HIGH_SHIFT = 10; -template -const Standard_Utf32Char NCollection_UtfIterator::UTF16_SURROGATE_LOW_BASE = 0x0010000UL; -template -const Standard_Utf32Char NCollection_UtfIterator::UTF16_SURROGATE_LOW_MASK = 0x3FFUL; -template -const Standard_Utf32Char NCollection_UtfIterator::UTF32_MAX_BMP = 0x0000FFFFUL; -template -const Standard_Utf32Char NCollection_UtfIterator::UTF32_MAX_LEGAL = 0x0010FFFFUL; - //================================================================================================= template diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.hxx index b54a2536e4..56b6ff5496 100755 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.hxx @@ -38,10 +38,10 @@ public: NCollection_UtfIterator Iterator() const { return NCollection_UtfIterator(myString); } //! @return the size of the buffer in bytes, excluding NULL-termination symbol - Standard_Integer Size() const { return mySize; } + Standard_Integer Size() const noexcept { return mySize; } //! @return the length of the string in Unicode symbols - Standard_Integer Length() const { return myLength; } + Standard_Integer Length() const noexcept { return myLength; } //! Retrieve Unicode symbol at specified position. //! Warning! This is a slow access. Iterator should be used for consecutive parsing. @@ -139,7 +139,7 @@ public: ~NCollection_UtfString(); //! Compares this string with another one. - bool IsEqual(const NCollection_UtfString& theCompare) const; + bool IsEqual(const NCollection_UtfString& theCompare) const noexcept; //! Returns the substring. //! @param theStart start index (inclusive) of subString @@ -151,7 +151,7 @@ public: //! Returns NULL-terminated Unicode string. //! Should not be modified or deleted! //! @return (const Type* ) pointer to string - const Type* ToCString() const { return myString; } + const Type* ToCString() const noexcept { return myString; } //! @return copy in UTF-8 format const NCollection_UtfString ToUtf8() const; @@ -172,7 +172,7 @@ public: bool ToLocale(char* theBuffer, const Standard_Integer theSizeBytes) const; //! @return true if string is empty - bool IsEmpty() const { return myString[0] == Type(0); } + bool IsEmpty() const noexcept { return myString[0] == Type(0); } //! Zero string. void Clear(); @@ -182,7 +182,7 @@ public: //! @name assign operators const NCollection_UtfString& Assign(const NCollection_UtfString& theOther); //! Exchange the data of two strings (without reallocating memory). - void Swap(NCollection_UtfString& theOther); + void Swap(NCollection_UtfString& theOther) noexcept; //! Copy from another string. const NCollection_UtfString& operator=(const NCollection_UtfString& theOther) @@ -225,9 +225,12 @@ public: //! @name assign operators } public: //! @name compare operators - bool operator==(const NCollection_UtfString& theCompare) const { return IsEqual(theCompare); } + bool operator==(const NCollection_UtfString& theCompare) const noexcept + { + return IsEqual(theCompare); + } - bool operator!=(const NCollection_UtfString& theCompare) const; + bool operator!=(const NCollection_UtfString& theCompare) const noexcept; private: //! @name low-level methods //! Implementation of copy routine for string of the same type @@ -301,7 +304,7 @@ private: //! @name low-level methods //! Provides bytes interface to avoid incorrect pointer arithmetics. static void strCopy(Standard_Byte* theStrDst, const Standard_Byte* theStrSrc, - const Standard_Integer theSizeBytes) + const Standard_Integer theSizeBytes) noexcept { std::memcpy(theStrDst, theStrSrc, (Standard_Size)theSizeBytes); } @@ -310,7 +313,7 @@ private: //! @name low-level methods static bool strAreEqual(const Type* theString1, const Standard_Integer theSizeBytes1, const Type* theString2, - const Standard_Integer theSizeBytes2) + const Standard_Integer theSizeBytes2) noexcept { return (theSizeBytes1 == theSizeBytes2) && (std::memcmp(theString1, theString2, (Standard_Size)theSizeBytes1) == 0); diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.lxx b/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.lxx index 4c0b0f4a49..dd79f149ef 100755 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.lxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_UtfString.lxx @@ -176,7 +176,7 @@ inline const NCollection_UtfString& NCollection_UtfString::Assign( //================================================================================================= template -inline void NCollection_UtfString::Swap(NCollection_UtfString& theOther) +inline void NCollection_UtfString::Swap(NCollection_UtfString& theOther) noexcept { // Note: we could use std::swap() here, but prefer to not // have dependency on header at that level @@ -289,7 +289,8 @@ inline const NCollection_UtfString& NCollection_UtfString::operator= //================================================================================================= template -inline bool NCollection_UtfString::IsEqual(const NCollection_UtfString& theCompare) const +inline bool NCollection_UtfString::IsEqual( + const NCollection_UtfString& theCompare) const noexcept { return this == &theCompare || strAreEqual(myString, mySize, theCompare.myString, theCompare.mySize); @@ -300,7 +301,8 @@ inline bool NCollection_UtfString::IsEqual(const NCollection_UtfString& th // purpose : // ======================================================================= template -inline bool NCollection_UtfString::operator!=(const NCollection_UtfString& theCompare) const +inline bool NCollection_UtfString::operator!=( + const NCollection_UtfString& theCompare) const noexcept { return (!NCollection_UtfString::operator==(theCompare)); } diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Vec2.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Vec2.hxx index 0318ed247f..f9120f311d 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Vec2.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Vec2.hxx @@ -22,11 +22,11 @@ //! Auxiliary macros to define couple of similar access components as vector methods. //! @return 2 components by their names in specified order #define NCOLLECTION_VEC_COMPONENTS_2D(theX, theY) \ - const NCollection_Vec2 theX##theY() const \ + constexpr NCollection_Vec2 theX##theY() const noexcept \ { \ return NCollection_Vec2(theX(), theY()); \ } \ - const NCollection_Vec2 theY##theX() const \ + constexpr NCollection_Vec2 theY##theX() const noexcept \ { \ return NCollection_Vec2(theY(), theX()); \ } @@ -39,16 +39,16 @@ class NCollection_Vec2 public: //! Returns the number of components. - static int Length() { return 2; } + static constexpr int Length() noexcept { return 2; } //! Empty constructor. Construct the zero vector. - NCollection_Vec2() { v[0] = v[1] = Element_t(0); } + constexpr NCollection_Vec2() noexcept { v[0] = v[1] = Element_t(0); } //! Initialize ALL components of vector within specified value. - explicit NCollection_Vec2(const Element_t theXY) { v[0] = v[1] = theXY; } + explicit constexpr NCollection_Vec2(const Element_t theXY) noexcept { v[0] = v[1] = theXY; } //! Per-component constructor. - explicit NCollection_Vec2(const Element_t theX, const Element_t theY) + explicit constexpr NCollection_Vec2(const Element_t theX, const Element_t theY) noexcept { v[0] = theX; v[1] = theY; @@ -60,57 +60,63 @@ public: //! @tparam OtherElement_t the element type of the other 2-component vector theOtherVec2 //! @param theOtherVec2 the 2-component vector that needs to be converted template - explicit NCollection_Vec2(const NCollection_Vec2& theOtherVec2) + explicit constexpr NCollection_Vec2(const NCollection_Vec2& theOtherVec2) noexcept { v[0] = static_cast(theOtherVec2[0]); v[1] = static_cast(theOtherVec2[1]); } //! Assign new values to the vector. - void SetValues(const Element_t theX, const Element_t theY) + constexpr void SetValues(const Element_t theX, const Element_t theY) noexcept { v[0] = theX; v[1] = theY; } //! Alias to 1st component as X coordinate in XY. - Element_t x() const { return v[0]; } + constexpr Element_t x() const noexcept { return v[0]; } //! Alias to 2nd component as Y coordinate in XY. - Element_t y() const { return v[1]; } + constexpr Element_t y() const noexcept { return v[1]; } //! @return 2 components by their names in specified order (in GLSL-style) NCOLLECTION_VEC_COMPONENTS_2D(x, y) //! Alias to 1st component as X coordinate in XY. - Element_t& x() { return v[0]; } + constexpr Element_t& x() noexcept { return v[0]; } //! Alias to 2nd component as Y coordinate in XY. - Element_t& y() { return v[1]; } + constexpr Element_t& y() noexcept { return v[1]; } //! Check this vector with another vector for equality (without tolerance!). - bool IsEqual(const NCollection_Vec2& theOther) const + constexpr bool IsEqual(const NCollection_Vec2& theOther) const noexcept { return v[0] == theOther.v[0] && v[1] == theOther.v[1]; } //! Check this vector with another vector for equality (without tolerance!). - bool operator==(const NCollection_Vec2& theOther) const { return IsEqual(theOther); } + constexpr bool operator==(const NCollection_Vec2& theOther) const noexcept + { + return IsEqual(theOther); + } //! Check this vector with another vector for non-equality (without tolerance!). - bool operator!=(const NCollection_Vec2& theOther) const { return !IsEqual(theOther); } + constexpr bool operator!=(const NCollection_Vec2& theOther) const noexcept + { + return !IsEqual(theOther); + } //! Raw access to the data (for OpenGL exchange). - const Element_t* GetData() const { return v; } + constexpr const Element_t* GetData() const noexcept { return v; } - Element_t* ChangeData() { return v; } + constexpr Element_t* ChangeData() noexcept { return v; } - operator const Element_t*() const { return v; } + constexpr operator const Element_t*() const noexcept { return v; } - operator Element_t*() { return v; } + constexpr operator Element_t*() noexcept { return v; } //! Compute per-component summary. - NCollection_Vec2& operator+=(const NCollection_Vec2& theAdd) + constexpr NCollection_Vec2& operator+=(const NCollection_Vec2& theAdd) noexcept { v[0] += theAdd.v[0]; v[1] += theAdd.v[1]; @@ -118,14 +124,14 @@ public: } //! Compute per-component summary. - friend NCollection_Vec2 operator+(const NCollection_Vec2& theLeft, - const NCollection_Vec2& theRight) + friend constexpr NCollection_Vec2 operator+(const NCollection_Vec2& theLeft, + const NCollection_Vec2& theRight) noexcept { return NCollection_Vec2(theLeft.v[0] + theRight.v[0], theLeft.v[1] + theRight.v[1]); } //! Compute per-component subtraction. - NCollection_Vec2& operator-=(const NCollection_Vec2& theDec) + constexpr NCollection_Vec2& operator-=(const NCollection_Vec2& theDec) noexcept { v[0] -= theDec.v[0]; v[1] -= theDec.v[1]; @@ -133,17 +139,17 @@ public: } //! Compute per-component subtraction. - friend NCollection_Vec2 operator-(const NCollection_Vec2& theLeft, - const NCollection_Vec2& theRight) + friend constexpr NCollection_Vec2 operator-(const NCollection_Vec2& theLeft, + const NCollection_Vec2& theRight) noexcept { return NCollection_Vec2(theLeft.v[0] - theRight.v[0], theLeft.v[1] - theRight.v[1]); } //! Unary -. - NCollection_Vec2 operator-() const { return NCollection_Vec2(-x(), -y()); } + constexpr NCollection_Vec2 operator-() const noexcept { return NCollection_Vec2(-x(), -y()); } //! Compute per-component multiplication. - NCollection_Vec2& operator*=(const NCollection_Vec2& theRight) + constexpr NCollection_Vec2& operator*=(const NCollection_Vec2& theRight) noexcept { v[0] *= theRight.v[0]; v[1] *= theRight.v[1]; @@ -151,57 +157,60 @@ public: } //! Compute per-component multiplication. - friend NCollection_Vec2 operator*(const NCollection_Vec2& theLeft, - const NCollection_Vec2& theRight) + friend constexpr NCollection_Vec2 operator*(const NCollection_Vec2& theLeft, + const NCollection_Vec2& theRight) noexcept { return NCollection_Vec2(theLeft.v[0] * theRight.v[0], theLeft.v[1] * theRight.v[1]); } //! Compute per-component multiplication by scale factor. - void Multiply(const Element_t theFactor) + constexpr void Multiply(const Element_t theFactor) noexcept { v[0] *= theFactor; v[1] *= theFactor; } //! Compute per-component multiplication by scale factor. - NCollection_Vec2 Multiplied(const Element_t theFactor) const + constexpr NCollection_Vec2 Multiplied(const Element_t theFactor) const noexcept { return NCollection_Vec2(v[0] * theFactor, v[1] * theFactor); } //! Compute component-wise minimum of two vectors. - NCollection_Vec2 cwiseMin(const NCollection_Vec2& theVec) const + constexpr NCollection_Vec2 cwiseMin(const NCollection_Vec2& theVec) const noexcept { return NCollection_Vec2(v[0] < theVec.v[0] ? v[0] : theVec.v[0], v[1] < theVec.v[1] ? v[1] : theVec.v[1]); } //! Compute component-wise maximum of two vectors. - NCollection_Vec2 cwiseMax(const NCollection_Vec2& theVec) const + constexpr NCollection_Vec2 cwiseMax(const NCollection_Vec2& theVec) const noexcept { return NCollection_Vec2(v[0] > theVec.v[0] ? v[0] : theVec.v[0], v[1] > theVec.v[1] ? v[1] : theVec.v[1]); } //! Compute component-wise modulus of the vector. - NCollection_Vec2 cwiseAbs() const { return NCollection_Vec2(std::abs(v[0]), std::abs(v[1])); } + NCollection_Vec2 cwiseAbs() const noexcept + { + return NCollection_Vec2(std::abs(v[0]), std::abs(v[1])); + } //! Compute maximum component of the vector. - Element_t maxComp() const { return v[0] > v[1] ? v[0] : v[1]; } + constexpr Element_t maxComp() const noexcept { return v[0] > v[1] ? v[0] : v[1]; } //! Compute minimum component of the vector. - Element_t minComp() const { return v[0] < v[1] ? v[0] : v[1]; } + constexpr Element_t minComp() const noexcept { return v[0] < v[1] ? v[0] : v[1]; } //! Compute per-component multiplication by scale factor. - NCollection_Vec2& operator*=(const Element_t theFactor) + constexpr NCollection_Vec2& operator*=(const Element_t theFactor) noexcept { Multiply(theFactor); return *this; } //! Compute per-component division by scale factor. - NCollection_Vec2& operator/=(const Element_t theInvFactor) + constexpr NCollection_Vec2& operator/=(const Element_t theInvFactor) { v[0] /= theInvFactor; v[1] /= theInvFactor; @@ -209,7 +218,7 @@ public: } //! Compute per-component division. - NCollection_Vec2& operator/=(const NCollection_Vec2& theRight) + constexpr NCollection_Vec2& operator/=(const NCollection_Vec2& theRight) { v[0] /= theRight.v[0]; v[1] /= theRight.v[1]; @@ -217,39 +226,48 @@ public: } //! Compute per-component multiplication by scale factor. - NCollection_Vec2 operator*(const Element_t theFactor) const { return Multiplied(theFactor); } + constexpr NCollection_Vec2 operator*(const Element_t theFactor) const noexcept + { + return Multiplied(theFactor); + } //! Compute per-component division by scale factor. - NCollection_Vec2 operator/(const Element_t theInvFactor) const + constexpr NCollection_Vec2 operator/(const Element_t theInvFactor) const { return NCollection_Vec2(v[0] / theInvFactor, v[1] / theInvFactor); } //! Compute per-component division. - friend NCollection_Vec2 operator/(const NCollection_Vec2& theLeft, - const NCollection_Vec2& theRight) + friend constexpr NCollection_Vec2 operator/(const NCollection_Vec2& theLeft, + const NCollection_Vec2& theRight) { return NCollection_Vec2(theLeft.v[0] / theRight.v[0], theLeft.v[1] / theRight.v[1]); } //! Computes the dot product. - Element_t Dot(const NCollection_Vec2& theOther) const + constexpr Element_t Dot(const NCollection_Vec2& theOther) const noexcept { return x() * theOther.x() + y() * theOther.y(); } //! Computes the vector modulus (magnitude, length). - Element_t Modulus() const { return std::sqrt(x() * x() + y() * y()); } + Element_t Modulus() const noexcept { return std::sqrt(x() * x() + y() * y()); } //! Computes the square of vector modulus (magnitude, length). //! This method may be used for performance tricks. - Element_t SquareModulus() const { return x() * x() + y() * y(); } + constexpr Element_t SquareModulus() const noexcept { return x() * x() + y() * y(); } //! Construct DX unit vector. - static NCollection_Vec2 DX() { return NCollection_Vec2(Element_t(1), Element_t(0)); } + static constexpr NCollection_Vec2 DX() noexcept + { + return NCollection_Vec2(Element_t(1), Element_t(0)); + } //! Construct DY unit vector. - static NCollection_Vec2 DY() { return NCollection_Vec2(Element_t(0), Element_t(1)); } + static constexpr NCollection_Vec2 DY() noexcept + { + return NCollection_Vec2(Element_t(0), Element_t(1)); + } //! Dumps the content of me into the stream void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Vec3.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Vec3.hxx index 25aba17c0e..82507e29e2 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Vec3.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Vec3.hxx @@ -21,27 +21,27 @@ //! Auxiliary macros to define couple of similar access components as vector methods #define NCOLLECTION_VEC_COMPONENTS_3D(theX, theY, theZ) \ - const NCollection_Vec3 theX##theY##theZ() const \ + constexpr NCollection_Vec3 theX##theY##theZ() const noexcept \ { \ return NCollection_Vec3(theX(), theY(), theZ()); \ } \ - const NCollection_Vec3 theX##theZ##theY() const \ + constexpr NCollection_Vec3 theX##theZ##theY() const noexcept \ { \ return NCollection_Vec3(theX(), theZ(), theY()); \ } \ - const NCollection_Vec3 theY##theX##theZ() const \ + constexpr NCollection_Vec3 theY##theX##theZ() const noexcept \ { \ return NCollection_Vec3(theY(), theX(), theZ()); \ } \ - const NCollection_Vec3 theY##theZ##theX() const \ + constexpr NCollection_Vec3 theY##theZ##theX() const noexcept \ { \ return NCollection_Vec3(theY(), theZ(), theX()); \ } \ - const NCollection_Vec3 theZ##theY##theX() const \ + constexpr NCollection_Vec3 theZ##theY##theX() const noexcept \ { \ return NCollection_Vec3(theZ(), theY(), theX()); \ } \ - const NCollection_Vec3 theZ##theX##theY() const \ + constexpr NCollection_Vec3 theZ##theX##theY() const noexcept \ { \ return NCollection_Vec3(theZ(), theX(), theY()); \ } @@ -55,16 +55,21 @@ class NCollection_Vec3 public: //! Returns the number of components. - static int Length() { return 3; } + static constexpr int Length() noexcept { return 3; } //! Empty constructor. Construct the zero vector. NCollection_Vec3() { std::memset(this, 0, sizeof(NCollection_Vec3)); } //! Initialize ALL components of vector within specified value. - explicit NCollection_Vec3(Element_t theValue) { v[0] = v[1] = v[2] = theValue; } + explicit constexpr NCollection_Vec3(Element_t theValue) noexcept + { + v[0] = v[1] = v[2] = theValue; + } //! Per-component constructor. - explicit NCollection_Vec3(const Element_t theX, const Element_t theY, const Element_t theZ) + explicit constexpr NCollection_Vec3(const Element_t theX, + const Element_t theY, + const Element_t theZ) noexcept { v[0] = theX; v[1] = theY; @@ -72,8 +77,8 @@ public: } //! Constructor from 2-components vector + optional 3rd value. - explicit NCollection_Vec3(const NCollection_Vec2& theVec2, - Element_t theZ = Element_t(0)) + explicit constexpr NCollection_Vec3(const NCollection_Vec2& theVec2, + Element_t theZ = Element_t(0)) noexcept { v[0] = theVec2[0]; v[1] = theVec2[1]; @@ -86,7 +91,7 @@ public: //! @tparam OtherElement_t the element type of the other 3-component vector theOtherVec3 //! @param theOtherVec3 the 3-component vector that needs to be converted template - explicit NCollection_Vec3(const NCollection_Vec3& theOtherVec3) + explicit constexpr NCollection_Vec3(const NCollection_Vec3& theOtherVec3) noexcept { v[0] = static_cast(theOtherVec3[0]); v[1] = static_cast(theOtherVec3[1]); @@ -94,7 +99,9 @@ public: } //! Assign new values to the vector. - void SetValues(const Element_t theX, const Element_t theY, const Element_t theZ) + constexpr void SetValues(const Element_t theX, + const Element_t theY, + const Element_t theZ) noexcept { v[0] = theX; v[1] = theY; @@ -102,7 +109,7 @@ public: } //! Assign new values to the vector. - void SetValues(const NCollection_Vec2& theVec2, Element_t theZ) + constexpr void SetValues(const NCollection_Vec2& theVec2, Element_t theZ) noexcept { v[0] = theVec2.x(); v[1] = theVec2.y(); @@ -110,22 +117,22 @@ public: } //! Alias to 1st component as X coordinate in XYZ. - Element_t x() const { return v[0]; } + constexpr Element_t x() const noexcept { return v[0]; } //! Alias to 1st component as RED channel in RGB. - Element_t r() const { return v[0]; } + constexpr Element_t r() const noexcept { return v[0]; } //! Alias to 2nd component as Y coordinate in XYZ. - Element_t y() const { return v[1]; } + constexpr Element_t y() const noexcept { return v[1]; } //! Alias to 2nd component as GREEN channel in RGB. - Element_t g() const { return v[1]; } + constexpr Element_t g() const noexcept { return v[1]; } //! Alias to 3rd component as Z coordinate in XYZ. - Element_t z() const { return v[2]; } + constexpr Element_t z() const noexcept { return v[2]; } //! Alias to 3rd component as BLUE channel in RGB. - Element_t b() const { return v[2]; } + constexpr Element_t b() const noexcept { return v[2]; } //! @return 2 components by their names in specified order (in GLSL-style) NCOLLECTION_VEC_COMPONENTS_2D(x, y) @@ -136,46 +143,52 @@ public: NCOLLECTION_VEC_COMPONENTS_3D(x, y, z) //! Alias to 1st component as X coordinate in XYZ. - Element_t& x() { return v[0]; } + constexpr Element_t& x() noexcept { return v[0]; } //! Alias to 1st component as RED channel in RGB. - Element_t& r() { return v[0]; } + constexpr Element_t& r() noexcept { return v[0]; } //! Alias to 2nd component as Y coordinate in XYZ. - Element_t& y() { return v[1]; } + constexpr Element_t& y() noexcept { return v[1]; } //! Alias to 2nd component as GREEN channel in RGB. - Element_t& g() { return v[1]; } + constexpr Element_t& g() noexcept { return v[1]; } //! Alias to 3rd component as Z coordinate in XYZ. - Element_t& z() { return v[2]; } + constexpr Element_t& z() noexcept { return v[2]; } //! Alias to 3rd component as BLUE channel in RGB. - Element_t& b() { return v[2]; } + constexpr Element_t& b() noexcept { return v[2]; } //! Check this vector with another vector for equality (without tolerance!). - bool IsEqual(const NCollection_Vec3& theOther) const + constexpr bool IsEqual(const NCollection_Vec3& theOther) const noexcept { return v[0] == theOther.v[0] && v[1] == theOther.v[1] && v[2] == theOther.v[2]; } //! Check this vector with another vector for equality (without tolerance!). - bool operator==(const NCollection_Vec3& theOther) const { return IsEqual(theOther); } + constexpr bool operator==(const NCollection_Vec3& theOther) const noexcept + { + return IsEqual(theOther); + } //! Check this vector with another vector for non-equality (without tolerance!). - bool operator!=(const NCollection_Vec3& theOther) const { return !IsEqual(theOther); } + constexpr bool operator!=(const NCollection_Vec3& theOther) const noexcept + { + return !IsEqual(theOther); + } //! Raw access to the data (for OpenGL exchange). - const Element_t* GetData() const { return v; } + constexpr const Element_t* GetData() const noexcept { return v; } - Element_t* ChangeData() { return v; } + constexpr Element_t* ChangeData() noexcept { return v; } - operator const Element_t*() const { return v; } + constexpr operator const Element_t*() const noexcept { return v; } - operator Element_t*() { return v; } + constexpr operator Element_t*() noexcept { return v; } //! Compute per-component summary. - NCollection_Vec3& operator+=(const NCollection_Vec3& theAdd) + constexpr NCollection_Vec3& operator+=(const NCollection_Vec3& theAdd) noexcept { v[0] += theAdd.v[0]; v[1] += theAdd.v[1]; @@ -184,18 +197,21 @@ public: } //! Compute per-component summary. - friend NCollection_Vec3 operator+(const NCollection_Vec3& theLeft, - const NCollection_Vec3& theRight) + friend constexpr NCollection_Vec3 operator+(const NCollection_Vec3& theLeft, + const NCollection_Vec3& theRight) noexcept { NCollection_Vec3 aSumm = NCollection_Vec3(theLeft); return aSumm += theRight; } //! Unary -. - NCollection_Vec3 operator-() const { return NCollection_Vec3(-x(), -y(), -z()); } + constexpr NCollection_Vec3 operator-() const noexcept + { + return NCollection_Vec3(-x(), -y(), -z()); + } //! Compute per-component subtraction. - NCollection_Vec3& operator-=(const NCollection_Vec3& theDec) + constexpr NCollection_Vec3& operator-=(const NCollection_Vec3& theDec) noexcept { v[0] -= theDec.v[0]; v[1] -= theDec.v[1]; @@ -204,15 +220,15 @@ public: } //! Compute per-component subtraction. - friend NCollection_Vec3 operator-(const NCollection_Vec3& theLeft, - const NCollection_Vec3& theRight) + friend constexpr NCollection_Vec3 operator-(const NCollection_Vec3& theLeft, + const NCollection_Vec3& theRight) noexcept { NCollection_Vec3 aSumm = NCollection_Vec3(theLeft); return aSumm -= theRight; } //! Compute per-component multiplication by scale factor. - void Multiply(const Element_t theFactor) + constexpr void Multiply(const Element_t theFactor) noexcept { v[0] *= theFactor; v[1] *= theFactor; @@ -220,7 +236,7 @@ public: } //! Compute per-component multiplication. - NCollection_Vec3& operator*=(const NCollection_Vec3& theRight) + constexpr NCollection_Vec3& operator*=(const NCollection_Vec3& theRight) noexcept { v[0] *= theRight.v[0]; v[1] *= theRight.v[1]; @@ -229,25 +245,28 @@ public: } //! Compute per-component multiplication. - friend NCollection_Vec3 operator*(const NCollection_Vec3& theLeft, - const NCollection_Vec3& theRight) + friend constexpr NCollection_Vec3 operator*(const NCollection_Vec3& theLeft, + const NCollection_Vec3& theRight) noexcept { NCollection_Vec3 aResult = NCollection_Vec3(theLeft); return aResult *= theRight; } //! Compute per-component multiplication by scale factor. - NCollection_Vec3& operator*=(const Element_t theFactor) + constexpr NCollection_Vec3& operator*=(const Element_t theFactor) noexcept { Multiply(theFactor); return *this; } //! Compute per-component multiplication by scale factor. - NCollection_Vec3 operator*(const Element_t theFactor) const { return Multiplied(theFactor); } + constexpr NCollection_Vec3 operator*(const Element_t theFactor) const noexcept + { + return Multiplied(theFactor); + } //! Compute per-component multiplication by scale factor. - NCollection_Vec3 Multiplied(const Element_t theFactor) const + constexpr NCollection_Vec3 Multiplied(const Element_t theFactor) const noexcept { NCollection_Vec3 aCopyVec3(*this); aCopyVec3 *= theFactor; @@ -255,7 +274,7 @@ public: } //! Compute component-wise minimum of two vectors. - NCollection_Vec3 cwiseMin(const NCollection_Vec3& theVec) const + constexpr NCollection_Vec3 cwiseMin(const NCollection_Vec3& theVec) const noexcept { return NCollection_Vec3(v[0] < theVec.v[0] ? v[0] : theVec.v[0], v[1] < theVec.v[1] ? v[1] : theVec.v[1], @@ -263,7 +282,7 @@ public: } //! Compute component-wise maximum of two vectors. - NCollection_Vec3 cwiseMax(const NCollection_Vec3& theVec) const + constexpr NCollection_Vec3 cwiseMax(const NCollection_Vec3& theVec) const noexcept { return NCollection_Vec3(v[0] > theVec.v[0] ? v[0] : theVec.v[0], v[1] > theVec.v[1] ? v[1] : theVec.v[1], @@ -271,25 +290,25 @@ public: } //! Compute component-wise modulus of the vector. - NCollection_Vec3 cwiseAbs() const + NCollection_Vec3 cwiseAbs() const noexcept { return NCollection_Vec3(std::abs(v[0]), std::abs(v[1]), std::abs(v[2])); } //! Compute maximum component of the vector. - Element_t maxComp() const + constexpr Element_t maxComp() const noexcept { return v[0] > v[1] ? (v[0] > v[2] ? v[0] : v[2]) : (v[1] > v[2] ? v[1] : v[2]); } //! Compute minimum component of the vector. - Element_t minComp() const + constexpr Element_t minComp() const noexcept { return v[0] < v[1] ? (v[0] < v[2] ? v[0] : v[2]) : (v[1] < v[2] ? v[1] : v[2]); } //! Compute per-component division by scale factor. - NCollection_Vec3& operator/=(const Element_t theInvFactor) + constexpr NCollection_Vec3& operator/=(const Element_t theInvFactor) { v[0] /= theInvFactor; v[1] /= theInvFactor; @@ -298,7 +317,7 @@ public: } //! Compute per-component division. - NCollection_Vec3& operator/=(const NCollection_Vec3& theRight) + constexpr NCollection_Vec3& operator/=(const NCollection_Vec3& theRight) { v[0] /= theRight.v[0]; v[1] /= theRight.v[1]; @@ -307,32 +326,32 @@ public: } //! Compute per-component division by scale factor. - NCollection_Vec3 operator/(const Element_t theInvFactor) const + constexpr NCollection_Vec3 operator/(const Element_t theInvFactor) const { NCollection_Vec3 aResult(*this); return aResult /= theInvFactor; } //! Compute per-component division. - friend NCollection_Vec3 operator/(const NCollection_Vec3& theLeft, - const NCollection_Vec3& theRight) + friend constexpr NCollection_Vec3 operator/(const NCollection_Vec3& theLeft, + const NCollection_Vec3& theRight) { NCollection_Vec3 aResult = NCollection_Vec3(theLeft); return aResult /= theRight; } //! Computes the dot product. - Element_t Dot(const NCollection_Vec3& theOther) const + constexpr Element_t Dot(const NCollection_Vec3& theOther) const noexcept { return x() * theOther.x() + y() * theOther.y() + z() * theOther.z(); } //! Computes the vector modulus (magnitude, length). - Element_t Modulus() const { return std::sqrt(x() * x() + y() * y() + z() * z()); } + Element_t Modulus() const noexcept { return std::sqrt(x() * x() + y() * y() + z() * z()); } //! Computes the square of vector modulus (magnitude, length). //! This method may be used for performance tricks. - Element_t SquareModulus() const { return x() * x() + y() * y() + z() * z(); } + constexpr Element_t SquareModulus() const noexcept { return x() * x() + y() * y() + z() * z(); } //! Normalize the vector. void Normalize() @@ -355,7 +374,8 @@ public: } //! Computes the cross product. - static NCollection_Vec3 Cross(const NCollection_Vec3& theVec1, const NCollection_Vec3& theVec2) + static constexpr NCollection_Vec3 Cross(const NCollection_Vec3& theVec1, + const NCollection_Vec3& theVec2) noexcept { return NCollection_Vec3(theVec1.y() * theVec2.z() - theVec1.z() * theVec2.y(), theVec1.z() * theVec2.x() - theVec1.x() * theVec2.z(), @@ -365,27 +385,27 @@ public: //! Compute linear interpolation between to vectors. //! @param theT - interpolation coefficient 0..1; //! @return interpolation result. - static NCollection_Vec3 GetLERP(const NCollection_Vec3& theFrom, - const NCollection_Vec3& theTo, - const Element_t theT) + static constexpr NCollection_Vec3 GetLERP(const NCollection_Vec3& theFrom, + const NCollection_Vec3& theTo, + const Element_t theT) noexcept { return theFrom * (Element_t(1) - theT) + theTo * theT; } //! Construct DX unit vector. - static NCollection_Vec3 DX() + static constexpr NCollection_Vec3 DX() noexcept { return NCollection_Vec3(Element_t(1), Element_t(0), Element_t(0)); } //! Construct DY unit vector. - static NCollection_Vec3 DY() + static constexpr NCollection_Vec3 DY() noexcept { return NCollection_Vec3(Element_t(0), Element_t(1), Element_t(0)); } //! Construct DZ unit vector. - static NCollection_Vec3 DZ() + static constexpr NCollection_Vec3 DZ() noexcept { return NCollection_Vec3(Element_t(0), Element_t(0), Element_t(1)); } @@ -403,7 +423,8 @@ private: //! Optimized concretization for float type. template <> -inline NCollection_Vec3& NCollection_Vec3::operator/=(const float theInvFactor) +inline constexpr NCollection_Vec3& NCollection_Vec3::operator/=( + const float theInvFactor) { Multiply(1.0f / theInvFactor); return *this; @@ -411,7 +432,8 @@ inline NCollection_Vec3& NCollection_Vec3::operator/=(const float //! Optimized concretization for double type. template <> -inline NCollection_Vec3& NCollection_Vec3::operator/=(const double theInvFactor) +inline constexpr NCollection_Vec3& NCollection_Vec3::operator/=( + const double theInvFactor) { Multiply(1.0 / theInvFactor); return *this; diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Vec4.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Vec4.hxx index e2cd23e36d..48f300c004 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Vec4.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Vec4.hxx @@ -28,19 +28,22 @@ class NCollection_Vec4 public: //! Returns the number of components. - static int Length() { return 4; } + static constexpr int Length() noexcept { return 4; } //! Empty constructor. Construct the zero vector. NCollection_Vec4() { std::memset(this, 0, sizeof(NCollection_Vec4)); } //! Initialize ALL components of vector within specified value. - explicit NCollection_Vec4(const Element_t theValue) { v[0] = v[1] = v[2] = v[3] = theValue; } + explicit constexpr NCollection_Vec4(const Element_t theValue) noexcept + { + v[0] = v[1] = v[2] = v[3] = theValue; + } //! Per-component constructor. - explicit NCollection_Vec4(const Element_t theX, - const Element_t theY, - const Element_t theZ, - const Element_t theW) + explicit constexpr NCollection_Vec4(const Element_t theX, + const Element_t theY, + const Element_t theZ, + const Element_t theW) noexcept { v[0] = theX; v[1] = theY; @@ -49,7 +52,7 @@ public: } //! Constructor from 2-components vector. - explicit NCollection_Vec4(const NCollection_Vec2& theVec2) + explicit constexpr NCollection_Vec4(const NCollection_Vec2& theVec2) noexcept { v[0] = theVec2[0]; v[1] = theVec2[1]; @@ -70,7 +73,7 @@ public: //! @tparam OtherElement_t the element type of the other 4-component vector theOtherVec4 //! @param theOtherVec4 the 4-component vector that needs to be converted template - explicit NCollection_Vec4(const NCollection_Vec4& theOtherVec4) + explicit constexpr NCollection_Vec4(const NCollection_Vec4& theOtherVec4) noexcept { v[0] = static_cast(theOtherVec4[0]); v[1] = static_cast(theOtherVec4[1]); @@ -79,10 +82,10 @@ public: } //! Assign new values to the vector. - void SetValues(const Element_t theX, - const Element_t theY, - const Element_t theZ, - const Element_t theW) + constexpr void SetValues(const Element_t theX, + const Element_t theY, + const Element_t theZ, + const Element_t theW) noexcept { v[0] = theX; v[1] = theY; @@ -91,7 +94,8 @@ public: } //! Assign new values as 3-component vector and a 4-th value. - void SetValues(const NCollection_Vec3& theVec3, const Element_t theW) + constexpr void SetValues(const NCollection_Vec3& theVec3, + const Element_t theW) noexcept { v[0] = theVec3.x(); v[1] = theVec3.y(); @@ -100,28 +104,28 @@ public: } //! Alias to 1st component as X coordinate in XYZW. - Element_t x() const { return v[0]; } + constexpr Element_t x() const noexcept { return v[0]; } //! Alias to 1st component as RED channel in RGBA. - Element_t r() const { return v[0]; } + constexpr Element_t r() const noexcept { return v[0]; } //! Alias to 2nd component as Y coordinate in XYZW. - Element_t y() const { return v[1]; } + constexpr Element_t y() const noexcept { return v[1]; } //! Alias to 2nd component as GREEN channel in RGBA. - Element_t g() const { return v[1]; } + constexpr Element_t g() const noexcept { return v[1]; } //! Alias to 3rd component as Z coordinate in XYZW. - Element_t z() const { return v[2]; } + constexpr Element_t z() const noexcept { return v[2]; } //! Alias to 3rd component as BLUE channel in RGBA. - Element_t b() const { return v[2]; } + constexpr Element_t b() const noexcept { return v[2]; } //! Alias to 4th component as W coordinate in XYZW. - Element_t w() const { return v[3]; } + constexpr Element_t w() const noexcept { return v[3]; } //! Alias to 4th component as ALPHA channel in RGBA. - Element_t a() const { return v[3]; } + constexpr Element_t a() const noexcept { return v[3]; } //! @return 2 of XYZW components in specified order as vector in GLSL-style NCOLLECTION_VEC_COMPONENTS_2D(x, y) @@ -141,53 +145,59 @@ public: NCOLLECTION_VEC_COMPONENTS_3D(r, g, b) //! Alias to 1st component as X coordinate in XYZW. - Element_t& x() { return v[0]; } + constexpr Element_t& x() noexcept { return v[0]; } //! Alias to 1st component as RED channel in RGBA. - Element_t& r() { return v[0]; } + constexpr Element_t& r() noexcept { return v[0]; } //! Alias to 2nd component as Y coordinate in XYZW. - Element_t& y() { return v[1]; } + constexpr Element_t& y() noexcept { return v[1]; } //! Alias to 2nd component as GREEN channel in RGBA. - Element_t& g() { return v[1]; } // Green color + constexpr Element_t& g() noexcept { return v[1]; } // Green color //! Alias to 3rd component as Z coordinate in XYZW. - Element_t& z() { return v[2]; } + constexpr Element_t& z() noexcept { return v[2]; } //! Alias to 3rd component as BLUE channel in RGBA. - Element_t& b() { return v[2]; } + constexpr Element_t& b() noexcept { return v[2]; } //! Alias to 4th component as W coordinate in XYZW. - Element_t& w() { return v[3]; } + constexpr Element_t& w() noexcept { return v[3]; } //! Alias to 4th component as ALPHA channel in RGBA. - Element_t& a() { return v[3]; } + constexpr Element_t& a() noexcept { return v[3]; } //! Check this vector with another vector for equality (without tolerance!). - bool IsEqual(const NCollection_Vec4& theOther) const + constexpr bool IsEqual(const NCollection_Vec4& theOther) const noexcept { return v[0] == theOther.v[0] && v[1] == theOther.v[1] && v[2] == theOther.v[2] && v[3] == theOther.v[3]; } //! Check this vector with another vector for equality (without tolerance!). - bool operator==(const NCollection_Vec4& theOther) const { return IsEqual(theOther); } + constexpr bool operator==(const NCollection_Vec4& theOther) const noexcept + { + return IsEqual(theOther); + } //! Check this vector with another vector for non-equality (without tolerance!). - bool operator!=(const NCollection_Vec4& theOther) const { return !IsEqual(theOther); } + constexpr bool operator!=(const NCollection_Vec4& theOther) const noexcept + { + return !IsEqual(theOther); + } //! Raw access to the data (for OpenGL exchange). - const Element_t* GetData() const { return v; } + constexpr const Element_t* GetData() const noexcept { return v; } - Element_t* ChangeData() { return v; } + constexpr Element_t* ChangeData() noexcept { return v; } - operator const Element_t*() const { return v; } + constexpr operator const Element_t*() const noexcept { return v; } - operator Element_t*() { return v; } + constexpr operator Element_t*() noexcept { return v; } //! Compute per-component summary. - NCollection_Vec4& operator+=(const NCollection_Vec4& theAdd) + constexpr NCollection_Vec4& operator+=(const NCollection_Vec4& theAdd) noexcept { v[0] += theAdd.v[0]; v[1] += theAdd.v[1]; @@ -197,18 +207,21 @@ public: } //! Compute per-component summary. - friend NCollection_Vec4 operator+(const NCollection_Vec4& theLeft, - const NCollection_Vec4& theRight) + friend constexpr NCollection_Vec4 operator+(const NCollection_Vec4& theLeft, + const NCollection_Vec4& theRight) noexcept { NCollection_Vec4 aSumm = NCollection_Vec4(theLeft); return aSumm += theRight; } //! Unary -. - NCollection_Vec4 operator-() const { return NCollection_Vec4(-x(), -y(), -z(), -w()); } + constexpr NCollection_Vec4 operator-() const noexcept + { + return NCollection_Vec4(-x(), -y(), -z(), -w()); + } //! Compute per-component subtraction. - NCollection_Vec4& operator-=(const NCollection_Vec4& theDec) + constexpr NCollection_Vec4& operator-=(const NCollection_Vec4& theDec) noexcept { v[0] -= theDec.v[0]; v[1] -= theDec.v[1]; @@ -218,15 +231,15 @@ public: } //! Compute per-component subtraction. - friend NCollection_Vec4 operator-(const NCollection_Vec4& theLeft, - const NCollection_Vec4& theRight) + friend constexpr NCollection_Vec4 operator-(const NCollection_Vec4& theLeft, + const NCollection_Vec4& theRight) noexcept { NCollection_Vec4 aSumm = NCollection_Vec4(theLeft); return aSumm -= theRight; } //! Compute per-component multiplication. - NCollection_Vec4& operator*=(const NCollection_Vec4& theRight) + constexpr NCollection_Vec4& operator*=(const NCollection_Vec4& theRight) noexcept { v[0] *= theRight.v[0]; v[1] *= theRight.v[1]; @@ -236,15 +249,15 @@ public: } //! Compute per-component multiplication. - friend NCollection_Vec4 operator*(const NCollection_Vec4& theLeft, - const NCollection_Vec4& theRight) + friend constexpr NCollection_Vec4 operator*(const NCollection_Vec4& theLeft, + const NCollection_Vec4& theRight) noexcept { NCollection_Vec4 aResult = NCollection_Vec4(theLeft); return aResult *= theRight; } //! Compute per-component multiplication. - void Multiply(const Element_t theFactor) + constexpr void Multiply(const Element_t theFactor) noexcept { v[0] *= theFactor; v[1] *= theFactor; @@ -253,17 +266,20 @@ public: } //! Compute per-component multiplication. - NCollection_Vec4& operator*=(const Element_t theFactor) + constexpr NCollection_Vec4& operator*=(const Element_t theFactor) noexcept { Multiply(theFactor); return *this; } //! Compute per-component multiplication. - NCollection_Vec4 operator*(const Element_t theFactor) const { return Multiplied(theFactor); } + constexpr NCollection_Vec4 operator*(const Element_t theFactor) const noexcept + { + return Multiplied(theFactor); + } //! Compute per-component multiplication. - NCollection_Vec4 Multiplied(const Element_t theFactor) const + constexpr NCollection_Vec4 Multiplied(const Element_t theFactor) const noexcept { NCollection_Vec4 aCopyVec4(*this); aCopyVec4 *= theFactor; @@ -271,7 +287,7 @@ public: } //! Compute component-wise minimum of two vectors. - NCollection_Vec4 cwiseMin(const NCollection_Vec4& theVec) const + constexpr NCollection_Vec4 cwiseMin(const NCollection_Vec4& theVec) const noexcept { return NCollection_Vec4(v[0] < theVec.v[0] ? v[0] : theVec.v[0], v[1] < theVec.v[1] ? v[1] : theVec.v[1], @@ -280,7 +296,7 @@ public: } //! Compute component-wise maximum of two vectors. - NCollection_Vec4 cwiseMax(const NCollection_Vec4& theVec) const + constexpr NCollection_Vec4 cwiseMax(const NCollection_Vec4& theVec) const noexcept { return NCollection_Vec4(v[0] > theVec.v[0] ? v[0] : theVec.v[0], v[1] > theVec.v[1] ? v[1] : theVec.v[1], @@ -289,13 +305,13 @@ public: } //! Compute component-wise modulus of the vector. - NCollection_Vec4 cwiseAbs() const + NCollection_Vec4 cwiseAbs() const noexcept { return NCollection_Vec4(std::abs(v[0]), std::abs(v[1]), std::abs(v[2]), std::abs(v[3])); } //! Compute maximum component of the vector. - Element_t maxComp() const + constexpr Element_t maxComp() const noexcept { const Element_t aMax1 = v[0] > v[1] ? v[0] : v[1]; const Element_t aMax2 = v[2] > v[3] ? v[2] : v[3]; @@ -304,7 +320,7 @@ public: } //! Compute minimum component of the vector. - Element_t minComp() const + constexpr Element_t minComp() const noexcept { const Element_t aMin1 = v[0] < v[1] ? v[0] : v[1]; const Element_t aMin2 = v[2] < v[3] ? v[2] : v[3]; @@ -313,13 +329,13 @@ public: } //! Computes the dot product. - Element_t Dot(const NCollection_Vec4& theOther) const + constexpr Element_t Dot(const NCollection_Vec4& theOther) const noexcept { return x() * theOther.x() + y() * theOther.y() + z() * theOther.z() + w() * theOther.w(); } //! Compute per-component division by scale factor. - NCollection_Vec4& operator/=(const Element_t theInvFactor) + constexpr NCollection_Vec4& operator/=(const Element_t theInvFactor) { v[0] /= theInvFactor; v[1] /= theInvFactor; @@ -329,7 +345,7 @@ public: } //! Compute per-component division. - NCollection_Vec4& operator/=(const NCollection_Vec4& theRight) + constexpr NCollection_Vec4& operator/=(const NCollection_Vec4& theRight) { v[0] /= theRight.v[0]; v[1] /= theRight.v[1]; @@ -339,15 +355,15 @@ public: } //! Compute per-component division by scale factor. - NCollection_Vec4 operator/(const Element_t theInvFactor) + constexpr NCollection_Vec4 operator/(const Element_t theInvFactor) const { NCollection_Vec4 aResult(*this); return aResult /= theInvFactor; } //! Compute per-component division. - friend NCollection_Vec4 operator/(const NCollection_Vec4& theLeft, - const NCollection_Vec4& theRight) + friend constexpr NCollection_Vec4 operator/(const NCollection_Vec4& theLeft, + const NCollection_Vec4& theRight) { NCollection_Vec4 aResult = NCollection_Vec4(theLeft); return aResult /= theRight; @@ -366,7 +382,8 @@ private: //! Optimized concretization for float type. template <> -inline NCollection_Vec4& NCollection_Vec4::operator/=(const float theInvFactor) +inline constexpr NCollection_Vec4& NCollection_Vec4::operator/=( + const float theInvFactor) { Multiply(1.0f / theInvFactor); return *this; @@ -374,7 +391,8 @@ inline NCollection_Vec4& NCollection_Vec4::operator/=(const float //! Optimized concretization for double type. template <> -inline NCollection_Vec4& NCollection_Vec4::operator/=(const double theInvFactor) +inline constexpr NCollection_Vec4& NCollection_Vec4::operator/=( + const double theInvFactor) { Multiply(1.0 / theInvFactor); return *this; diff --git a/src/FoundationClasses/TKernel/Standard/Standard_DefineAlloc.hxx b/src/FoundationClasses/TKernel/Standard/Standard_DefineAlloc.hxx index d74ab5658f..d4c5f6ca88 100644 --- a/src/FoundationClasses/TKernel/Standard/Standard_DefineAlloc.hxx +++ b/src/FoundationClasses/TKernel/Standard/Standard_DefineAlloc.hxx @@ -37,17 +37,17 @@ // as it is not supported. #if defined(__BORLANDC__) || (defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530)) #define DEFINE_STANDARD_ALLOC_PLACEMENT \ - void* operator new(size_t, void* theAddress) \ + void* operator new(size_t, void* theAddress) noexcept \ { \ return theAddress; \ } #else #define DEFINE_STANDARD_ALLOC_PLACEMENT \ - void* operator new(size_t, void* theAddress) \ + void* operator new(size_t, void* theAddress) noexcept \ { \ return theAddress; \ } \ - void operator delete(void*, void*) {} + void operator delete(void*, void*) noexcept {} #endif // Macro to override operators new and delete to use OCC memory manager @@ -67,7 +67,7 @@ #ifndef WORKAROUND_SUNPRO_NEW_PLACEMENT #define WORKAROUND_SUNPRO_NEW_PLACEMENT #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x420) -inline void* operator new(size_t, void* anAddress) +inline void* operator new(size_t, void* anAddress) noexcept { return anAddress; } diff --git a/src/Visualization/TKOpenGl/OpenGl/OpenGl_View_Raytrace.cxx b/src/Visualization/TKOpenGl/OpenGl/OpenGl_View_Raytrace.cxx index 15d42d57e3..631e461842 100644 --- a/src/Visualization/TKOpenGl/OpenGl/OpenGl_View_Raytrace.cxx +++ b/src/Visualization/TKOpenGl/OpenGl/OpenGl_View_Raytrace.cxx @@ -42,12 +42,6 @@ #include #endif -namespace -{ -static const OpenGl_Vec4 THE_WHITE_COLOR(1.0f, 1.0f, 1.0f, 1.0f); -static const OpenGl_Vec4 THE_BLACK_COLOR(0.0f, 0.0f, 0.0f, 1.0f); -} // namespace - namespace { //! Defines OpenGL texture samplers. diff --git a/src/Visualization/TKV3d/SelectMgr/SelectMgr_ViewerSelector.cxx b/src/Visualization/TKV3d/SelectMgr/SelectMgr_ViewerSelector.cxx index 81296ae475..5750e203f5 100644 --- a/src/Visualization/TKV3d/SelectMgr/SelectMgr_ViewerSelector.cxx +++ b/src/Visualization/TKV3d/SelectMgr/SelectMgr_ViewerSelector.cxx @@ -71,7 +71,6 @@ private: bool myToPreferClosest; }; -static const Graphic3d_Mat4d SelectMgr_ViewerSelector_THE_IDENTITY_MAT; } // namespace //================================================================================================= -- 2.39.5