diff --git a/applications/test/sizeof/Test-sizeof.C b/applications/test/sizeof/Test-sizeof.C index 5232f06b5c82119686aa2c423dd68ff2f8b07b75..dfebf13b59fb63475900514c46593ddb7bb9dd01 100644 --- a/applications/test/sizeof/Test-sizeof.C +++ b/applications/test/sizeof/Test-sizeof.C @@ -39,6 +39,7 @@ Description #include "argList.H" #include "Time.H" #include "IOobject.H" +#include "scalarField.H" namespace Foam { @@ -139,6 +140,8 @@ int main(int argc, char *argv[]) cout<<"PstreamBuffers:" << sizeof(Foam::PstreamBuffers) << nl; cout<<"Time:" << sizeof(Foam::Time) << nl; + cout<<"tmp<>:" << sizeof(tmp<scalarField>) << nl; + Info << "---\nEnd\n" << endl; return 0; diff --git a/src/OpenFOAM/db/regIOobject/regIOobjectI.H b/src/OpenFOAM/db/regIOobject/regIOobjectI.H index aa490b75ce63c6a20684c45e59816a9a02f1f4f7..144799397e92bcfb30af1e8a8ae1715fb98c47f4 100644 --- a/src/OpenFOAM/db/regIOobject/regIOobjectI.H +++ b/src/OpenFOAM/db/regIOobject/regIOobjectI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -98,12 +98,12 @@ inline Type& Foam::regIOobject::store(refPtr<Type>& ptr) if (ptr.is_pointer()) { // Acquire ownership, pass management to objectRegistry - p = ptr.ptr(); + p = ptr.release(); store(p); // Change parameter to access the stored reference - ptr.cref(*p); + ptr.cref(p); } else { @@ -144,7 +144,7 @@ inline Type& Foam::regIOobject::store(tmp<Type>& ptr) store(p); // Change parameter to access the stored reference - ptr.cref(*p); + ptr.cref(p); } else { diff --git a/src/OpenFOAM/memory/autoPtr/autoPtr.H b/src/OpenFOAM/memory/autoPtr/autoPtr.H index 4804275bb86d0de41867794426d09cefe57e7a9f..af002bc84adfeacf8bdf140748cf665cae13c170 100644 --- a/src/OpenFOAM/memory/autoPtr/autoPtr.H +++ b/src/OpenFOAM/memory/autoPtr/autoPtr.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,7 +65,7 @@ namespace Foam template<class T> class autoPtr { - //- Pointer to managed object + //- The managed pointer T* ptr_; @@ -103,10 +103,10 @@ public: // Constructors - //- Construct with no managed object. + //- Construct with no managed pointer. inline constexpr autoPtr() noexcept; - //- Construct with no managed object (literal nullptr). + //- Construct with no managed pointer (literal nullptr). inline constexpr autoPtr(std::nullptr_t) noexcept; //- Construct, taking ownership of the pointer. @@ -134,7 +134,7 @@ public: #endif - //- Deletes the managed object if such is present + //- Deletes the managed pointer inline ~autoPtr() noexcept; @@ -142,14 +142,8 @@ public: // Query - //- Deprecated(2020-07) True if the managed pointer is null - // - // \deprecated(2020-07) - use bool operator - FOAM_DEPRECATED_FOR(2020-07, "bool operator") - bool empty() const noexcept { return !ptr_; } - //- True if the managed pointer is non-null - bool valid() const noexcept { return ptr_; } + bool valid() const noexcept { return bool(ptr_); } // Access @@ -170,7 +164,7 @@ public: // Edit - //- Return pointer to the managed object and release ownership. + //- Release ownership and return the pointer. inline T* release() noexcept; //- Same as \c release(). @@ -182,11 +176,11 @@ public: void clear() noexcept { reset(nullptr); } //- Delete managed object and set to new given pointer - inline void reset(T* p = nullptr) noexcept; + // \remark Same as move assign, but better for code documentation + inline void reset(autoPtr<T>&& other) noexcept; //- Delete managed object and set to new given pointer - // \remark Same as move assign, but better for code documentation - inline void reset(autoPtr<T>&& ap) noexcept; + inline void reset(T* p = nullptr) noexcept; //- Swaps the managed object with other autoPtr. inline void swap(autoPtr<T>& other) noexcept; @@ -230,7 +224,7 @@ public: // Casting - //- True if the managed pointer is non-null + //- True if pointer/reference is non-null. Same as valid() explicit operator bool() const noexcept { return bool(ptr_); } //- Cast to pointer type @@ -253,6 +247,9 @@ public: // Assignment + //- No copy assignment from plain pointer (uncontrolled access) + void operator=(T* p) = delete; + //- Transfer object ownership from parameter inline void operator=(autoPtr<T>&& ap) noexcept; @@ -270,6 +267,12 @@ public: // Housekeeping + //- Deprecated(2020-07) True if the managed pointer is null + // + // \deprecated(2020-07) - use bool operator + FOAM_DEPRECATED_FOR(2020-07, "bool operator") + bool empty() const noexcept { return !ptr_; } + //- Deprecated(2018-02) Identical to reset(). // \note Provided for backward compatibility - the older version // enforced a run-time check (Fatal if pointer was already set) @@ -279,10 +282,6 @@ public: FOAM_DEPRECATED_FOR(2018-02, "reset() - same behaviour") #endif void set(T* p) noexcept { reset(p); } - - //- Deprecated(2018-02) No copy assignment from plain pointer - // \deprecated(2018-02) Convenient, but uncontrolled access - void operator=(T* p) = delete; }; diff --git a/src/OpenFOAM/memory/autoPtr/autoPtrI.H b/src/OpenFOAM/memory/autoPtr/autoPtrI.H index a8bce75464ff119aec201dac69a678add62728f3..12411277421287589b93ca13584935e054cf53e1 100644 --- a/src/OpenFOAM/memory/autoPtr/autoPtrI.H +++ b/src/OpenFOAM/memory/autoPtr/autoPtrI.H @@ -114,9 +114,13 @@ inline void Foam::autoPtr<T>::reset(T* p) noexcept template<class T> -inline void Foam::autoPtr<T>::reset(autoPtr<T>&& ap) noexcept +inline void Foam::autoPtr<T>::reset(autoPtr<T>&& other) noexcept { - reset(ap.release()); + if (&other != this) + { + // Ignore self-assignment + reset(other.release()); + } } diff --git a/src/OpenFOAM/memory/refPtr/refPtr.H b/src/OpenFOAM/memory/refPtr/refPtr.H index d7cf643fd86e1141d8168462c5425cf23271816e..b78b5b0d8da7374293cd6e8b93d150d2396df3bf 100644 --- a/src/OpenFOAM/memory/refPtr/refPtr.H +++ b/src/OpenFOAM/memory/refPtr/refPtr.H @@ -59,12 +59,12 @@ class refPtr { // Private Data - //- Object types + //- The stored reference type enum refType { - PTR, //!< Managing a pointer (not ref-counted) - CREF, //!< Using (const) reference to an object - REF //!< Using (non-const) reference to an object + PTR, //!< A managed pointer (not ref-counted) + CREF, //!< A const reference to an object + REF //!< A non-const reference to an object }; //- The managed pointer or address of the object (reference) @@ -111,10 +111,10 @@ public: // Constructors - //- Default construct, no managed pointer. + //- Construct with no managed pointer. inline constexpr refPtr() noexcept; - //- Construct with no managed pointer. + //- Construct with no managed pointer (literal nullptr). inline constexpr refPtr(std::nullptr_t) noexcept; //- Construct, taking ownership of the pointer. @@ -151,21 +151,15 @@ public: // Query - //- Deprecated(2020-07) True if a null managed pointer - // - // \deprecated(2020-07) - use bool operator - FOAM_DEPRECATED_FOR(2020-07, "bool operator") - bool empty() const noexcept { return !ptr_; } - //- True for non-null pointer/reference - bool valid() const noexcept { return ptr_; } + bool valid() const noexcept { return bool(ptr_); } + + //- If the stored/referenced content is const + bool is_const() const noexcept { return type_ == CREF; } //- True if this is a managed pointer (not a reference) bool is_pointer() const noexcept { return type_ == PTR; } - //- Identical to is_pointer() - bool isTmp() const noexcept { return type_ == PTR; } - //- True if this is a non-null managed pointer inline bool movable() const noexcept; @@ -196,6 +190,10 @@ public: // Edit + //- Release ownership and return the pointer. + //- A no-op for reference objects (returns nullptr). + inline T* release() noexcept; + //- Return managed pointer for reuse, or clone() the object reference. inline T* ptr() const; @@ -203,7 +201,10 @@ public: //- delete object and set pointer to nullptr inline void clear() const noexcept; - //- Delete managed temporary object and set to new given pointer + //- Clear existing and transfer ownership. + inline void reset(refPtr<T>&& other) noexcept; + + //- Delete managed pointer and set to new given pointer inline void reset(T* p = nullptr) noexcept; //- Clear existing and transfer ownership from autoPtr. @@ -212,21 +213,18 @@ public: //- Clear existing and transfer ownership from unique_ptr void reset(std::unique_ptr<T>&& other) { reset(other.release()); } - //- Clear existing and transfer ownership. - inline void reset(refPtr<T>&& other) noexcept; - //- Clear existing and set (const) reference inline void cref(const T& obj) noexcept; //- Clear existing and set (const) reference to pointer content. - // A null pointer is permitted (treated as a managed pointer). + // The pointer can be null, which is handled like a clear(). inline void cref(const T* p) noexcept; //- Clear existing and set (non-const) reference inline void ref(T& obj) noexcept; //- Clear existing and set (non-const) reference to pointer content. - // A null pointer is permitted (treated as a managed pointer). + // The pointer can be null, which is handled like a clear(). inline void ref(T* p) noexcept; //- Swaps the managed object with other. @@ -257,8 +255,8 @@ public: //- Cast to underlying data type, using the cref() method. operator const T&() const { return cref(); } - //- Non-null pointer/reference : valid() - explicit operator bool() const noexcept { return ptr_; } + //- True if pointer/reference is non-null. Same as valid() + explicit operator bool() const noexcept { return bool(ptr_); } //- Transfer ownership of the managed pointer. // Fatal for a null managed pointer or if the object is const. @@ -276,6 +274,15 @@ public: //- Conversion to tmp, releases pointer or shallow-copies reference inline operator tmp<T>(); + + + // Housekeeping + + //- Deprecated(2020-07) True if a null managed pointer + // + // \deprecated(2020-07) - use bool operator + FOAM_DEPRECATED_FOR(2020-07, "bool operator") + bool empty() const noexcept { return !ptr_; } }; diff --git a/src/OpenFOAM/memory/refPtr/refPtrI.H b/src/OpenFOAM/memory/refPtr/refPtrI.H index 7736fa301f574fde665e0fd270917e7ea48e2788..0664701b1802ef3a2af54571d7257416862a6ff6 100644 --- a/src/OpenFOAM/memory/refPtr/refPtrI.H +++ b/src/OpenFOAM/memory/refPtr/refPtrI.H @@ -186,41 +186,35 @@ inline bool Foam::refPtr<T>::movable() const noexcept template<class T> inline const T& Foam::refPtr<T>::cref() const { - if (type_ == PTR) + if (type_ == PTR && !ptr_) { - if (!ptr_) - { - FatalErrorInFunction - << this->typeName() << " deallocated" - << abort(FatalError); - } + FatalErrorInFunction + << this->typeName() << " deallocated" + << abort(FatalError); } - return *ptr_; // const reference + return *ptr_; // const reference } template<class T> inline T& Foam::refPtr<T>::ref() const { - if (type_ == PTR) + if (type_ == CREF) { - if (!ptr_) - { - FatalErrorInFunction - << this->typeName() << " deallocated" - << abort(FatalError); - } + FatalErrorInFunction + << "Attempted non-const reference to const object: " + << this->typeName() + << abort(FatalError); } - else if (type_ == CREF) + else if (type_ == PTR && !ptr_) { FatalErrorInFunction - << "Attempted non-const reference to const object from a " - << this->typeName() + << this->typeName() << " deallocated" << abort(FatalError); } - return *ptr_; // non-const reference + return *ptr_; // non-const reference } @@ -231,6 +225,20 @@ inline T& Foam::refPtr<T>::constCast() const } +template<class T> +inline T* Foam::refPtr<T>::release() noexcept +{ + if (type_ == PTR) + { + T* p = ptr_; + ptr_ = nullptr; + return p; + } + + return nullptr; +} + + template<class T> inline T* Foam::refPtr<T>::ptr() const { @@ -363,7 +371,7 @@ inline T& Foam::refPtr<T>::operator*() if (type_ == CREF) { FatalErrorInFunction - << "Attempt to cast const object to non-const for a " + << "Attempt to cast const object to non-const: " << this->typeName() << abort(FatalError); } @@ -398,7 +406,7 @@ inline T* Foam::refPtr<T>::operator->() if (type_ == CREF) { FatalErrorInFunction - << "Attempt to cast const object to non-const for a " + << "Attempt to cast const object to non-const: " << this->typeName() << abort(FatalError); } diff --git a/src/OpenFOAM/memory/tmp/tmp.H b/src/OpenFOAM/memory/tmp/tmp.H index 7a4272f0ee9655bd376942dddcb7779f09dfd2a3..ccd2efc6242011f30d5d867786015440283786ef 100644 --- a/src/OpenFOAM/memory/tmp/tmp.H +++ b/src/OpenFOAM/memory/tmp/tmp.H @@ -66,12 +66,12 @@ class tmp { // Private Data - //- Object types + //- The stored reference type enum refType { - PTR, //!< Managing a pointer (ref-counted) - CREF, //!< Using (const) reference to an object - REF //!< Using (non-const) reference to an object + PTR, //!< A managed pointer (ref-counted) + CREF, //!< A const reference to an object + REF //!< A non-const reference to an object }; //- The managed pointer or address of the object (reference) @@ -125,10 +125,10 @@ public: // Constructors - //- Default construct, no managed pointer. + //- Construct with no managed pointer. inline constexpr tmp() noexcept; - //- Construct with no managed pointer. + //- Construct with no managed pointer (literal nullptr). inline constexpr tmp(std::nullptr_t) noexcept; //- Construct, taking ownership of the pointer. @@ -166,14 +166,11 @@ public: // Query - //- Deprecated(2020-07) True if a null managed pointer - // - // \deprecated(2020-07) - use bool operator - FOAM_DEPRECATED_FOR(2020-07, "bool operator") - bool empty() const noexcept { return !ptr_; } + //- True if pointer/reference is non-null + bool valid() const noexcept { return bool(ptr_); } - //- True for non-null pointer/reference - bool valid() const noexcept { return ptr_; } + //- If the stored/referenced content is const + bool is_const() const noexcept { return type_ == CREF; } //- True if this is a managed pointer (not a reference) bool is_pointer() const noexcept { return type_ == PTR; } @@ -218,24 +215,24 @@ public: //- delete object and set pointer to nullptr inline void clear() const noexcept; - //- Delete managed temporary object and set to new given pointer - inline void reset(T* p = nullptr) noexcept; - //- Clear existing and transfer ownership. inline void reset(tmp<T>&& other) noexcept; + //- Delete managed temporary object and set to new given pointer + inline void reset(T* p = nullptr) noexcept; + //- Clear existing and set (const) reference inline void cref(const T& obj) noexcept; //- Clear existing and set (const) reference to pointer content. - // A null pointer is permitted (treated as a managed pointer). + // The pointer can be null, which is handled like a clear(). inline void cref(const T* p) noexcept; //- Clear existing and set to (non-const) reference inline void ref(T& obj) noexcept; //- Clear existing and set (non-const) reference to pointer content. - // A null pointer is permitted (treated as a managed pointer). + // The pointer can be null, which is handled like a clear(). inline void ref(T* p) noexcept; //- Swaps the managed object with other. @@ -258,8 +255,8 @@ public: //- Cast to underlying data type, using the cref() method. operator const T&() const { return cref(); } - //- Non-null pointer/reference : valid() - explicit operator bool() const noexcept { return ptr_; } + //- True if pointer/reference is non-null. Same as valid() + explicit operator bool() const noexcept { return bool(ptr_); } //- Transfer ownership of the managed pointer. // Fatal for a null managed pointer or if the object is const. @@ -274,6 +271,15 @@ public: //- Reset via assignment from literal nullptr inline void operator=(std::nullptr_t) noexcept; + + + // Housekeeping + + //- Deprecated(2020-07) True if a null managed pointer + // + // \deprecated(2020-07) - use bool operator + FOAM_DEPRECATED_FOR(2020-07, "bool operator") + bool empty() const noexcept { return !ptr_; } }; diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H index 094eab36a7aaae1f4889c009a0f2c6fd8899413e..b58eb7df37e3f9d7ba65ba5b79760ef4b4fa2bb5 100644 --- a/src/OpenFOAM/memory/tmp/tmpI.H +++ b/src/OpenFOAM/memory/tmp/tmpI.H @@ -210,41 +210,35 @@ inline bool Foam::tmp<T>::movable() const noexcept template<class T> inline const T& Foam::tmp<T>::cref() const { - if (type_ == PTR) + if (type_ == PTR && !ptr_) { - if (!ptr_) - { - FatalErrorInFunction - << this->typeName() << " deallocated" - << abort(FatalError); - } + FatalErrorInFunction + << this->typeName() << " deallocated" + << abort(FatalError); } - return *ptr_; // const reference + return *ptr_; // const reference } template<class T> inline T& Foam::tmp<T>::ref() const { - if (type_ == PTR) + if (type_ == CREF) { - if (!ptr_) - { - FatalErrorInFunction - << this->typeName() << " deallocated" - << abort(FatalError); - } + FatalErrorInFunction + << "Attempted non-const reference to const object: " + << this->typeName() + << abort(FatalError); } - else if (type_ == CREF) + else if (type_ == PTR && !ptr_) { FatalErrorInFunction - << "Attempted non-const reference to const object from a " - << this->typeName() + << this->typeName() << " deallocated" << abort(FatalError); } - return *ptr_; // non-const reference + return *ptr_; // non-const reference } @@ -387,14 +381,11 @@ inline void Foam::tmp<T>::swap(tmp<T>& other) noexcept template<class T> inline const T* Foam::tmp<T>::operator->() const { - if (type_ == PTR) + if (type_ == PTR && !ptr_) { - if (!ptr_) - { - FatalErrorInFunction - << this->typeName() << " deallocated" - << abort(FatalError); - } + FatalErrorInFunction + << this->typeName() << " deallocated" + << abort(FatalError); } return ptr_; @@ -404,20 +395,17 @@ inline const T* Foam::tmp<T>::operator->() const template<class T> inline T* Foam::tmp<T>::operator->() { - if (type_ == PTR) + if (type_ == CREF) { - if (!ptr_) - { - FatalErrorInFunction - << this->typeName() << " deallocated" - << abort(FatalError); - } + FatalErrorInFunction + << "Attempt to cast const object to non-const: " + << this->typeName() + << abort(FatalError); } - else if (type_ == CREF) + else if (type_ == PTR && !ptr_) { FatalErrorInFunction - << "Attempt to cast const object to non-const for a " - << this->typeName() + << this->typeName() << " deallocated" << abort(FatalError); } diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.C b/src/OpenFOAM/primitives/Scalar/Scalar.C index cc096ebeb4413c8c1c65f1d291363df1000ab116..d6ec9d98595cdabd79712a608181593fe818271a 100644 --- a/src/OpenFOAM/primitives/Scalar/Scalar.C +++ b/src/OpenFOAM/primitives/Scalar/Scalar.C @@ -31,7 +31,7 @@ License namespace Foam { -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // const char* const pTraits<Scalar>::typeName = "scalar"; const char* const pTraits<Scalar>::componentNames[] = { "" }; @@ -45,7 +45,9 @@ const Scalar pTraits<Scalar>::rootMax = ScalarROOTVGREAT; const Scalar pTraits<Scalar>::vsmall = ScalarVSMALL; -pTraits<Scalar>::pTraits(const Scalar& val) +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +pTraits<Scalar>::pTraits(const Scalar& val) noexcept : p_(val) {} diff --git a/src/OpenFOAM/primitives/Scalar/Scalar.H b/src/OpenFOAM/primitives/Scalar/Scalar.H index bdb895628bd92f299394fa457a7162501dac4eea..e526027b3654be652be7c4aa7e51317f0e85a63a 100644 --- a/src/OpenFOAM/primitives/Scalar/Scalar.H +++ b/src/OpenFOAM/primitives/Scalar/Scalar.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -110,7 +110,7 @@ public: // Constructors //- Copy construct from primitive - explicit pTraits(const Scalar& val); + explicit pTraits(const Scalar& val) noexcept; //- Read construct from Istream explicit pTraits(Istream& is); @@ -119,13 +119,13 @@ public: // Member Functions //- Access to the value - operator Scalar() const + operator Scalar() const noexcept { return p_; } //- Access to the value - operator Scalar&() + operator Scalar&() noexcept { return p_; } @@ -143,7 +143,7 @@ word name(const Scalar val); template<> struct nameOp<Scalar> { - inline word operator()(const Scalar val) const + word operator()(const Scalar val) const { return Foam::name(val); } diff --git a/src/OpenFOAM/primitives/bools/bool/bool.C b/src/OpenFOAM/primitives/bools/bool/bool.C index 63da1e6a4f94d46c9ef442ea0d2ef16f78963f49..826f4c81566e977853f94fb36209255ee8d4822d 100644 --- a/src/OpenFOAM/primitives/bools/bool/bool.C +++ b/src/OpenFOAM/primitives/bools/bool/bool.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,7 +31,7 @@ License #include "error.H" #include "IOstreams.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // const char* const Foam::pTraits<bool>::typeName = "bool"; const char* const Foam::pTraits<bool>::componentNames[] = { "" }; @@ -40,7 +40,9 @@ const bool Foam::pTraits<bool>::zero = false; const bool Foam::pTraits<bool>::one = true; -Foam::pTraits<bool>::pTraits(const bool& p) +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::pTraits<bool>::pTraits(const bool& p) noexcept : p_(p) {} @@ -52,6 +54,8 @@ Foam::pTraits<bool>::pTraits(Istream& is) } +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + Foam::Istream& Foam::operator>>(Istream& is, bool& b) { b = static_cast<bool>(Switch(is)); diff --git a/src/OpenFOAM/primitives/bools/bool/bool.H b/src/OpenFOAM/primitives/bools/bool/bool.H index 8fc49b7cb6b3fc427b132eb9290fd8fef0c9c7f4..cbd4adc00da15d6ff789c6387c6ac7ef299caf41 100644 --- a/src/OpenFOAM/primitives/bools/bool/bool.H +++ b/src/OpenFOAM/primitives/bools/bool/bool.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -109,7 +109,7 @@ public: // Constructors //- Copy construct from primitive - explicit pTraits(const bool& p); + explicit pTraits(const bool& p) noexcept; //- Read construct from Istream explicit pTraits(Istream& is); @@ -118,13 +118,13 @@ public: // Member Functions //- Access to the value - operator bool() const + operator bool() const noexcept { return p_; } //- Access to the value - operator bool&() + operator bool&() noexcept { return p_; } diff --git a/src/OpenFOAM/primitives/chars/char/char.C b/src/OpenFOAM/primitives/chars/char/char.C index 6d5802816b619a502856b53e308df6be0516a755..de8e20e773f16aa4dcc91b0c1099e10f43840c3e 100644 --- a/src/OpenFOAM/primitives/chars/char/char.C +++ b/src/OpenFOAM/primitives/chars/char/char.C @@ -29,10 +29,13 @@ License #include "char.H" #include "IOstreams.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // const char* const Foam::pTraits<char>::typeName = "char"; + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + Foam::pTraits<char>::pTraits(const char p) noexcept : p_(p) @@ -45,6 +48,8 @@ Foam::pTraits<char>::pTraits(Istream& is) } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + char Foam::readChar(Istream& is) { char c; diff --git a/src/OpenFOAM/primitives/ints/int16/int16.H b/src/OpenFOAM/primitives/ints/int16/int16.H index 8ea19f1537e2f8efb0912087fe958968e50f8cd9..a0f4341c5a7700ce77934527fc725f6c835aacf3 100644 --- a/src/OpenFOAM/primitives/ints/int16/int16.H +++ b/src/OpenFOAM/primitives/ints/int16/int16.H @@ -61,7 +61,7 @@ inline word name(const int16_t val) template<> struct nameOp<int16_t> { - inline word operator()(const int16_t val) const + word operator()(const int16_t val) const { return word(std::to_string(int(val)), false); // Needs no stripping } diff --git a/src/OpenFOAM/primitives/ints/int32/int32.C b/src/OpenFOAM/primitives/ints/int32/int32.C index 2b10a9596d3a48c88d48fa2867b9ac46ab4704e9..1453a8dd2e54a3b0827da9edfff147354f5fdb11 100644 --- a/src/OpenFOAM/primitives/ints/int32/int32.C +++ b/src/OpenFOAM/primitives/ints/int32/int32.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014-2016 OpenFOAM Foundation - Copyright (C) 2017-2018 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,7 @@ License #include "int32.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // const char* const Foam::pTraits<int32_t>::componentNames[] = { "" }; @@ -39,7 +39,10 @@ const int32_t Foam::pTraits<int32_t>::max = INT32_MAX; const int32_t Foam::pTraits<int32_t>::rootMin = pTraits<int32_t>::min; const int32_t Foam::pTraits<int32_t>::rootMax = pTraits<int32_t>::max; -Foam::pTraits<int32_t>::pTraits(const int32_t& val) + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::pTraits<int32_t>::pTraits(const int32_t& val) noexcept : p_(val) {} diff --git a/src/OpenFOAM/primitives/ints/int32/int32.H b/src/OpenFOAM/primitives/ints/int32/int32.H index 2cf170baf623f24620f3dc8401851ef4cf78f6b1..6b1e8f9a2ac951f231d30b1a5dda8850b6c1788a 100644 --- a/src/OpenFOAM/primitives/ints/int32/int32.H +++ b/src/OpenFOAM/primitives/ints/int32/int32.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -69,7 +69,7 @@ inline word name(const int32_t val) template<> struct nameOp<int32_t> { - inline word operator()(const int32_t val) const + word operator()(const int32_t val) const { return word(std::to_string(val), false); // Needs no stripping } @@ -175,7 +175,7 @@ public: // Constructors //- Copy construct from primitive - explicit pTraits(const int32_t& val); + explicit pTraits(const int32_t& val) noexcept; //- Read construct from Istream explicit pTraits(Istream& is); @@ -184,13 +184,13 @@ public: // Member Functions //- Access to the value - operator int32_t() const + operator int32_t() const noexcept { return p_; } //- Access to the value - operator int32_t&() + operator int32_t&() noexcept { return p_; } diff --git a/src/OpenFOAM/primitives/ints/int64/int64.C b/src/OpenFOAM/primitives/ints/int64/int64.C index c9b709902651d673dc77ba54bb8bcd4f3f569292..d305760d038ecc052c8ae942d7351727b28b961e 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64.C +++ b/src/OpenFOAM/primitives/ints/int64/int64.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014-2016 OpenFOAM Foundation - Copyright (C) 2017-2018 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,7 @@ License #include "int64.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // const char* const Foam::pTraits<int64_t>::componentNames[] = { "" }; @@ -39,11 +39,15 @@ const int64_t Foam::pTraits<int64_t>::max = INT64_MAX; const int64_t Foam::pTraits<int64_t>::rootMin = pTraits<int64_t>::min; const int64_t Foam::pTraits<int64_t>::rootMax = pTraits<int64_t>::max; -Foam::pTraits<int64_t>::pTraits(const int64_t& val) + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::pTraits<int64_t>::pTraits(const int64_t& val) noexcept : p_(val) {} + Foam::pTraits<int64_t>::pTraits(Istream& is) { is >> p_; diff --git a/src/OpenFOAM/primitives/ints/int64/int64.H b/src/OpenFOAM/primitives/ints/int64/int64.H index 0f9faf2757b1941e4b2bf56f9ec3b5a8bcc25c50..3d1fdc7c9b3a98a6da65a48e0aced82ccdf1bc67 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64.H +++ b/src/OpenFOAM/primitives/ints/int64/int64.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -69,7 +69,7 @@ inline word name(const int64_t val) template<> struct nameOp<int64_t> { - inline word operator()(const int64_t val) const + word operator()(const int64_t val) const { return word(std::to_string(val), false); // Needs no stripping } @@ -174,7 +174,7 @@ public: // Constructors //- Copy construct from primitive - explicit pTraits(const int64_t& val); + explicit pTraits(const int64_t& val) noexcept; //- Read construct from Istream explicit pTraits(Istream& is); @@ -183,13 +183,13 @@ public: // Member Functions //- Access to the value - operator int64_t() const + operator int64_t() const noexcept { return p_; } //- Access to the value - operator int64_t&() + operator int64_t&() noexcept { return p_; } diff --git a/src/OpenFOAM/primitives/ints/uint16/uint16.H b/src/OpenFOAM/primitives/ints/uint16/uint16.H index c61d37e8225faa6a28373eab6e1b2211dcc17715..7245c2d40a05dcf9798fbc5436a2c855265269dd 100644 --- a/src/OpenFOAM/primitives/ints/uint16/uint16.H +++ b/src/OpenFOAM/primitives/ints/uint16/uint16.H @@ -62,7 +62,7 @@ inline word name(const uint16_t val) template<> struct nameOp<uint16_t> { - inline word operator()(const uint16_t val) const + word operator()(const uint16_t val) const { return word(std::to_string(int(val)), false); // Needs no stripping } diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32.C b/src/OpenFOAM/primitives/ints/uint32/uint32.C index 340ab250eb86e2fb67172c283a1915187fd16220..b1a040069a00ccaf7c171b938d97525e91dc6588 100644 --- a/src/OpenFOAM/primitives/ints/uint32/uint32.C +++ b/src/OpenFOAM/primitives/ints/uint32/uint32.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014-2016 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,7 @@ License #include "uint32.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // const char* const Foam::pTraits<uint32_t>::componentNames[] = { "" }; @@ -39,11 +39,15 @@ const uint32_t Foam::pTraits<uint32_t>::max = UINT32_MAX; const uint32_t Foam::pTraits<uint32_t>::rootMin = 0; const uint32_t Foam::pTraits<uint32_t>::rootMax = pTraits<uint32_t>::max; -Foam::pTraits<uint32_t>::pTraits(const uint32_t& val) + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::pTraits<uint32_t>::pTraits(const uint32_t& val) noexcept : p_(val) {} + Foam::pTraits<uint32_t>::pTraits(Istream& is) { is >> p_; diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32.H b/src/OpenFOAM/primitives/ints/uint32/uint32.H index 69e7cb70b9b57e1001d7a262464b536451906aa5..5a3f574508e13ff63bff24f3c8bb12739daa0e67 100644 --- a/src/OpenFOAM/primitives/ints/uint32/uint32.H +++ b/src/OpenFOAM/primitives/ints/uint32/uint32.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -68,7 +68,7 @@ inline word name(const uint32_t val) template<> struct nameOp<uint32_t> { - inline word operator()(const uint32_t val) const + word operator()(const uint32_t val) const { return word(std::to_string(val), false); // Needs no stripping } @@ -161,7 +161,7 @@ public: // Constructors //- Copy construct from primitive - explicit pTraits(const uint32_t& val); + explicit pTraits(const uint32_t& val) noexcept; //- Read construct from Istream explicit pTraits(Istream& is); @@ -170,13 +170,13 @@ public: // Member Functions //- Access to the value - operator uint32_t() const + operator uint32_t() const noexcept { return p_; } //- Access to the value - operator uint32_t&() + operator uint32_t&() noexcept { return p_; } diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64.C b/src/OpenFOAM/primitives/ints/uint64/uint64.C index 804b86ac6986a1ec20e2aea057f0cfdd3cb98668..ca4f207d5b9e597b4cce846b150df9fbc690f241 100644 --- a/src/OpenFOAM/primitives/ints/uint64/uint64.C +++ b/src/OpenFOAM/primitives/ints/uint64/uint64.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014-2016 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,7 @@ License #include "uint64.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // const char* const Foam::pTraits<uint64_t>::componentNames[] = { "" }; @@ -39,7 +39,10 @@ const uint64_t Foam::pTraits<uint64_t>::max = UINT64_MAX; const uint64_t Foam::pTraits<uint64_t>::rootMin = 0; const uint64_t Foam::pTraits<uint64_t>::rootMax = pTraits<uint64_t>::max; -Foam::pTraits<uint64_t>::pTraits(const uint64_t& val) + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::pTraits<uint64_t>::pTraits(const uint64_t& val) noexcept : p_(val) {} diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64.H b/src/OpenFOAM/primitives/ints/uint64/uint64.H index cc7624f8053593c15a48de470e0e3954b90b62fe..49dcb96e4a58507b6ae2114e7ad1ba29ea84fa4b 100644 --- a/src/OpenFOAM/primitives/ints/uint64/uint64.H +++ b/src/OpenFOAM/primitives/ints/uint64/uint64.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -69,7 +69,7 @@ inline word name(const uint64_t val) template<> struct nameOp<uint64_t> { - inline word operator()(const uint64_t val) const + word operator()(const uint64_t val) const { return word(std::to_string(val), false); // Needs no stripping } @@ -170,7 +170,7 @@ public: // Constructors //- Copy construct from primitive - explicit pTraits(const uint64_t& val); + explicit pTraits(const uint64_t& val) noexcept; //- Read construct from Istream explicit pTraits(Istream& is); @@ -179,13 +179,13 @@ public: // Member Functions //- Access to the value - operator uint64_t() const + operator uint64_t() const noexcept { return p_; } //- Access to the value - operator uint64_t&() + operator uint64_t&() noexcept { return p_; } diff --git a/src/OpenFOAM/primitives/ints/uint8/uint8.C b/src/OpenFOAM/primitives/ints/uint8/uint8.C index 0c9cdf74bd377f38945cf56c26f8987a9718aa27..52b52ee90d7b75ff83331f7de8b0b1146a7369ab 100644 --- a/src/OpenFOAM/primitives/ints/uint8/uint8.C +++ b/src/OpenFOAM/primitives/ints/uint8/uint8.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,7 +27,7 @@ License #include "uint8.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // const char* const Foam::pTraits<uint8_t>::typeName = "uint8"; const char* const Foam::pTraits<uint8_t>::componentNames[] = { "" }; @@ -40,11 +40,14 @@ const uint8_t Foam::pTraits<uint8_t>::rootMin = 0; const uint8_t Foam::pTraits<uint8_t>::rootMax = UINT8_MAX; -Foam::pTraits<uint8_t>::pTraits(const uint8_t& val) +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::pTraits<uint8_t>::pTraits(const uint8_t& val) noexcept : p_(val) {} + Foam::pTraits<uint8_t>::pTraits(Istream& is) { is >> p_; diff --git a/src/OpenFOAM/primitives/ints/uint8/uint8.H b/src/OpenFOAM/primitives/ints/uint8/uint8.H index 85d412c21d3057e1ce22dd80009903307299b293..a45642adbf300ddb48f7640b22f8925121a81f9a 100644 --- a/src/OpenFOAM/primitives/ints/uint8/uint8.H +++ b/src/OpenFOAM/primitives/ints/uint8/uint8.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -68,7 +68,7 @@ inline word name(const uint8_t val) template<> struct nameOp<uint8_t> { - inline word operator()(const uint8_t val) const + word operator()(const uint8_t val) const { return word(std::to_string(int(val)), false); // Needs no stripping } @@ -126,7 +126,7 @@ public: // Constructors //- Copy construct from primitive - explicit pTraits(const uint8_t& val); + explicit pTraits(const uint8_t& val) noexcept; //- Read construct from Istream explicit pTraits(Istream& is); diff --git a/src/OpenFOAM/primitives/pTraits/pTraits.H b/src/OpenFOAM/primitives/pTraits/pTraits.H index f748c1b2a7510194b03af23e1af8a0ca66f49258..98c3a8136a29caeee32b9a8385dc5afa2cbe97ae 100644 --- a/src/OpenFOAM/primitives/pTraits/pTraits.H +++ b/src/OpenFOAM/primitives/pTraits/pTraits.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,7 +28,7 @@ Class Foam::pTraits Description - Traits class for primitives. + A traits class, which is primarily used for primitives. All primitives need a specialised version of this class. The specialised version will normally also require a conversion @@ -51,25 +51,27 @@ class Istream; Class pTraits Declaration \*---------------------------------------------------------------------------*/ -template<class PrimitiveType> +// The base implementation is a pass-through to the base class. +// Accordingly it inherits all static methods (eg, typeName etc). +template<class Base> class pTraits : - public PrimitiveType + public Base { public: // Constructors - //- Copy construct from primitive - explicit pTraits(const PrimitiveType& p) + //- Copy construct from base class + explicit pTraits(const Base& obj) : - PrimitiveType(p) + Base(obj) {} //- Construct from Istream explicit pTraits(Istream& is) : - PrimitiveType(is) + Base(is) {} }; diff --git a/src/OpenFOAM/primitives/strings/word/word.H b/src/OpenFOAM/primitives/strings/word/word.H index d05abd312f3edeaecfed023483691d931a40870a..19d9c2a8742c16a2c2c614924418ca97edb0357e 100644 --- a/src/OpenFOAM/primitives/strings/word/word.H +++ b/src/OpenFOAM/primitives/strings/word/word.H @@ -231,7 +231,7 @@ word name(const void* ptr); template<class T> struct nameOp { - inline word operator()(const T& obj) const + word operator()(const T& obj) const { return obj.name(); } @@ -242,7 +242,7 @@ struct nameOp template<class T> struct typeOp { - inline word operator()(const T& obj) const + word operator()(const T& obj) const { return obj.type(); }